Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 17122e5

Browse filesBrowse 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
Copy full SHA for 17122e5

3 files changed

+30-1Lines changed: 30 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/test_runner/runner.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js
+4-1Lines 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
}
Collapse file
+7Lines 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+
});
Collapse file
+19Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.