Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

fix: crash with --parallel and --retries both enabled (#5173)

Josh Goldberg ✨d7013ddb1099
diff --git a/lib/nodejs/serializer.js b/lib/nodejs/serializer.js
index 25d2e397..63e1a24e 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 00000000..251a58b0
--- /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 5dc1d07f..fad184e2 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]');
+ });
});