Skip to content

Commit d4fa353

Browse files
committed
test: speed up .only
1 parent 1b857c9 commit d4fa353

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

scripts/test.mjs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Node 20 does not support --experimental-strip-types flag.
99

1010
import {spawn, execSync} from 'node:child_process';
11+
import {globSync, readFileSync} from 'node:fs';
1112
import path from 'node:path';
1213
import process from 'node:process';
1314

@@ -38,10 +39,24 @@ if (userArgs.length > 0) {
3839
}
3940
} else {
4041
const isNode20 = process.version.startsWith('v20.');
41-
if (isNode20) {
42-
files.push('build/tests');
43-
} else {
44-
files.push('build/tests/**/*.test.js');
42+
if (flags.includes('--test-only')) {
43+
const tsFiles = globSync('tests/**/*.test.ts');
44+
for (const tsFile of tsFiles) {
45+
const content = readFileSync(tsFile, 'utf8');
46+
if (content.includes('.only(')) {
47+
files.push(path.join('build', tsFile.replace(/\.ts$/, '.js')));
48+
}
49+
}
50+
if (files.length === 0) {
51+
console.warn('no files contain .only');
52+
process.exit(0);
53+
}
54+
} else if (files.length === 0) {
55+
if (isNode20) {
56+
files.push('build/tests');
57+
} else {
58+
files.push('build/tests/**/*.test.js');
59+
}
4560
}
4661
}
4762

0 commit comments

Comments
 (0)