☕️ Classic, reliable, trusted test framework for Node.js and the browser
fix: propagate spec file path on parallel worker death (#6268)
michalbiesek55a544a409cc
diff --git a/lib/nodejs/parallel-buffered-runner.cjs b/lib/nodejs/parallel-buffered-runner.cjsindex 5270db88..6041c7df 100644--- a/lib/nodejs/parallel-buffered-runner.cjs+++ b/lib/nodejs/parallel-buffered-runner.cjs@@ -222,6 +222,13 @@ class ParallelBufferedRunner extends Runner {this._state = ABORTING;await pool.terminate(true);}+ if (err && typeof err === "object") {+ try {+ err.file = file;+ } catch {+ /* frozen or non-writable */+ }+ }throw err;}} finally {diff --git a/lib/runner.js b/lib/runner.jsindex 4e852ac9..1eb4152d 100644--- a/lib/runner.js+++ b/lib/runner.js@@ -1132,6 +1132,9 @@ Runner.prototype._uncaught = function (err) {runnable = new Runnable("Uncaught error outside test suite");debug("uncaught(): no current Runnable; created a phony one");runnable.parent = this.suite;+ if (err.file) {+ runnable.file = err.file;+ }if (this.state === constants.STATE_RUNNING) {debug("uncaught(): failing gracefully");diff --git a/test/integration/fixtures/parallel/worker-death.js b/test/integration/fixtures/parallel/worker-death.jsnew file mode 100644index 00000000..32369019--- /dev/null+++ b/test/integration/fixtures/parallel/worker-death.js@@ -0,0 +1,5 @@+// Fixture: a spec whose worker dies via process.exit in after()+describe('worker death', () => {+ it('passes before crash', () => {});+ after(() => process.exit(1));+});diff --git a/test/integration/parallel.spec.cjs b/test/integration/parallel.spec.cjsindex 97b6a14f..9e193eae 100644--- a/test/integration/parallel.spec.cjs+++ b/test/integration/parallel.spec.cjs@@ -77,6 +77,25 @@ describe("parallel run", () => {]);});+ it("should report the crashing spec file when a worker dies", async () => {+ // Two different spec files, two workers. The dying worker never flushes its+ // buffered events, so its passing test is lost and only test1.js reports one.+ const result = await runMochaJSONAsync("parallel/worker-death.js", [+ "--parallel",+ "--jobs",+ "2",+ require.resolve("./fixtures/parallel/test1.js"),+ ]);+ assert.deepStrictEqual(+ result.passes.map((test) => test.fullTitle),+ ["test1 should pass"],+ );+ assert.strictEqual(result.failures.length, 1);+ const failure = result.failures[0];+ assert.strictEqual(failure.title, "Uncaught error outside test suite");+ assert.match(failure.file, /worker-death\.js$/);+ });+it("should correctly handle a non-writable getter reference in an exception", async () => {const result = await runMochaJSONAsync("parallel/getter-error-object.js", ["--parallel",