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 {
21
- Affected ,
22
- PackageName ,
23
- TestAll ,
24
- TestName ,
25
- TestPath ,
26
- mergeAffected ,
27
- } 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' ;
28
21
29
22
export class Config {
30
23
match : List < string > ;
31
24
ignore : List < string > ;
32
25
packageFile : List < string > ;
33
- testAll : ( path : PackageName ) => void ;
34
- testSome : ( path : PackageName , tests : Map < TestPath , Set < TestName > > ) => void ;
26
+ testAll : ( ) => void ;
27
+ testSome : ( tests : Map < TestPath , Set < TestName > > ) => void ;
35
28
36
29
constructor ( {
37
30
match,
@@ -43,14 +36,16 @@ export class Config {
43
36
match ?: string [ ] ;
44
37
ignore ?: string [ ] ;
45
38
packageFile ?: string [ ] ;
46
- testAll ?: ( path : PackageName ) => void ;
47
- testSome ?: ( path : PackageName , tests : Map < TestPath , Set < TestName > > ) => void ;
39
+ testAll ?: ( ) => void ;
40
+ testSome ?: ( tests : Map < TestPath , Set < TestName > > ) => void ;
48
41
} ) {
49
42
this . match = List ( match || [ '**' ] ) ;
50
43
this . ignore = List ( ignore ) ;
51
44
this . packageFile = List ( packageFile ) ;
52
- this . testAll = testAll || ( path => { } ) ;
53
- this . testSome = testSome || ( ( path , tests ) => { } ) ;
45
+ this . testAll = testAll || ( ( ) => { } ) ;
46
+ this . testSome =
47
+ testSome ||
48
+ ( _ => { } ) ; /* eslint-disable @typescript-eslint/no-unused-vars */
54
49
}
55
50
56
51
affected = ( head : string , main : string ) : List < Affected > =>
@@ -65,25 +60,27 @@ export class Config {
65
60
) ;
66
61
67
62
test = ( affected : Affected ) => {
68
- const cwd = process . cwd ( )
69
- process . chdir ( git . root ( ) )
63
+ const cwd = process . cwd ( ) ;
64
+ const dir = path . join ( git . root ( ) , affected . path ) ;
65
+ console . log ( `>> cd ${ dir } ` ) ;
66
+ process . chdir ( dir ) ;
70
67
if ( 'TestAll' in affected ) {
71
- this . testAll ( affected . path )
68
+ this . testAll ( ) ;
72
69
}
73
70
if ( 'TestSome' in affected ) {
74
- this . testSome ( affected . path , affected . TestSome )
71
+ this . testSome ( affected . TestSome ) ;
75
72
}
76
- process . chdir ( cwd )
77
- }
73
+ process . chdir ( cwd ) ;
74
+ } ;
78
75
79
76
matchFile = ( diff : git . Diff ) : boolean =>
80
77
this . match . some ( p => minimatch ( diff . filename , p ) ) &&
81
78
this . ignore . some ( p => ! minimatch ( diff . filename , p ) ) ;
82
79
83
80
findAffected = ( diff : git . Diff ) : Affected => {
84
- const path = this . findPackage ( diff . filename )
85
- return TestAll ( path ) // TOOD: discover affected tests only
86
- }
81
+ const path = this . findPackage ( diff . filename ) ;
82
+ return TestAll ( path ) ; // TOOD: discover affected tests only
83
+ } ;
87
84
88
85
findPackage = ( filename : string ) : string => {
89
86
const dir = path . dirname ( filename ) ;
0 commit comments