Skip to content

Commit

Permalink
test_runner: update kPatterns
Browse files Browse the repository at this point in the history
PR-URL: #54728
Fixes: #54726
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
  • Loading branch information
pmarchini authored and RafaelGSS committed Sep 17, 2024
1 parent 7a1d633 commit 6552fdd
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;


Expand Down
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions test/fixtures/test-runner/matching-patterns/index-test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');

test('this should pass');
4 changes: 4 additions & 0 deletions test/fixtures/test-runner/matching-patterns/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');

test('this should pass');
4 changes: 4 additions & 0 deletions test/fixtures/test-runner/matching-patterns/index-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';
import test from 'node:test';

test('this should pass');
35 changes: 35 additions & 0 deletions test/parallel/test-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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/);
}

0 comments on commit 6552fdd

Please sign in to comment.