diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index 7f78bddf4bef40..041c9b68b600da 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -51,7 +51,7 @@ const coverageColors = { const kMultipleCallbackInvocations = 'multipleCallbackInvocations'; const kRegExpPattern = /^\/(.*)\/([a-z]*)$/; -const kPatterns = ['test', 'test/**/*', 'test-*', '*[.-_]test']; +const kPatterns = ['test', 'test/**/*', 'test-*', '*[._-]test']; const kDefaultPattern = `**/{${ArrayPrototypeJoin(kPatterns, ',')}}.?(c|m)js`; diff --git a/test/fixtures/test-runner/issue-54726/latest.js b/test/fixtures/test-runner/issue-54726/latest.js new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/fixtures/test-runner/issue-54726/non-matching.js b/test/fixtures/test-runner/issue-54726/non-matching.js new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/fixtures/test-runner/matching-patterns/index-test.cjs b/test/fixtures/test-runner/matching-patterns/index-test.cjs new file mode 100644 index 00000000000000..2a722c504b9fa5 --- /dev/null +++ b/test/fixtures/test-runner/matching-patterns/index-test.cjs @@ -0,0 +1,4 @@ +'use strict'; +const test = require('node:test'); + +test('this should pass'); diff --git a/test/fixtures/test-runner/matching-patterns/index-test.js b/test/fixtures/test-runner/matching-patterns/index-test.js new file mode 100644 index 00000000000000..2a722c504b9fa5 --- /dev/null +++ b/test/fixtures/test-runner/matching-patterns/index-test.js @@ -0,0 +1,4 @@ +'use strict'; +const test = require('node:test'); + +test('this should pass'); diff --git a/test/fixtures/test-runner/matching-patterns/index-test.mjs b/test/fixtures/test-runner/matching-patterns/index-test.mjs new file mode 100644 index 00000000000000..49290287eb348c --- /dev/null +++ b/test/fixtures/test-runner/matching-patterns/index-test.mjs @@ -0,0 +1,4 @@ +'use strict'; +import test from 'node:test'; + +test('this should pass'); diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 8610d512561dff..6ba4516673fb79 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -43,6 +43,22 @@ for (const isolation of ['none', 'process']) { assert.match(stdout, /ok 6 - this should be executed/); } + { + // Should match files with "-test.(c|m)js" suffix. + const args = ['--test', '--test-reporter=tap', + `--experimental-test-isolation=${isolation}`]; + const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'matching-patterns') }); + + assert.strictEqual(child.status, 0); + assert.strictEqual(child.signal, null); + assert.strictEqual(child.stderr.toString(), ''); + const stdout = child.stdout.toString(); + + assert.match(stdout, /ok 1 - this should pass/); + assert.match(stdout, /ok 2 - this should pass/); + assert.match(stdout, /ok 3 - this should pass/); + } + { // Same but with a prototype mutation in require scripts. const args = [ @@ -361,3 +377,22 @@ for (const isolation of ['none', 'process']) { assert.match(stdout, /# fail 0/); assert.match(stdout, /# skipped 0/); } + +{ + // Should not match files like latest.js + const args = ['--test', '--test-reporter=tap']; + const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'issue-54726') }); + + assert.strictEqual(child.status, 0); + assert.strictEqual(child.signal, null); + assert.strictEqual(child.stderr.toString(), ''); + const stdout = child.stdout.toString(); + + assert.match(stdout, /tests 0/); + assert.match(stdout, /suites 0/); + assert.match(stdout, /pass 0/); + assert.match(stdout, /fail 0/); + assert.match(stdout, /cancelled 0/); + assert.match(stdout, /skipped 0/); + assert.match(stdout, /todo 0/); +}