Skip to content

Commit 0a4f389

Browse files
committed
test_runner: support typescript files in default glob
1 parent 96ec7ee commit 0a4f389

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

lib/internal/test_runner/utils.js

Lines 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;
Lines 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);
Lines 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);
Lines 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);

test/parallel/test-runner-cli.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ for (const isolation of ['none', 'process']) {
4444
}
4545

4646
{
47-
// Should match files with "-test.(c|m)js" suffix.
47+
// Should match files with "-test.(c|m)(j|t)s" suffix.
4848
const args = ['--test', '--test-reporter=tap',
49+
'--no-warnings', '--experimental-strip-types',
4950
`--experimental-test-isolation=${isolation}`];
5051
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'matching-patterns') });
5152

@@ -57,6 +58,9 @@ for (const isolation of ['none', 'process']) {
5758
assert.match(stdout, /ok 1 - this should pass/);
5859
assert.match(stdout, /ok 2 - this should pass/);
5960
assert.match(stdout, /ok 3 - this should pass/);
61+
assert.match(stdout, /ok 4 - this should pass/);
62+
assert.match(stdout, /ok 5 - this should pass/);
63+
assert.match(stdout, /ok 6 - this should pass/);
6064
}
6165

6266
{

0 commit comments

Comments
 (0)