mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
4
test/fixtures/test-runner/matching-patterns/typescript-test.cts
vendored
Normal file
4
test/fixtures/test-runner/matching-patterns/typescript-test.cts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
const test = require('node:test');
|
||||
|
||||
// 'as string' ensures that type stripping actually occurs
|
||||
test('this should pass' as string);
|
||||
4
test/fixtures/test-runner/matching-patterns/typescript-test.mts
vendored
Normal file
4
test/fixtures/test-runner/matching-patterns/typescript-test.mts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { test } from 'node:test';
|
||||
|
||||
// 'as string' ensures that type stripping actually occurs
|
||||
test('this should pass' as string);
|
||||
4
test/fixtures/test-runner/matching-patterns/typescript-test.ts
vendored
Normal file
4
test/fixtures/test-runner/matching-patterns/typescript-test.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
const test = require('node:test');
|
||||
|
||||
// 'as string' ensures that type stripping actually occurs
|
||||
test('this should pass' as string);
|
||||
@@ -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/);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user