From d7013ddb1099cfafe66a1af9640370998290e62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josh=20Goldberg=20=E2=9C=A8?= Date: Tue, 6 Aug 2024 12:12:10 -0400 Subject: [PATCH] fix: crash with --parallel and --retries both enabled (#5173) * test case: crash with --parallel and --retries both enabled * fix: crash with --parallel and --retries both enabled --- lib/nodejs/serializer.js | 2 +- .../fixtures/parallel/non-circular-error.mjs | 5 +++++ test/integration/parallel.spec.js | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/integration/fixtures/parallel/non-circular-error.mjs diff --git a/lib/nodejs/serializer.js b/lib/nodejs/serializer.js index 25d2e39727..63e1a24e51 100644 --- a/lib/nodejs/serializer.js +++ b/lib/nodejs/serializer.js @@ -259,7 +259,7 @@ class SerializableEvent { }); // mutates the object - breakCircularDeps(result); + breakCircularDeps(result.error); const pairs = Object.keys(result).map(key => [result, key]); diff --git a/test/integration/fixtures/parallel/non-circular-error.mjs b/test/integration/fixtures/parallel/non-circular-error.mjs new file mode 100644 index 0000000000..251a58b0fd --- /dev/null +++ b/test/integration/fixtures/parallel/non-circular-error.mjs @@ -0,0 +1,5 @@ +import {it} from '../../../../index.js'; + +it('test', () => { + throw new Error('Foo'); +}); diff --git a/test/integration/parallel.spec.js b/test/integration/parallel.spec.js index 5dc1d07fcd..fad184e24b 100644 --- a/test/integration/parallel.spec.js +++ b/test/integration/parallel.spec.js @@ -43,4 +43,19 @@ describe('parallel run', () => { assert.strictEqual(result.failures[0].err.message, 'Foo'); assert.strictEqual(result.failures[0].err.foo.props[0], '[Circular]'); }); + + it('should correctly handle an exception with retries', async () => { + const result = await runMochaJSONAsync('parallel/circular-error.mjs', [ + '--parallel', + '--jobs', + '2', + '--retries', + '1', + require.resolve('./fixtures/parallel/testworkerid1.mjs') + ]); + assert.strictEqual(result.stats.failures, 1); + assert.strictEqual(result.stats.passes, 1); + assert.strictEqual(result.failures[0].err.message, 'Foo'); + assert.strictEqual(result.failures[0].err.foo.props[0], '[Circular]'); + }); });