Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,10 @@ function run(options = kEmptyObject) {
);
if (topLevelTestCount === root.subtests.length) {
// This file had no tests in it. Add the placeholder test.
const subtest = root.createSubtest(Test, testFile);
const subtest = root.createSubtest(Test, testFile, kEmptyObject, undefined, {
__proto__: null,
loc: [1, 1, resolve(testFile)],
});
if (threw) {
subtest.fail(importError);
}
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/test-runner/syntax-error-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'node:test';

test('a test!', () => {
if true {
// syntax error
}
});
18 changes: 18 additions & 0 deletions test/parallel/test-runner-enqueue-file-syntax-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
require('../common');
const assert = require('node:assert');
const { spawnSync } = require('node:child_process');
const fixtures = require('../common/fixtures');

const testFile = fixtures.path('test-runner', 'syntax-error-test.mjs');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the original issue states "test:enqueue event has no file field", should we cover it with a test?

const child = spawnSync(process.execPath, [
'--no-warnings',
'--test',
'--test-reporter=tap',
'--test-isolation=none',
testFile,
], { encoding: 'utf8' });

assert.match(child.stdout, /error:.*"Unexpected token 'true'"\n/);
assert.match(child.stdout, /SyntaxError/);
assert.strictEqual(child.status, 1);
Loading