From 3c678b666adf36951457f1db617c8991776e54b5 Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Tue, 10 Sep 2024 15:15:24 +0200 Subject: [PATCH 1/4] test_runner: update kPatterns --- lib/internal/test_runner/utils.js | 2 +- test/fixtures/test-runner/54726/latest.js | 0 .../test-runner/54726/non-matching.js | 0 test/parallel/test-runner-cli.js | 19 +++++++++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/test-runner/54726/latest.js create mode 100644 test/fixtures/test-runner/54726/non-matching.js diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index 0d6fab11d10d82..2fc0907c388780 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/54726/latest.js b/test/fixtures/test-runner/54726/latest.js new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/fixtures/test-runner/54726/non-matching.js b/test/fixtures/test-runner/54726/non-matching.js new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 8610d512561dff..4b3eaec1f1b99c 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -361,3 +361,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, '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/); +} From 14d1cbcd12b08c3a376ad2ecf02203b89c88a181 Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Tue, 10 Sep 2024 15:15:24 +0200 Subject: [PATCH 2/4] test: rename repro name --- test/fixtures/test-runner/{54726 => issue-54726}/latest.js | 0 .../fixtures/test-runner/{54726 => issue-54726}/non-matching.js | 0 test/parallel/test-runner-cli.js | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename test/fixtures/test-runner/{54726 => issue-54726}/latest.js (100%) rename test/fixtures/test-runner/{54726 => issue-54726}/non-matching.js (100%) diff --git a/test/fixtures/test-runner/54726/latest.js b/test/fixtures/test-runner/issue-54726/latest.js similarity index 100% rename from test/fixtures/test-runner/54726/latest.js rename to test/fixtures/test-runner/issue-54726/latest.js diff --git a/test/fixtures/test-runner/54726/non-matching.js b/test/fixtures/test-runner/issue-54726/non-matching.js similarity index 100% rename from test/fixtures/test-runner/54726/non-matching.js rename to test/fixtures/test-runner/issue-54726/non-matching.js diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 4b3eaec1f1b99c..a1e3e2d85554e4 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -365,7 +365,7 @@ for (const isolation of ['none', 'process']) { { // Should not match files like latest.js . const args = ['--test', '--test-reporter=tap']; - const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, '54726') }); + const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'issue-54726') }); assert.strictEqual(child.status, 0); assert.strictEqual(child.signal, null); From a052c0b981203074255ffe416f001a78a52f8006 Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Tue, 10 Sep 2024 15:15:24 +0200 Subject: [PATCH 3/4] test: add -test.(c|m)js test cases --- .../test-runner/matching-patterns/index-test.cjs | 4 ++++ .../test-runner/matching-patterns/index-test.js | 4 ++++ .../test-runner/matching-patterns/index-test.mjs | 4 ++++ test/parallel/test-runner-cli.js | 16 ++++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 test/fixtures/test-runner/matching-patterns/index-test.cjs create mode 100644 test/fixtures/test-runner/matching-patterns/index-test.js create mode 100644 test/fixtures/test-runner/matching-patterns/index-test.mjs 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 a1e3e2d85554e4..490893b671d9c3 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 = [ From 318f0d28ba1d00beba4d904e42a164860aa10769 Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Tue, 10 Sep 2024 15:15:24 +0200 Subject: [PATCH 4/4] test: minor --- test/parallel/test-runner-cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 490893b671d9c3..6ba4516673fb79 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -379,7 +379,7 @@ for (const isolation of ['none', 'process']) { } { - // Should not match files like latest.js . + // Should not match files like latest.js const args = ['--test', '--test-reporter=tap']; const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'issue-54726') });