Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1240197

Browse filesBrowse files
avivkellertargos
authored andcommitted
test_runner: support typescript files in default glob
PR-URL: #55081 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7982d3d commit 1240197
Copy full SHA for 1240197

File tree

Expand file treeCollapse file tree

6 files changed

+55
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+55
-8
lines changed
Open diff view settings
Collapse file

‎doc/api/test.md‎

Copy file name to clipboardExpand all lines: doc/api/test.md
+17-6Lines changed: 17 additions & 6 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,22 @@ node --test
422422

423423
By default, Node.js will run all files matching these patterns:
424424

425-
* `**/*.test.?(c|m)js`
426-
* `**/*-test.?(c|m)js`
427-
* `**/*_test.?(c|m)js`
428-
* `**/test-*.?(c|m)js`
429-
* `**/test.?(c|m)js`
430-
* `**/test/**/*.?(c|m)js`
425+
* `**/*.test.{cjs,mjs,js}`
426+
* `**/*-test.{cjs,mjs,js}`
427+
* `**/*_test.{cjs,mjs,js}`
428+
* `**/test-*.{cjs,mjs,js}`
429+
* `**/test.{cjs,mjs,js}`
430+
* `**/test/**/*.{cjs,mjs,js}`
431+
432+
When [`--experimental-strip-types`][] is supplied, the following
433+
additional patterns are matched:
434+
435+
* `**/*.test.{cts,mts,ts}`
436+
* `**/*-test.{cts,mts,ts}`
437+
* `**/*_test.{cts,mts,ts}`
438+
* `**/test-*.{cts,mts,ts}`
439+
* `**/test.{cts,mts,ts}`
440+
* `**/test/**/*.{cts,mts,ts}`
431441

432442
Alternatively, one or more glob patterns can be provided as the
433443
final argument(s) to the Node.js command, as shown below.
@@ -3558,6 +3568,7 @@ Can be used to abort test subtasks when the test has been aborted.
35583568

35593569
[TAP]: https://testanything.org/
35603570
[TTY]: tty.md
3571+
[`--experimental-strip-types`]: cli.md#--experimental-strip-types
35613572
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
35623573
[`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks
35633574
[`--experimental-test-snapshots`]: cli.md#--experimental-test-snapshots
Collapse file

‎lib/internal/test_runner/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/utils.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ const kMultipleCallbackInvocations = 'multipleCallbackInvocations';
5454
const kRegExpPattern = /^\/(.*)\/([a-z]*)$/;
5555

5656
const kPatterns = ['test', 'test/**/*', 'test-*', '*[._-]test'];
57-
const kDefaultPattern = `**/{${ArrayPrototypeJoin(kPatterns, ',')}}.?(c|m)js`;
58-
57+
const kFileExtensions = ['js', 'mjs', 'cjs'];
58+
if (getOptionValue('--experimental-strip-types')) {
59+
ArrayPrototypePush(kFileExtensions, 'ts', 'mts', 'cts');
60+
}
61+
const kDefaultPattern = `**/{${ArrayPrototypeJoin(kPatterns, ',')}}.{${ArrayPrototypeJoin(kFileExtensions, ',')}}`;
5962

6063
function createDeferredCallback() {
6164
let calledCount = 0;
Collapse file
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const test = require('node:test');
2+
3+
// 'as string' ensures that type stripping actually occurs
4+
test('this should pass' as string);
Collapse file
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { test } from 'node:test';
2+
3+
// 'as string' ensures that type stripping actually occurs
4+
test('this should pass' as string);
Collapse file
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const test = require('node:test');
2+
3+
// 'as string' ensures that type stripping actually occurs
4+
test('this should pass' as string);
Collapse file

‎test/parallel/test-runner-cli.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-runner-cli.js
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ for (const isolation of ['none', 'process']) {
5757
assert.match(stdout, /ok 1 - this should pass/);
5858
assert.match(stdout, /ok 2 - this should pass/);
5959
assert.match(stdout, /ok 3 - this should pass/);
60+
// Doesn't match the TypeScript files
61+
assert.doesNotMatch(stdout, /ok 4 - this should pass/);
62+
}
63+
64+
for (const type of ['strip', 'transform']) {
65+
// Should match files with "-test.(c|m)(t|j)s" suffix when typescript support is enabled
66+
const args = ['--test', '--test-reporter=tap', '--no-warnings',
67+
`--experimental-${type}-types`, `--experimental-test-isolation=${isolation}`];
68+
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'matching-patterns') });
69+
70+
assert.strictEqual(child.status, 0);
71+
assert.strictEqual(child.signal, null);
72+
assert.strictEqual(child.stderr.toString(), '');
73+
const stdout = child.stdout.toString();
74+
75+
assert.match(stdout, /ok 1 - this should pass/);
76+
assert.match(stdout, /ok 2 - this should pass/);
77+
assert.match(stdout, /ok 3 - this should pass/);
78+
assert.match(stdout, /ok 4 - this should pass/);
79+
assert.match(stdout, /ok 5 - this should pass/);
80+
assert.match(stdout, /ok 6 - this should pass/);
6081
}
6182

6283
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.