@@ -7,22 +7,32 @@ import * as process from 'node:process';
7
7
const dir = path . dirname ( url . fileURLToPath ( new URL ( import . meta. url ) ) ) ;
8
8
process . chdir ( dir ) ;
9
9
10
+ const onlyRun = process . argv . slice ( 2 ) ;
11
+
10
12
// #1: run simple test cases; these just confirm they can compile once, and run
11
13
12
14
const casesDir = 'cases' ;
13
15
try {
14
16
fs . rmSync ( 'dist/' , { recursive : true } ) ;
15
- } catch { }
17
+ } catch { }
16
18
17
19
let lastSoloFailure : string = '' ;
18
20
21
+ const success : string [ ] = [ ] ;
19
22
const errors : string [ ] = [ ] ;
20
- const cases = fs . readdirSync ( casesDir ) . filter ( ( x ) => x . endsWith ( '.js' ) ) . toSorted ( ) ;
23
+ const cases = fs
24
+ . readdirSync ( casesDir )
25
+ . filter ( ( x ) => x . endsWith ( '.js' ) )
26
+ . toSorted ( ) ;
21
27
for ( const caseToRun of cases ) {
22
28
const { name } = path . parse ( caseToRun ) ;
23
29
24
30
// strip any trailing number: test "foo2" will run after "foo1"
25
31
const soloName = name . replace ( / \d + $ / , '' ) ;
32
+ if ( onlyRun . length && ! onlyRun . includes ( soloName ) ) {
33
+ continue ;
34
+ }
35
+
26
36
try {
27
37
if ( soloName === lastSoloFailure ) {
28
38
continue ;
@@ -36,6 +46,7 @@ for (const caseToRun of cases) {
36
46
const script = path . join ( 'test' , casesDir , caseToRun ) ;
37
47
await $ `npx tsx ./app split ${ script } test/dist/${ soloName } -n index` ;
38
48
await $ `node test/dist/${ soloName } /index.js` ;
49
+ success . push ( caseToRun ) ;
39
50
} catch {
40
51
errors . push ( caseToRun ) ;
41
52
lastSoloFailure = soloName ;
@@ -44,4 +55,12 @@ for (const caseToRun of cases) {
44
55
console . info ( ) ;
45
56
}
46
57
47
- console . info ( cases . length - errors . length + '/' + cases . length , 'passed' ) ;
58
+ const total = success . length + errors . length ;
59
+ if ( total === 0 ) {
60
+ console . warn ( 'no tests matched' ) ;
61
+ process . exit ( 2 ) ; // no test run
62
+ }
63
+ console . info ( success . length + '/' + total , 'passed' ) ;
64
+ if ( errors . length ) {
65
+ process . exit ( 1 ) ;
66
+ }
0 commit comments