Skip to content

Commit 6d5e309

Browse files
authored
test_runner: report load errors with --test-isolation=none
Signed-off-by: lazerg <lazerg2@gmail.com> Assisted-by: Claude PR-URL: #66550 Fixes: #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>
1 parent 9899b39 commit 6d5e309

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎lib/internal/test_runner/runner.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,8 @@ function run(options = kEmptyObject) {
11661166
topLevelTestCount,
11671167
root.subtests.length,
11681168
);
1169-
if (topLevelTestCount === root.subtests.length) {
1170-
// This file had no tests in it. Add the placeholder test.
1169+
if (threw || topLevelTestCount === root.subtests.length) {
1170+
// This file failed to load or had no tests in it. Add the placeholder test.
11711171
const subtest = root.createSubtest(Test, testFile, kEmptyObject, undefined, {
11721172
__proto__: null,
11731173
loc: [1, 1, resolve(testFile)],
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from 'node:test';
2+
3+
test('registered before the error', () => {});
4+
null.x;
5+
test('never registered', () => {});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('node:assert');
4+
const fixtures = require('../common/fixtures');
5+
const { run } = require('node:test');
6+
7+
const testFile = fixtures.path('test-runner', 'throws-after-test.mjs');
8+
const testRun = run({
9+
files: [testFile],
10+
isolation: 'none'
11+
});
12+
13+
testRun.on('test:pass', common.mustCall((test) => {
14+
assert.strictEqual(test.name, 'registered before the error');
15+
}));
16+
17+
testRun.on('test:fail', common.mustCall((test) => {
18+
assert.strictEqual(test.name, testFile);
19+
assert.match(test.details.error.toString(), /TypeError: Cannot read properties of null/);
20+
}));

0 commit comments

Comments
 (0)