1
1
import { spawn } from "node:child_process" ;
2
2
import isMain from "is-main" ;
3
3
4
- async function runTests (
5
- nodeOptions : string [ ] = [ ] ,
4
+ async function runTests ( {
5
+ nodeOptions = [ ] ,
6
+ filesFilter = "" ,
6
7
program = "node" ,
7
- programOptions : string [ ] = [ ] ,
8
- env : Record < string , string > = { } ,
9
- ) : Promise < void > {
8
+ programOptions = [ ] ,
9
+ env = { } ,
10
+ } : {
11
+ nodeOptions ?: string [ ] ;
12
+ filesFilter ?: string ;
13
+ program ?: string ;
14
+ programOptions ?: string [ ] ;
15
+ env ?: Record < string , string > ;
16
+ } ) : Promise < void > {
10
17
const time = Date . now ( ) ;
11
18
12
19
return new Promise ( ( resolve , reject ) => {
@@ -18,7 +25,7 @@ async function runTests(
18
25
"--experimental-strip-types" ,
19
26
"--test" ,
20
27
...nodeOptions ,
21
- "src/**/*.test.ts" ,
28
+ filesFilter !== "" ? filesFilter : "src/**/*.test.ts" ,
22
29
] ,
23
30
{ stdio : "inherit" , env : { ...process . env , ...env } } ,
24
31
) ;
@@ -38,27 +45,29 @@ async function runTests(
38
45
}
39
46
40
47
if ( isMain ( import . meta) ) {
48
+ const filesFilter = process . argv . slice ( 3 ) . join ( " " ) . trim ( ) ;
49
+
41
50
if ( process . argv [ 2 ] === "test" ) {
42
- await runTests ( ) ;
51
+ await runTests ( { filesFilter } ) ;
43
52
}
44
53
45
54
if ( process . argv [ 2 ] === "test:inspect" ) {
46
- await runTests ( [ "--inspect" ] ) ;
55
+ await runTests ( { nodeOptions : [ "--inspect" ] , filesFilter } ) ;
47
56
}
48
57
49
58
if ( process . argv [ 2 ] === "test:watch" ) {
50
- await runTests ( [ "--watch" ] ) ;
59
+ await runTests ( { nodeOptions : [ "--watch" ] , filesFilter } ) ;
51
60
}
52
61
53
62
if ( process . argv [ 2 ] === "test:coverage" ) {
54
- await runTests (
55
- [ "--experimental-test-coverage" ] ,
56
- "c8" ,
57
- [ "-r" , "html" , "node" ] ,
58
- {
63
+ await runTests ( {
64
+ nodeOptions : [ "--experimental-test-coverage" ] ,
65
+ program : "c8" ,
66
+ programOptions : [ "-r" , "html" , "node" ] ,
67
+ env : {
59
68
// biome-ignore lint/style/useNamingConvention: node options
60
69
NODE_V8_COVERAGE : "./coverage" ,
61
70
} ,
62
- ) ;
71
+ } ) ;
63
72
}
64
73
}
0 commit comments