diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 3f9e855f755212..53e426561148cd 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -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); } diff --git a/test/fixtures/test-runner/syntax-error-test.mjs b/test/fixtures/test-runner/syntax-error-test.mjs new file mode 100644 index 00000000000000..536821087677cf --- /dev/null +++ b/test/fixtures/test-runner/syntax-error-test.mjs @@ -0,0 +1,7 @@ +import { test } from 'node:test'; + +test('a test!', () => { + if true { + // syntax error + } +}); diff --git a/test/parallel/test-runner-enqueue-file-syntax-error.js b/test/parallel/test-runner-enqueue-file-syntax-error.js new file mode 100644 index 00000000000000..d45f31a0cbdcde --- /dev/null +++ b/test/parallel/test-runner-enqueue-file-syntax-error.js @@ -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'); +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);