15
15
import * as fs from 'node:fs' ;
16
16
import * as git from './git' ;
17
17
import * as path from 'path' ;
18
- import { List , Map , Set } from 'immutable' ;
19
- import { minimatch } from 'minimatch' ; /* eslint-disable @typescript-eslint/no-explicit-any */
20
- import { Affected , TestAll , TestName , TestPath , mergeAffected } from './affected' ;
18
+ import { List , Map , Set } from 'immutable' ;
19
+ import { minimatch } from 'minimatch' ; /* eslint-disable @typescript-eslint/no-explicit-any */
20
+ import { Affected , TestAll , TestName , TestPath , mergeAffected } from './affected' ;
21
+
22
+ type RunTestsAll = {
23
+ root : string
24
+ path : string
25
+ }
26
+
27
+ type RunTestsSome = {
28
+ root : string
29
+ path : string
30
+ tests : Map < TestPath , Set < TestName > > ;
31
+ }
21
32
22
33
export class Config {
23
34
match : List < string > ;
24
35
ignore : List < string > ;
25
36
packageFile : List < string > ;
26
- testAll : ( ) => void ;
27
- testSome : ( tests : Map < TestPath , Set < TestName > > ) => void ;
37
+ testAll : ( _ : RunTestsAll ) => void ;
38
+ testSome : ( _ : RunTestsSome ) => void ;
28
39
29
40
constructor ( {
30
41
match,
@@ -36,16 +47,14 @@ export class Config {
36
47
match ?: string [ ] ;
37
48
ignore ?: string [ ] ;
38
49
packageFile ?: string [ ] ;
39
- testAll ?: ( ) => void ;
40
- testSome ?: ( tests : Map < TestPath , Set < TestName > > ) => void ;
50
+ testAll ?: ( _ : RunTestsAll ) => void ;
51
+ testSome ?: ( _ : RunTestsSome ) => void ;
41
52
} ) {
42
53
this . match = List ( match || [ '**' ] ) ;
43
54
this . ignore = List ( ignore ) ;
44
55
this . packageFile = List ( packageFile ) ;
45
- this . testAll = testAll || ( ( ) => { } ) ;
46
- this . testSome =
47
- testSome ||
48
- ( _ => { } ) ; /* eslint-disable @typescript-eslint/no-unused-vars */
56
+ this . testAll = testAll || ( _ => { } ) ;
57
+ this . testSome = testSome || ( _ => { } ) ;
49
58
}
50
59
51
60
affected = ( head : string , main : string ) : List < Affected > =>
@@ -61,14 +70,19 @@ export class Config {
61
70
62
71
test = ( affected : Affected ) => {
63
72
const cwd = process . cwd ( ) ;
64
- const dir = path . join ( git . root ( ) , affected . path ) ;
73
+ const root = git . root ( ) ;
74
+ const dir = path . join ( root , affected . path ) ;
65
75
console . log ( `>> cd ${ dir } ` ) ;
66
76
process . chdir ( dir ) ;
67
77
if ( 'TestAll' in affected ) {
68
- this . testAll ( ) ;
78
+ this . testAll ( { root : root , path : affected . path } ) ;
69
79
}
70
80
if ( 'TestSome' in affected ) {
71
- this . testSome ( affected . TestSome ) ;
81
+ this . testSome ( {
82
+ root : root ,
83
+ path : affected . path ,
84
+ tests : affected . TestSome ,
85
+ } ) ;
72
86
}
73
87
process . chdir ( cwd ) ;
74
88
} ;
0 commit comments