test_runner: support typescript files in default glob

PR-URL: https://github.com/nodejs/node/pull/55081
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Aviv Keller
2024-09-28 22:47:48 -04:00
committed by GitHub
parent e225f00034
commit 27dab9d916
6 changed files with 55 additions and 8 deletions

View File

@@ -422,12 +422,22 @@ node --test
By default, Node.js will run all files matching these patterns:
* `**/*.test.?(c|m)js`
* `**/*-test.?(c|m)js`
* `**/*_test.?(c|m)js`
* `**/test-*.?(c|m)js`
* `**/test.?(c|m)js`
* `**/test/**/*.?(c|m)js`
* `**/*.test.{cjs,mjs,js}`
* `**/*-test.{cjs,mjs,js}`
* `**/*_test.{cjs,mjs,js}`
* `**/test-*.{cjs,mjs,js}`
* `**/test.{cjs,mjs,js}`
* `**/test/**/*.{cjs,mjs,js}`
When [`--experimental-strip-types`][] is supplied, the following
additional patterns are matched:
* `**/*.test.{cts,mts,ts}`
* `**/*-test.{cts,mts,ts}`
* `**/*_test.{cts,mts,ts}`
* `**/test-*.{cts,mts,ts}`
* `**/test.{cts,mts,ts}`
* `**/test/**/*.{cts,mts,ts}`
Alternatively, one or more glob patterns can be provided as the
final argument(s) to the Node.js command, as shown below.
@@ -3568,6 +3578,7 @@ added:
Can be used to abort test subtasks when the test has been aborted.
[TAP]: https://testanything.org/
[`--experimental-strip-types`]: cli.md#--experimental-strip-types
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
[`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks
[`--experimental-test-snapshots`]: cli.md#--experimental-test-snapshots

View File

@@ -54,8 +54,11 @@ const kMultipleCallbackInvocations = 'multipleCallbackInvocations';
const kRegExpPattern = /^\/(.*)\/([a-z]*)$/;
const kPatterns = ['test', 'test/**/*', 'test-*', '*[._-]test'];
const kDefaultPattern = `**/{${ArrayPrototypeJoin(kPatterns, ',')}}.?(c|m)js`;
const kFileExtensions = ['js', 'mjs', 'cjs'];
if (getOptionValue('--experimental-strip-types')) {
ArrayPrototypePush(kFileExtensions, 'ts', 'mts', 'cts');
}
const kDefaultPattern = `**/{${ArrayPrototypeJoin(kPatterns, ',')}}.{${ArrayPrototypeJoin(kFileExtensions, ',')}}`;
function createDeferredCallback() {
let calledCount = 0;

View File

@@ -0,0 +1,4 @@
const test = require('node:test');
// 'as string' ensures that type stripping actually occurs
test('this should pass' as string);

View File

@@ -0,0 +1,4 @@
import { test } from 'node:test';
// 'as string' ensures that type stripping actually occurs
test('this should pass' as string);

View File

@@ -0,0 +1,4 @@
const test = require('node:test');
// 'as string' ensures that type stripping actually occurs
test('this should pass' as string);

View File

@@ -57,6 +57,27 @@ for (const isolation of ['none', 'process']) {
assert.match(stdout, /ok 1 - this should pass/);
assert.match(stdout, /ok 2 - this should pass/);
assert.match(stdout, /ok 3 - this should pass/);
// Doesn't match the TypeScript files
assert.doesNotMatch(stdout, /ok 4 - this should pass/);
}
for (const type of ['strip', 'transform']) {
// Should match files with "-test.(c|m)(t|j)s" suffix when typescript support is enabled
const args = ['--test', '--test-reporter=tap', '--no-warnings',
`--experimental-${type}-types`, `--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/);
assert.match(stdout, /ok 4 - this should pass/);
assert.match(stdout, /ok 5 - this should pass/);
assert.match(stdout, /ok 6 - this should pass/);
}
{