1
- /* global describe, it*/
1
+ /* global describe it fit expect */
2
2
"use strict" ;
3
3
4
- require ( "should" ) ;
5
4
const path = require ( "path" ) ;
6
5
const fs = require ( "fs" ) ;
7
6
const vm = require ( "vm" ) ;
8
7
const mkdirp = require ( "mkdirp" ) ;
9
- const Test = require ( "mocha/lib/test" ) ;
10
8
const checkArrayExpectation = require ( "./checkArrayExpectation" ) ;
9
+ const async = require ( "async" ) ;
11
10
12
11
const Stats = require ( "../lib/Stats" ) ;
13
12
const webpack = require ( "../lib/webpack" ) ;
@@ -116,7 +115,6 @@ describe("TestCases", () => {
116
115
describe ( config . name , ( ) => {
117
116
categories . forEach ( ( category ) => {
118
117
describe ( category . name , function ( ) {
119
- this . timeout ( 30000 ) ;
120
118
category . tests . filter ( ( test ) => {
121
119
const testDirectory = path . join ( casesPath , category . name , test ) ;
122
120
const filterPath = path . join ( testDirectory , "test.filter.js" ) ;
@@ -126,95 +124,96 @@ describe("TestCases", () => {
126
124
}
127
125
return true ;
128
126
} ) . forEach ( ( testName ) => {
129
- const suite = describe ( testName , ( ) => { } ) ;
130
- it ( testName + " should compile" , ( done ) => {
131
- const testDirectory = path . join ( casesPath , category . name , testName ) ;
132
- const outputDirectory = path . join ( __dirname , "js" , config . name , category . name , testName ) ;
133
- const options = {
134
- context : casesPath ,
135
- entry : "./" + category . name + "/" + testName + "/index" ,
136
- target : "async-node" ,
137
- devtool : config . devtool ,
138
- mode : config . mode || "none" ,
139
- optimization : config . mode ? NO_EMIT_ON_ERRORS_OPTIMIZATIONS : Object . assign ( { } , config . optimization , DEFAULT_OPTIMIZATIONS ) ,
140
- performance : {
141
- hints : false
142
- } ,
143
- output : {
144
- pathinfo : true ,
145
- path : outputDirectory ,
146
- filename : "bundle.js"
147
- } ,
148
- resolve : {
149
- modules : [ "web_modules" , "node_modules" ] ,
150
- mainFields : [ "webpack" , "browser" , "web" , "browserify" , [ "jam" , "main" ] , "main" ] ,
151
- aliasFields : [ "browser" ] ,
152
- extensions : [ ".mjs" , ".webpack.js" , ".web.js" , ".js" , ".json" ] ,
153
- concord : true
154
- } ,
155
- resolveLoader : {
156
- modules : [ "web_loaders" , "web_modules" , "node_loaders" , "node_modules" ] ,
157
- mainFields : [ "webpackLoader" , "webLoader" , "loader" , "main" ] ,
158
- extensions : [ ".webpack-loader.js" , ".web-loader.js" , ".loader.js" , ".js" ]
159
- } ,
160
- module : {
161
- rules : [ {
162
- test : / \. c o f f e e $ / ,
163
- loader : "coffee-loader"
164
- } , {
165
- test : / \. j a d e $ / ,
166
- loader : "jade-loader"
167
- } ]
168
- } ,
169
- plugins : ( config . plugins || [ ] ) . concat ( function ( ) {
170
- this . hooks . compilation . tap ( "TestCasesTest" , ( compilation ) => {
171
- [ "optimize" , "optimizeModulesBasic" , "optimizeChunksBasic" , "afterOptimizeTree" , "afterOptimizeAssets" ] . forEach ( ( hook ) => {
172
- compilation . hooks [ hook ] . tap ( "TestCasesTest" , ( ) => compilation . checkConstraints ( ) ) ;
127
+ describe ( testName , ( ) => {
128
+ it ( testName + " should compile" , ( done ) => {
129
+ const testDirectory = path . join ( casesPath , category . name , testName ) ;
130
+ const outputDirectory = path . join ( __dirname , "js" , config . name , category . name , testName ) ;
131
+ const options = {
132
+ context : casesPath ,
133
+ entry : "./" + category . name + "/" + testName + "/index" ,
134
+ target : "async-node" ,
135
+ devtool : config . devtool ,
136
+ mode : config . mode || "none" ,
137
+ optimization : config . mode ? NO_EMIT_ON_ERRORS_OPTIMIZATIONS : Object . assign ( { } , config . optimization , DEFAULT_OPTIMIZATIONS ) ,
138
+ performance : {
139
+ hints : false
140
+ } ,
141
+ output : {
142
+ pathinfo : true ,
143
+ path : outputDirectory ,
144
+ filename : "bundle.js"
145
+ } ,
146
+ resolve : {
147
+ modules : [ "web_modules" , "node_modules" ] ,
148
+ mainFields : [ "webpack" , "browser" , "web" , "browserify" , [ "jam" , "main" ] , "main" ] ,
149
+ aliasFields : [ "browser" ] ,
150
+ extensions : [ ".mjs" , ".webpack.js" , ".web.js" , ".js" , ".json" ] ,
151
+ concord : true
152
+ } ,
153
+ resolveLoader : {
154
+ modules : [ "web_loaders" , "web_modules" , "node_loaders" , "node_modules" ] ,
155
+ mainFields : [ "webpackLoader" , "webLoader" , "loader" , "main" ] ,
156
+ extensions : [ ".webpack-loader.js" , ".web-loader.js" , ".loader.js" , ".js" ]
157
+ } ,
158
+ module : {
159
+ rules : [ {
160
+ test : / \. c o f f e e $ / ,
161
+ loader : "coffee-loader"
162
+ } , {
163
+ test : / \. j a d e $ / ,
164
+ loader : "jade-loader"
165
+ } ]
166
+ } ,
167
+ plugins : ( config . plugins || [ ] ) . concat ( function ( ) {
168
+ this . hooks . compilation . tap ( "TestCasesTest" , ( compilation ) => {
169
+ [ "optimize" , "optimizeModulesBasic" , "optimizeChunksBasic" , "afterOptimizeTree" , "afterOptimizeAssets" ] . forEach ( ( hook ) => {
170
+ compilation . hooks [ hook ] . tap ( "TestCasesTest" , ( ) => compilation . checkConstraints ( ) ) ;
171
+ } ) ;
173
172
} ) ;
173
+ } )
174
+ } ;
175
+ webpack ( options , ( err , stats ) => {
176
+ if ( err ) return done ( err ) ;
177
+ const statOptions = Stats . presetToOptions ( "verbose" ) ;
178
+ statOptions . colors = false ;
179
+ mkdirp . sync ( outputDirectory ) ;
180
+ fs . writeFileSync ( path . join ( outputDirectory , "stats.txt" ) , stats . toString ( statOptions ) , "utf-8" ) ;
181
+ const jsonStats = stats . toJson ( {
182
+ errorDetails : true
174
183
} ) ;
175
- } )
176
- } ;
177
- webpack ( options , ( err , stats ) => {
178
- if ( err ) return done ( err ) ;
179
- const statOptions = Stats . presetToOptions ( "verbose" ) ;
180
- statOptions . colors = false ;
181
- mkdirp . sync ( outputDirectory ) ;
182
- fs . writeFileSync ( path . join ( outputDirectory , "stats.txt" ) , stats . toString ( statOptions ) , "utf-8" ) ;
183
- const jsonStats = stats . toJson ( {
184
- errorDetails : true
185
- } ) ;
186
- if ( checkArrayExpectation ( testDirectory , jsonStats , "error" , "Error" , done ) ) return ;
187
- if ( checkArrayExpectation ( testDirectory , jsonStats , "warning" , "Warning" , done ) ) return ;
188
- let exportedTest = 0 ;
189
-
190
- function _it ( title , fn ) {
191
- const test = new Test ( title , fn ) ;
192
- suite . addTest ( test ) ;
193
- exportedTest ++ ;
194
- // WORKAROUND for a v8 bug
195
- // Error objects retrain all scopes in the stacktrace
196
- test . _trace = test . _trace . message ;
184
+ if ( checkArrayExpectation ( testDirectory , jsonStats , "error" , "Error" , done ) ) return ;
185
+ if ( checkArrayExpectation ( testDirectory , jsonStats , "warning" , "Warning" , done ) ) return ;
186
+ let exportedTests = [ ] ;
197
187
198
- return test ;
199
- }
188
+ function _it ( title , fn ) {
189
+ exportedTests . push ( fit ( title , fn ) ) ;
190
+ // TODO: is this necessary in 'jest'?
191
+ // WORKAROUND for a v8 bug
192
+ // Error objects retrain all scopes in the stacktrace
193
+ // test._trace = test._trace.message;
194
+ }
200
195
201
- function _require ( module ) {
202
- if ( module . substr ( 0 , 2 ) === "./" ) {
203
- const p = path . join ( outputDirectory , module ) ;
204
- const fn = vm . runInThisContext ( "(function(require, module, exports, __dirname, it) {" + fs . readFileSync ( p , "utf-8" ) + "\n})" , p ) ;
205
- const m = {
206
- exports : { } ,
207
- webpackTestSuiteModule : true
208
- } ;
209
- fn . call ( m . exports , _require , m , m . exports , outputDirectory , _it ) ;
210
- return m . exports ;
211
- } else return require ( module ) ;
212
- }
213
- _require . webpackTestSuiteRequire = true ;
214
- _require ( "./bundle.js" ) ;
215
- if ( exportedTest === 0 ) return done ( new Error ( "No tests exported by test case" ) ) ;
216
- done ( ) ;
217
- } ) ;
196
+ function _require ( module ) {
197
+ if ( module . substr ( 0 , 2 ) === "./" ) {
198
+ const p = path . join ( outputDirectory , module ) ;
199
+ const fn = vm . runInThisContext ( "(function(require, module, exports, __dirname, it, expect) {" + fs . readFileSync ( p , "utf-8" ) + "\n})" , p ) ;
200
+ const m = {
201
+ exports : { } ,
202
+ webpackTestSuiteModule : true
203
+ } ;
204
+ fn . call ( m . exports , _require , m , m . exports , outputDirectory , _it , expect ) ;
205
+ return m . exports ;
206
+ } else return require ( module ) ;
207
+ }
208
+ _require . webpackTestSuiteRequire = true ;
209
+ _require ( "./bundle.js" ) ;
210
+ if ( exportedTests . length === 0 ) return done ( new Error ( "No tests exported by test case" ) ) ;
211
+ async . waterfall (
212
+ exportedTests . map ( test => ( callback ) => test . execute ( callback , true ) ) ,
213
+ done
214
+ ) ;
215
+ } ) ;
216
+ } , 30000 ) ;
218
217
} ) ;
219
218
} ) ;
220
219
} ) ;
0 commit comments