mocha
mocha copied to clipboard
🐛 Bug: Parallel mode crashes if test exception contains circular references
Prerequisites
- [x] Checked that your issue hasn't already been filed by cross-referencing issues with the
faqlabel - [x] Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
- [x] 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
- [x] Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
node node_modules/.bin/mocha --version(Local) andmocha --version(Global). We recommend that you not install Mocha globally.
Description
Parallel mode crashes or hangs if test exception contains circular references
Steps to Reproduce
1. Hangs if error has self reference:
Test file test.js
describe('Test', () => {
it('test', () => {
const error = new Error('Foo');
error.self = error;
throw error;
});
});
Running following will simply hang:
$ mocha --parallel test.js
2. Crashes if error has circular references passed within array properties
Test file test.js
describe('Test', () => {
it('test', () => {
const error = new Error('Foo');
error.foo = { props: [] };
error.foo.props.push(error.foo);
throw error;
});
});
Running following
$ mocha --parallel test.js
will result with an error as:
1) Uncaught error outside test suite
0 passing (308ms)
1 failing
1) Uncaught error outside test suite:
Uncaught TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'props' -> object with constructor 'Array'
--- index 0 closes the circle
at stringify (<anonymous>)
at writeChannelMessage (node:internal/child_process/serialization:120:20)
at process.target._send (node:internal/child_process:819:17)
at process.target.send (node:internal/child_process:719:19)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
Expected behavior:
Originally thrown exception should surface in report
Versions
- The output of
mocha --versionandnode node_modules/.bin/mocha --version: 8.2.1 - The output of
node --version: 15.5.1 - Your operating system
- name and version: macOS 10.15.7
- architecture (32 or 64-bit): 64-bit
- Your shell (e.g., bash, zsh, PowerShell, cmd): zsh
This PR hopefully help with the second case (which is something we were seeing when developing with nestjs): https://github.com/mochajs/mocha/pull/5032
Heh, on my machine now it just ... hangs indefinitely. Fun.
Similar yet not similar to #4910