From e0a0a2abc398287f32606e7bfe6fc49dce5361df Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Fri, 13 Sep 2024 04:51:35 +0200 Subject: [PATCH] test_runner: update kPatterns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/54728 Fixes: https://github.com/nodejs/node/issues/54726 Reviewed-By: Matteo Collina Reviewed-By: Michaƫl Zasso Reviewed-By: Antoine du Hamel Reviewed-By: Jake Yuesong Li Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Chemi Atlow Reviewed-By: James M Snell Reviewed-By: Moshe Atlow --- lib/internal/test_runner/utils.js | 2 +- .../test-runner/issue-54726/latest.js | 0 .../test-runner/issue-54726/non-matching.js | 0 .../matching-patterns/index-test.cjs | 4 +++ .../matching-patterns/index-test.js | 4 +++ .../matching-patterns/index-test.mjs | 4 +++ test/parallel/test-runner-cli.js | 35 +++++++++++++++++++ 7 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/test-runner/issue-54726/latest.js create mode 100644 test/fixtures/test-runner/issue-54726/non-matching.js 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/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/); +}