From 09ab6af339162cf416b829e09ab27f2534ee08ba Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Wed, 28 Jan 2026 23:53:06 -0300 Subject: [PATCH 1/4] test_runner: fix test enqueue when test file has syntax error --- lib/internal/test_runner/runner.js | 5 ++++- .../test-runner/syntax-error-test.mjs | 7 ++++++ .../test-runner-enqueue-file-syntax-error.js | 22 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/test-runner/syntax-error-test.mjs create mode 100644 test/parallel/test-runner-enqueue-file-syntax-error.js diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 3f9e855f755212..5ab1bf2229bd02 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, { __proto__: null }, 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..a0f5de6dde1d69 --- /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 + } +}); \ No newline at end of file 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..28418f2c27c05c --- /dev/null +++ b/test/parallel/test-runner-enqueue-file-syntax-error.js @@ -0,0 +1,22 @@ +// Flags: --no-warnings +'use strict'; +const common = require('../common'); +const assert = require('node:assert'); +const { run } = require('node:test'); +const fixtures = require('../common/fixtures'); + +const testFile = fixtures.path('test-runner', 'syntax-error-test.mjs'); +const stream = run({ + files: [testFile], + isolation: 'none', +}); + +stream.on('test:enqueue', common.mustCall((data) => { + assert.ok(data.file, 'test:enqueue event should have file field'); + assert.strictEqual(data.file, testFile); +})); + +stream.on('test:fail', common.mustCall((data) => { + assert.ok(data.details.error); + assert.ok(/SyntaxError/.test(data.details.error.name)); +})); From 742a56d8689d2202c8677e7a8e2c73d7d527556b Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Thu, 29 Jan 2026 00:03:23 -0300 Subject: [PATCH 2/4] fix linter issues --- test/parallel/test-runner-enqueue-file-syntax-error.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-runner-enqueue-file-syntax-error.js b/test/parallel/test-runner-enqueue-file-syntax-error.js index 28418f2c27c05c..51e5d738d4eef0 100644 --- a/test/parallel/test-runner-enqueue-file-syntax-error.js +++ b/test/parallel/test-runner-enqueue-file-syntax-error.js @@ -18,5 +18,5 @@ stream.on('test:enqueue', common.mustCall((data) => { stream.on('test:fail', common.mustCall((data) => { assert.ok(data.details.error); - assert.ok(/SyntaxError/.test(data.details.error.name)); + assert.match(data.details.error.message, /SyntaxError/); })); From 3a2b935c7ec9591f75d44abf89e3f0de9f44bde0 Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Thu, 29 Jan 2026 10:06:14 -0300 Subject: [PATCH 3/4] fix test --- .../test-runner-enqueue-file-syntax-error.js | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/test/parallel/test-runner-enqueue-file-syntax-error.js b/test/parallel/test-runner-enqueue-file-syntax-error.js index 51e5d738d4eef0..cb5c1c39cd5d43 100644 --- a/test/parallel/test-runner-enqueue-file-syntax-error.js +++ b/test/parallel/test-runner-enqueue-file-syntax-error.js @@ -1,22 +1,19 @@ -// Flags: --no-warnings 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('node:assert'); -const { run } = require('node:test'); +const { spawnSync } = require('node:child_process'); const fixtures = require('../common/fixtures'); const testFile = fixtures.path('test-runner', 'syntax-error-test.mjs'); -const stream = run({ - files: [testFile], - isolation: 'none', -}); +const child = spawnSync(process.execPath, [ + '--no-warnings', + '--test', + '--test-reporter=tap', + '--test-isolation=none', + testFile, +], { encoding: 'utf8' }); -stream.on('test:enqueue', common.mustCall((data) => { - assert.ok(data.file, 'test:enqueue event should have file field'); - assert.strictEqual(data.file, testFile); -})); - -stream.on('test:fail', common.mustCall((data) => { - assert.ok(data.details.error); - assert.match(data.details.error.message, /SyntaxError/); -})); +assert.match(child.stdout, new RegExp(`# Subtest: ${testFile}`)); +assert.match(child.stdout, /location:.*syntax-error-test\.mjs/); +assert.match(child.stdout, /SyntaxError/); +assert.strictEqual(child.status, 1); From ffdc923e774ee2b1e3b2ce6bca71bbc4931819de Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Thu, 29 Jan 2026 14:51:45 -0300 Subject: [PATCH 4/4] apply review suggestions --- lib/internal/test_runner/runner.js | 2 +- test/fixtures/test-runner/syntax-error-test.mjs | 2 +- test/parallel/test-runner-enqueue-file-syntax-error.js | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 5ab1bf2229bd02..53e426561148cd 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -851,7 +851,7 @@ 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, { __proto__: null }, undefined, { + const subtest = root.createSubtest(Test, testFile, kEmptyObject, undefined, { __proto__: null, loc: [1, 1, resolve(testFile)], }); diff --git a/test/fixtures/test-runner/syntax-error-test.mjs b/test/fixtures/test-runner/syntax-error-test.mjs index a0f5de6dde1d69..536821087677cf 100644 --- a/test/fixtures/test-runner/syntax-error-test.mjs +++ b/test/fixtures/test-runner/syntax-error-test.mjs @@ -4,4 +4,4 @@ test('a test!', () => { if true { // syntax error } -}); \ No newline at end of file +}); diff --git a/test/parallel/test-runner-enqueue-file-syntax-error.js b/test/parallel/test-runner-enqueue-file-syntax-error.js index cb5c1c39cd5d43..d45f31a0cbdcde 100644 --- a/test/parallel/test-runner-enqueue-file-syntax-error.js +++ b/test/parallel/test-runner-enqueue-file-syntax-error.js @@ -13,7 +13,6 @@ const child = spawnSync(process.execPath, [ testFile, ], { encoding: 'utf8' }); -assert.match(child.stdout, new RegExp(`# Subtest: ${testFile}`)); -assert.match(child.stdout, /location:.*syntax-error-test\.mjs/); +assert.match(child.stdout, /error:.*"Unexpected token 'true'"\n/); assert.match(child.stdout, /SyntaxError/); assert.strictEqual(child.status, 1);