1
+ /* global beforeAll expect fit */
1
2
"use strict" ;
2
3
3
- require ( "should" ) ;
4
4
const path = require ( "path" ) ;
5
5
const fs = require ( "fs" ) ;
6
6
const vm = require ( "vm" ) ;
7
- const Test = require ( "mocha/lib/test" ) ;
8
7
const mkdirp = require ( "mkdirp" ) ;
9
8
const checkArrayExpectation = require ( "./checkArrayExpectation" ) ;
9
+ const async = require ( "async" ) ;
10
10
11
11
const Stats = require ( "../lib/Stats" ) ;
12
12
const webpack = require ( "../lib/webpack" ) ;
@@ -61,7 +61,7 @@ describe("WatchTestCases", () => {
61
61
tests : fs . readdirSync ( path . join ( casesPath , cat ) ) . filter ( ( folder ) => folder . indexOf ( "_" ) < 0 ) . sort ( )
62
62
} ;
63
63
} ) ;
64
- before ( ( ) => {
64
+ beforeAll ( ( ) => {
65
65
let dest = path . join ( __dirname , "js" ) ;
66
66
if ( ! fs . existsSync ( dest ) )
67
67
fs . mkdirSync ( dest ) ;
@@ -90,7 +90,6 @@ describe("WatchTestCases", () => {
90
90
} ) ;
91
91
before ( ( ) => remove ( tempDirectory ) ) ;
92
92
it ( "should compile" , function ( done ) {
93
- this . timeout ( 45000 ) ;
94
93
const outputDirectory = path . join ( __dirname , "js" , "watch" , category . name , testName ) ;
95
94
96
95
let options = { } ;
@@ -154,17 +153,15 @@ describe("WatchTestCases", () => {
154
153
} ) ;
155
154
if ( checkArrayExpectation ( path . join ( testDirectory , run . name ) , jsonStats , "error" , "Error" , done ) ) return ;
156
155
if ( checkArrayExpectation ( path . join ( testDirectory , run . name ) , jsonStats , "warning" , "Warning" , done ) ) return ;
157
- let exportedTests = 0 ;
156
+ let exportedTests = [ ] ;
158
157
159
158
function _it ( title , fn ) {
160
- const test = new Test ( title , fn ) ;
161
- run . suite . addTest ( test ) ;
162
- exportedTests ++ ;
163
- return test ;
159
+ exportedTests . push ( fit ( title , fn , 45000 ) ) ;
164
160
}
165
161
166
162
const globalContext = {
167
- console : console
163
+ console : console ,
164
+ expect : expect
168
165
} ;
169
166
170
167
function _require ( currentDirectory , module ) {
@@ -183,14 +180,14 @@ describe("WatchTestCases", () => {
183
180
content = fs . readFileSync ( p , "utf-8" ) ;
184
181
}
185
182
if ( options . target === "web" || options . target === "webworker" ) {
186
- fn = vm . runInNewContext ( "(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, window) {" + content + "\n})" , globalContext , p ) ;
183
+ fn = vm . runInNewContext ( "(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, expect, window) {" + content + "\n})" , globalContext , p ) ;
187
184
} else {
188
- fn = vm . runInThisContext ( "(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE) {" + content + "\n})" , p ) ;
185
+ fn = vm . runInThisContext ( "(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, expect ) {" + content + "\n})" , p ) ;
189
186
}
190
187
const m = {
191
188
exports : { }
192
189
} ;
193
- fn . call ( m . exports , _require . bind ( null , path . dirname ( p ) ) , m , m . exports , path . dirname ( p ) , p , _it , run . name , jsonStats , state , globalContext ) ;
190
+ fn . call ( m . exports , _require . bind ( null , path . dirname ( p ) ) , m , m . exports , path . dirname ( p ) , p , _it , run . name , jsonStats , state , expect , globalContext ) ;
194
191
return module . exports ;
195
192
} else if ( testConfig . modules && module in testConfig . modules ) {
196
193
return testConfig . modules [ module ] ;
@@ -206,7 +203,7 @@ describe("WatchTestCases", () => {
206
203
if ( testConfig . noTests ) return process . nextTick ( done ) ;
207
204
_require ( outputDirectory , testConfig . bundlePath || "./bundle.js" ) ;
208
205
209
- if ( exportedTests < 1 ) return done ( new Error ( "No tests exported by test case" ) ) ;
206
+ if ( exportedTests . length < 1 ) return done ( new Error ( "No tests exported by test case" ) ) ;
210
207
runIdx ++ ;
211
208
if ( runIdx < runs . length ) {
212
209
run = runs [ runIdx ] ;
@@ -220,9 +217,13 @@ describe("WatchTestCases", () => {
220
217
watching . close ( ) ;
221
218
process . nextTick ( done ) ;
222
219
}
220
+ async . waterfall (
221
+ exportedTests . map ( test => ( callback ) => test . execute ( callback , true ) ) ,
222
+ done
223
+ ) ;
223
224
} ) ;
224
225
} , 300 ) ;
225
- } ) ;
226
+ } , 45000 ) ;
226
227
} ) ;
227
228
} ) ;
228
229
} ) ;
0 commit comments