@@ -7,6 +7,7 @@ const vm = require("vm");
7
7
const mkdirp = require ( "mkdirp" ) ;
8
8
const rimraf = require ( "rimraf" ) ;
9
9
const checkArrayExpectation = require ( "./checkArrayExpectation" ) ;
10
+ const createLazyTestEnv = require ( "./helpers/createLazyTestEnv" ) ;
10
11
const { remove } = require ( "./helpers/remove" ) ;
11
12
12
13
const Stats = require ( "../lib/Stats" ) ;
@@ -140,6 +141,7 @@ describe("WatchTestCases", () => {
140
141
let triggeringFilename ;
141
142
let lastHash = "" ;
142
143
const currentWatchStepModule = require ( "./helpers/currentWatchStep" ) ;
144
+ let compilationFinished = done ;
143
145
currentWatchStepModule . step = run . name ;
144
146
copyDiff ( path . join ( testDirectory , run . name ) , tempDirectory , true ) ;
145
147
@@ -156,13 +158,15 @@ describe("WatchTestCases", () => {
156
158
aggregateTimeout : 1000
157
159
} ,
158
160
( err , stats ) => {
159
- if ( err ) return done ( err ) ;
161
+ if ( err ) return compilationFinished ( err ) ;
160
162
if ( ! stats )
161
- return done ( new Error ( "No stats reported from Compiler" ) ) ;
163
+ return compilationFinished (
164
+ new Error ( "No stats reported from Compiler" )
165
+ ) ;
162
166
if ( stats . hash === lastHash ) return ;
163
167
lastHash = stats . hash ;
164
168
if ( run . done && lastHash !== stats . hash ) {
165
- return done (
169
+ return compilationFinished (
166
170
new Error (
167
171
"Compilation changed but no change was issued " +
168
172
lastHash +
@@ -178,7 +182,7 @@ describe("WatchTestCases", () => {
178
182
}
179
183
if ( waitMode ) return ;
180
184
run . done = true ;
181
- if ( err ) return done ( err ) ;
185
+ if ( err ) return compilationFinished ( err ) ;
182
186
const statOptions = Stats . presetToOptions ( "verbose" ) ;
183
187
statOptions . colors = false ;
184
188
mkdirp . sync ( outputDirectory ) ;
@@ -196,7 +200,7 @@ describe("WatchTestCases", () => {
196
200
jsonStats ,
197
201
"error" ,
198
202
"Error" ,
199
- done
203
+ compilationFinished
200
204
)
201
205
)
202
206
return ;
@@ -206,17 +210,11 @@ describe("WatchTestCases", () => {
206
210
jsonStats ,
207
211
"warning" ,
208
212
"Warning" ,
209
- done
213
+ compilationFinished
210
214
)
211
215
)
212
216
return ;
213
217
214
- const exportedTests = [ ] ;
215
-
216
- function _it ( title , fn ) {
217
- exportedTests . push ( { title, fn, timeout : 45000 } ) ;
218
- }
219
-
220
218
const globalContext = {
221
219
console : console ,
222
220
expect : expect
@@ -271,7 +269,7 @@ describe("WatchTestCases", () => {
271
269
m . exports ,
272
270
path . dirname ( p ) ,
273
271
p ,
274
- _it ,
272
+ run . it ,
275
273
run . name ,
276
274
jsonStats ,
277
275
state ,
@@ -298,22 +296,26 @@ describe("WatchTestCases", () => {
298
296
// empty
299
297
}
300
298
301
- if ( testConfig . noTests ) return process . nextTick ( done ) ;
299
+ if ( testConfig . noTests )
300
+ return process . nextTick ( compilationFinished ) ;
302
301
_require (
303
302
outputDirectory ,
304
303
testConfig . bundlePath || "./bundle.js"
305
304
) ;
306
305
307
- if ( exportedTests . length < 1 )
308
- return done ( new Error ( "No tests exported by test case" ) ) ;
306
+ if ( run . getNumberOfTests ( ) < 1 )
307
+ return compilationFinished (
308
+ new Error ( "No tests exported by test case" )
309
+ ) ;
309
310
310
- const continueStep = ( ) => {
311
+ run . it ( "should compile the next step" , done => {
311
312
runIdx ++ ;
312
313
if ( runIdx < runs . length ) {
313
314
run = runs [ runIdx ] ;
314
315
waitMode = true ;
315
316
setTimeout ( ( ) => {
316
317
waitMode = false ;
318
+ compilationFinished = done ;
317
319
currentWatchStepModule . step = run . name ;
318
320
copyDiff (
319
321
path . join ( testDirectory , run . name ) ,
@@ -326,33 +328,26 @@ describe("WatchTestCases", () => {
326
328
327
329
done ( ) ;
328
330
}
329
- } ;
330
-
331
- // Run the tests
332
- const asyncSuite = describe ( `WatchTestCases ${
333
- category . name
334
- } ${ testName } step ${ run . name } `, ( ) => {
335
- exportedTests . forEach (
336
- ( { title, fn, timeout } ) =>
337
- fn
338
- ? fit ( title , fn , timeout )
339
- : fit ( title , ( ) => { } ) . pend ( "Skipped" )
340
- ) ;
341
331
} ) ;
342
- // workaround for jest running clearSpies on the wrong suite (invoked by clearResourcesForRunnable)
343
- asyncSuite . disabled = true ;
344
332
345
- jasmine
346
- . getEnv ( )
347
- . execute ( [ asyncSuite . id ] , asyncSuite )
348
- . then ( continueStep , done ) ;
333
+ compilationFinished ( ) ;
349
334
}
350
335
) ;
351
336
} , 300 ) ;
352
337
} ,
353
338
45000
354
339
) ;
355
340
341
+ for ( const run of runs ) {
342
+ const { it : _it , getNumberOfTests } = createLazyTestEnv (
343
+ jasmine . getEnv ( ) ,
344
+ 10000 ,
345
+ run . name
346
+ ) ;
347
+ run . it = _it ;
348
+ run . getNumberOfTests = getNumberOfTests ;
349
+ }
350
+
356
351
afterAll ( ( ) => {
357
352
remove ( tempDirectory ) ;
358
353
} ) ;
0 commit comments