@@ -108,89 +108,104 @@ describe("WatchTestCases", () => {
108108
109109 const state = { } ;
110110 let runIdx = 0 ;
111+ let waitMode = false ;
111112 let run = runs [ runIdx ] ;
113+ let triggeringFilename ;
112114 let lastHash = "" ;
115+ const currentWatchStepModule = require ( "./helpers/currentWatchStep" ) ;
116+ currentWatchStepModule . step = run . name ;
113117 copyDiff ( path . join ( testDirectory , run . name ) , tempDirectory ) ;
114118
115- const compiler = webpack ( options ) ;
116- const watching = compiler . watch ( {
117- aggregateTimeout : 1000
118- } , ( err , stats ) => {
119- if ( err )
120- return done ( err ) ;
121- if ( ! stats )
122- return done ( new Error ( "No stats reported from Compiler" ) ) ;
123- if ( stats . hash === lastHash )
124- return ;
125- lastHash = stats . hash ;
126- if ( run . done )
127- return done ( new Error ( "Compilation changed but no change was issued " + lastHash + " != " + stats . hash + " (run " + runIdx + ")" ) ) ;
128- run . done = true ;
129- if ( err ) return done ( err ) ;
130- const statOptions = Stats . presetToOptions ( "verbose" ) ;
131- statOptions . colors = false ;
132- fs . writeFileSync ( path . join ( outputDirectory , "stats.txt" ) , stats . toString ( statOptions ) , "utf-8" ) ;
133- const jsonStats = stats . toJson ( {
134- errorDetails : true
119+ setTimeout ( ( ) => {
120+ const compiler = webpack ( options ) ;
121+ compiler . plugin ( "invalid" , ( filename , mtime ) => {
122+ triggeringFilename = filename ;
135123 } ) ;
136- if ( checkArrayExpectation ( path . join ( testDirectory , run . name ) , jsonStats , "error" , "Error" , done ) ) return ;
137- if ( checkArrayExpectation ( path . join ( testDirectory , run . name ) , jsonStats , "warning" , "Warning" , done ) ) return ;
138- let exportedTests = 0 ;
124+ const watching = compiler . watch ( {
125+ aggregateTimeout : 1000
126+ } , ( err , stats ) => {
127+ if ( err )
128+ return done ( err ) ;
129+ if ( ! stats )
130+ return done ( new Error ( "No stats reported from Compiler" ) ) ;
131+ if ( stats . hash === lastHash )
132+ return ;
133+ lastHash = stats . hash ;
134+ if ( run . done && lastHash !== stats . hash ) {
135+ return done ( new Error ( "Compilation changed but no change was issued " + lastHash + " != " + stats . hash + " (run " + runIdx + ")\n" +
136+ "Triggering change: " + triggeringFilename ) ) ;
137+ }
138+ if ( waitMode ) return ;
139+ run . done = true ;
140+ if ( err ) return done ( err ) ;
141+ const statOptions = Stats . presetToOptions ( "verbose" ) ;
142+ statOptions . colors = false ;
143+ fs . writeFileSync ( path . join ( outputDirectory , "stats.txt" ) , stats . toString ( statOptions ) , "utf-8" ) ;
144+ const jsonStats = stats . toJson ( {
145+ errorDetails : true
146+ } ) ;
147+ if ( checkArrayExpectation ( path . join ( testDirectory , run . name ) , jsonStats , "error" , "Error" , done ) ) return ;
148+ if ( checkArrayExpectation ( path . join ( testDirectory , run . name ) , jsonStats , "warning" , "Warning" , done ) ) return ;
149+ let exportedTests = 0 ;
139150
140- function _it ( title , fn ) {
141- const test = new Test ( title , fn ) ;
142- run . suite . addTest ( test ) ;
143- exportedTests ++ ;
144- return test ;
145- }
151+ function _it ( title , fn ) {
152+ const test = new Test ( title , fn ) ;
153+ run . suite . addTest ( test ) ;
154+ exportedTests ++ ;
155+ return test ;
156+ }
146157
147- function _require ( currentDirectory , module ) {
148- if ( Array . isArray ( module ) || / ^ \. \. ? \/ / . test ( module ) ) {
149- let fn ;
150- let content ;
151- let p ;
152- if ( Array . isArray ( module ) ) {
153- p = path . join ( currentDirectory , module [ 0 ] ) ;
154- content = module . map ( ( arg ) => {
155- p = path . join ( currentDirectory , arg ) ;
156- return fs . readFileSync ( p , "utf-8" ) ;
157- } ) . join ( "\n" ) ;
158- } else {
159- p = path . join ( currentDirectory , module ) ;
160- content = fs . readFileSync ( p , "utf-8" ) ;
161- }
162- fn = vm . runInThisContext ( "(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE) {" + content + "\n})" , p ) ;
163- const m = {
164- exports : { }
165- } ;
166- fn . call ( m . exports , _require . bind ( null , path . dirname ( p ) ) , m , m . exports , path . dirname ( p ) , p , _it , run . name , jsonStats , state ) ;
167- return module . exports ;
168- } else if ( testConfig . modules && module in testConfig . modules ) {
169- return testConfig . modules [ module ] ;
170- } else return require ( module ) ;
171- }
158+ function _require ( currentDirectory , module ) {
159+ if ( Array . isArray ( module ) || / ^ \. \. ? \/ / . test ( module ) ) {
160+ let fn ;
161+ let content ;
162+ let p ;
163+ if ( Array . isArray ( module ) ) {
164+ p = path . join ( currentDirectory , module [ 0 ] ) ;
165+ content = module . map ( ( arg ) => {
166+ p = path . join ( currentDirectory , arg ) ;
167+ return fs . readFileSync ( p , "utf-8" ) ;
168+ } ) . join ( "\n" ) ;
169+ } else {
170+ p = path . join ( currentDirectory , module ) ;
171+ content = fs . readFileSync ( p , "utf-8" ) ;
172+ }
173+ fn = vm . runInThisContext ( "(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE) {" + content + "\n})" , p ) ;
174+ const m = {
175+ exports : { }
176+ } ;
177+ fn . call ( m . exports , _require . bind ( null , path . dirname ( p ) ) , m , m . exports , path . dirname ( p ) , p , _it , run . name , jsonStats , state ) ;
178+ return module . exports ;
179+ } else if ( testConfig . modules && module in testConfig . modules ) {
180+ return testConfig . modules [ module ] ;
181+ } else return require ( module ) ;
182+ }
172183
173- let testConfig = { } ;
174- try {
175- // try to load a test file
176- testConfig = require ( path . join ( testDirectory , "test.config.js" ) ) ;
177- } catch ( e ) { }
184+ let testConfig = { } ;
185+ try {
186+ // try to load a test file
187+ testConfig = require ( path . join ( testDirectory , "test.config.js" ) ) ;
188+ } catch ( e ) { }
178189
179- if ( testConfig . noTests ) return process . nextTick ( done ) ;
180- _require ( outputDirectory , "./bundle.js" ) ;
190+ if ( testConfig . noTests ) return process . nextTick ( done ) ;
191+ _require ( outputDirectory , "./bundle.js" ) ;
181192
182- if ( exportedTests < 1 ) return done ( new Error ( "No tests exported by test case" ) ) ;
183- runIdx ++ ;
184- if ( runIdx < runs . length ) {
185- run = runs [ runIdx ] ;
186- setTimeout ( ( ) => {
187- copyDiff ( path . join ( testDirectory , run . name ) , tempDirectory ) ;
188- } , 1500 ) ;
189- } else {
190- watching . close ( ) ;
191- process . nextTick ( done ) ;
192- }
193- } ) ;
193+ if ( exportedTests < 1 ) return done ( new Error ( "No tests exported by test case" ) ) ;
194+ runIdx ++ ;
195+ if ( runIdx < runs . length ) {
196+ run = runs [ runIdx ] ;
197+ waitMode = true ;
198+ setTimeout ( ( ) => {
199+ waitMode = false ;
200+ currentWatchStepModule . step = run . name ;
201+ copyDiff ( path . join ( testDirectory , run . name ) , tempDirectory ) ;
202+ } , 1500 ) ;
203+ } else {
204+ watching . close ( ) ;
205+ process . nextTick ( done ) ;
206+ }
207+ } ) ;
208+ } , 300 ) ;
194209 } ) ;
195210 } ) ;
196211 } ) ;
0 commit comments