Skip to content

Commit

Permalink
test_runner: support typescript files in default glob
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Sep 23, 2024
1 parent 96ec7ee commit 0a4f389
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const test = require('node:test');

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

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

// 'as string' ensures that type stripping actually occurs
test('this should pass' as string);
6 changes: 5 additions & 1 deletion test/parallel/test-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ for (const isolation of ['none', 'process']) {
}

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

Expand All @@ -57,6 +58,9 @@ 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/);
assert.match(stdout, /ok 4 - this should pass/);
assert.match(stdout, /ok 5 - this should pass/);
assert.match(stdout, /ok 6 - this should pass/);
}

{
Expand Down

0 comments on commit 0a4f389

Please sign in to comment.