From 439ae5c961aa26c9884a3756e214a2eb920bbc58 Mon Sep 17 00:00:00 2001 From: Sergii Kolbasin Date: Wed, 6 Oct 2021 09:56:24 +0200 Subject: [PATCH] Ignore retriedTest serialization to avoid circular issues --- src/register.js | 5 ++++- test-functional/.mocharc.json | 3 ++- test/parallel-mode.test.js | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/register.js b/src/register.js index 10966ad..7566b5b 100644 --- a/src/register.js +++ b/src/register.js @@ -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) => { diff --git a/test-functional/.mocharc.json b/test-functional/.mocharc.json index 37ed19e..58f1883 100644 --- a/test-functional/.mocharc.json +++ b/test-functional/.mocharc.json @@ -1,5 +1,6 @@ { "require": ["should", "./register"], "reporter": "./src/mochawesome", - "reporterOption": [] + "reporterOption": [], + "retries": 1 } diff --git a/test/parallel-mode.test.js b/test/parallel-mode.test.js index 6c43b0f..21e2c83 100644 --- a/test/parallel-mode.test.js +++ b/test/parallel-mode.test.js @@ -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()", () => {