10BC0 test_runner: fix test enqueue when test file has syntax error · nodejs/node@17122e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 17122e5

Browse files
geeksilva97aduh95
authored andcommitted
test_runner: fix test enqueue when test file has syntax error
PR-URL: #61573 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
1 parent 47df432 commit 17122e5

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/internal/test_runner/runner.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,10 @@ function run(options = kEmptyObject) {
874874
);
875875
if (topLevelTestCount === root.subtests.length) {
876876
// This file had no tests in it. Add the placeholder test.
877-
const subtest = root.createSubtest(Test, testFile);
877+
const subtest = root.createSubtest(Test, testFile, kEmptyObject, undefined, {
878+
__proto__: null,
879+
loc: [1, 1, resolve(testFile)],
880+
});
878881
if (threw) {
879882
subtest.fail(importError);
880883
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from 'node:test';
2+
3+
test('a test!', () => {
4+
if true {
5+
// syntax error
6+
}
7+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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', 'syntax-error-test.mjs');
8+
const testRun = run({
9+
files: [testFile],
10+
isolation: 'none'
11+
});
12+
13+
testRun.on('test:enqueue', common.mustCall((test) => {
14+
assert.strictEqual(test.file, testFile);
15+
}));
16+
17+
testRun.on('test:fail', common.mustCall((test) => {
18+
assert.match(test.details.error.toString(), /SyntaxError: Unexpected token 'true'/);
19+
}));

0 commit comments

Comments
 (0)
0