@@ -12,27 +12,40 @@ function computeGlob(pattern, options) {
12
12
} ) ;
13
13
}
14
14
15
+ function getGlobs ( patterns , cwd ) {
16
+ return Promise . all ( patterns . map ( globPattern =>
17
+ computeGlob ( globPattern , {
18
+ cwd : cwd ,
19
+ ignore : 'node_modules/**' ,
20
+ } )
21
+ ) )
22
+ . then ( globLists => [ ] . concat . apply ( [ ] , globLists ) )
23
+ }
24
+
15
25
function WatchTestFilesPlugin ( testGlobs ) {
16
26
this . testGlobs = testGlobs || [ ] ;
17
27
}
18
28
19
29
WatchTestFilesPlugin . prototype . apply = function ( compiler ) {
20
- compiler . plugin ( 'emit' , ( compilation , callback ) => {
21
- console . log ( )
22
- Promise . all ( this . testGlobs . map ( globPattern =>
23
- computeGlob ( globPattern , {
24
- cwd : compiler . options . context ,
25
- ignore : 'node_modules/**' ,
26
- } )
27
- ) )
28
- . then ( globLists => [ ] . concat . apply ( [ ] , globLists ) )
29
- . then ( testFiles => {
30
- testFiles . forEach ( testFile => {
31
- compilation . fileDependencies . push ( path . join ( compiler . options . context , testFile ) ) ;
32
- } ) ;
30
+ var testFiles = [ ] ;
31
+ compiler . plugin ( 'make' , ( compilation , callback ) => {
32
+ getGlobs ( this . testGlobs , compiler . options . context )
33
+ . then ( foundFiles => {
34
+ testFiles = foundFiles ;
35
+ return Promise . all (
36
+ testFiles . map ( filename => new Promise ( ( resolve , reject ) => {
37
+ // TODO: add to modules
38
+ resolve ( filename ) ;
39
+ } ) )
40
+ )
33
41
} )
34
- . then ( callback )
35
- . catch ( console . error ) ;
42
+ . then ( callback ) ;
43
+ } ) ;
44
+ compiler . plugin ( 'emit' , ( compilation , callback ) => {
45
+ testFiles . forEach ( testFile => {
46
+ compilation . fileDependencies . push ( path . join ( compiler . options . context , testFile ) ) ;
47
+ } ) ;
48
+ callback ( ) ;
36
49
} ) ;
37
50
} ;
38
51
0 commit comments