Skip to content

Commit da908b3

Browse files
lazergrichardlau
authored andcommitted
test_runner: report load errors with --test-isolation=none
Signed-off-by: lazerg <[email protected]> Assisted-by: Claude PR-URL: #66550 Fixes: #66549 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Ulises Gascón <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 30814ce commit da908b3

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
@@ -1167,8 +1167,8 @@ function run(options = kEmptyObject) {
11671167
topLevelTestCount,
11681168
root.subtests.length,
11691169
);
1170-
if (topLevelTestCount === root.subtests.length) {
1171-
// This file had no tests in it. Add the placeholder test.
1170+
if (threw || topLevelTestCount === root.subtests.length) {
1171+
// This file failed to load or had no tests in it. Add the placeholder test.
11721172
const subtest = root.createSubtest(Test, testFile, kEmptyObject, undefined, {
11731173
__proto__: null,
11741174
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)