Skip to content

Commit

Permalink
Merge pull request #357 from kolbasik/hotfix/issue-356
Browse files Browse the repository at this point in the history
Ignore retriedTest serialization to avoid circular issues
  • Loading branch information
adamgruber authored Oct 6, 2021
2 parents f478f70 + 439ae5c commit e5a8c50
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const serializeHook = hook => {
}

const serializeTest = test => {
return serializeObject(test, ['pending', 'context']);
const result = serializeObject(test, ['pending', 'context']);
// to remove a circular dependency: https://github.com/adamgruber/mochawesome/issues/356
result["$$retriedTest"] = null;
return result;
}

const serializeObject = (obj, fields) => {
Expand Down
3 changes: 2 additions & 1 deletion test-functional/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"require": ["should", "./register"],
"reporter": "./src/mochawesome",
"reporterOption": []
"reporterOption": [],
"retries": 1
}
21 changes: 21 additions & 0 deletions test/parallel-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,27 @@ describe('Parallel Mode', () => {
fake: true
});
});

it(`should ignore the retriedTest to avoid circular serialization issue`, () => {
// arrange
const given = {
testName: 'FAKE TEST',
retriedName: 'RETRIED TEST',
suiteName: 'FAKE SUITE',
error: Object.assign(new Error("FAKE ERROR"), { fake: true })
};
const test = new Test(given.testName, noop);
test.parent = new Suite(given.suiteName);
test.retriedTest(new Test(given.retriedName, noop))

// act
const actual = serializeTest(test);

// assert
actual.should.containDeep({
"$$retriedTest": null
});
});
});

describe("serializeError()", () => {
Expand Down

0 comments on commit e5a8c50

Please sign in to comment.