Commit 6d5e3098711 for nodejs
commit 6d5e30987117e072bb4638c0535946464a314b7e
Author: Lazizbek Ergashev <lazerg2@gmail.com>
Date: Thu Oct 8 08:54:07 2026 +0500
test_runner: report load errors with --test-isolation=none
Signed-off-by: lazerg <lazerg2@gmail.com>
Assisted-by: Claude
PR-URL: https://github.com/nodejs/node/pull/66550
Fixes: https://github.com/nodejs/node/issues/66549
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js
index 03ab8ee1c63..b3d1b30b12e 100644
--- a/lib/internal/test_runner/runner.js
+++ b/lib/internal/test_runner/runner.js
@@ -1166,8 +1166,8 @@ function run(options = kEmptyObject) {
topLevelTestCount,
root.subtests.length,
);
- if (topLevelTestCount === root.subtests.length) {
- // This file had no tests in it. Add the placeholder test.
+ if (threw || topLevelTestCount === root.subtests.length) {
+ // This file failed to load or had no tests in it. Add the placeholder test.
const subtest = root.createSubtest(Test, testFile, kEmptyObject, undefined, {
__proto__: null,
loc: [1, 1, resolve(testFile)],
diff --git a/test/fixtures/test-runner/throws-after-test.mjs b/test/fixtures/test-runner/throws-after-test.mjs
new file mode 100644
index 00000000000..45b8efca56e
--- /dev/null
+++ b/test/fixtures/test-runner/throws-after-test.mjs
@@ -0,0 +1,5 @@
+import { test } from 'node:test';
+
+test('registered before the error', () => {});
+null.x;
+test('never registered', () => {});
diff --git a/test/parallel/test-runner-no-isolation-load-error.js b/test/parallel/test-runner-no-isolation-load-error.js
new file mode 100644
index 00000000000..cfd23610ec9
--- /dev/null
+++ b/test/parallel/test-runner-no-isolation-load-error.js
@@ -0,0 +1,20 @@
+'use strict';
+const common = require('../common');
+const assert = require('node:assert');
+const fixtures = require('../common/fixtures');
+const { run } = require('node:test');
+
+const testFile = fixtures.path('test-runner', 'throws-after-test.mjs');
+const testRun = run({
+ files: [testFile],
+ isolation: 'none'
+});
+
+testRun.on('test:pass', common.mustCall((test) => {
+ assert.strictEqual(test.name, 'registered before the error');
+}));
+
+testRun.on('test:fail', common.mustCall((test) => {
+ assert.strictEqual(test.name, testFile);
+ assert.match(test.details.error.toString(), /TypeError: Cannot read properties of null/);
+}));