1+ "use strict" ;
2+
13/* globals describe it */
2- var should = require ( "should" ) ;
3- var path = require ( "path" ) ;
4- var fs = require ( "fs" ) ;
5- var vm = require ( "vm" ) ;
6- var Test = require ( "mocha/lib/test" ) ;
7- var checkArrayExpectation = require ( "./checkArrayExpectation" ) ;
4+ const should = require ( "should" ) ;
5+ const path = require ( "path" ) ;
6+ const fs = require ( "fs" ) ;
7+ const vm = require ( "vm" ) ;
8+ const Test = require ( "mocha/lib/test" ) ;
9+ const checkArrayExpectation = require ( "./checkArrayExpectation" ) ;
810
9- var Stats = require ( "../lib/Stats" ) ;
10- var webpack = require ( "../lib/webpack" ) ;
11+ const Stats = require ( "../lib/Stats" ) ;
12+ const webpack = require ( "../lib/webpack" ) ;
1113
12- describe ( "ConfigTestCases" , function ( ) {
13- var casesPath = path . join ( __dirname , "configCases" ) ;
14- var categories = fs . readdirSync ( casesPath ) ;
14+ describe ( "ConfigTestCases" , ( ) => {
15+ const casesPath = path . join ( __dirname , "configCases" ) ;
16+ let categories = fs . readdirSync ( casesPath ) ;
1517
16- categories = categories . map ( function ( cat ) {
18+ categories = categories . map ( ( cat ) => {
1719 return {
1820 name : cat ,
19- tests : fs . readdirSync ( path . join ( casesPath , cat ) ) . filter ( function ( folder ) {
21+ tests : fs . readdirSync ( path . join ( casesPath , cat ) ) . filter ( ( folder ) => {
2022 return folder . indexOf ( "_" ) < 0 ;
21- } ) . sort ( ) . filter ( function ( testName ) {
22- var testDirectory = path . join ( casesPath , cat , testName ) ;
23- var filterPath = path . join ( testDirectory , "test.filter.js" ) ;
23+ } ) . sort ( ) . filter ( ( testName ) => {
24+ const testDirectory = path . join ( casesPath , cat , testName ) ;
25+ const filterPath = path . join ( testDirectory , "test.filter.js" ) ;
2426 if ( fs . existsSync ( filterPath ) && ! require ( filterPath ) ( ) ) {
25- describe . skip ( testName , function ( ) {
26- it ( 'filtered' ) ;
27- } ) ;
27+ describe . skip ( testName , ( ) => it ( "filtered" ) ) ;
2828 return false ;
2929 }
3030 return true ;
3131 } )
3232 } ;
3333 } ) ;
34- categories . forEach ( function ( category ) {
35- describe ( category . name , function ( ) {
36- category . tests . forEach ( function ( testName ) {
37- var suite = describe ( testName , function ( ) { } ) ;
34+ categories . forEach ( ( category ) => {
35+ describe ( category . name , ( ) => {
36+ category . tests . forEach ( ( testName ) => {
37+ const suite = describe ( testName , ( ) => { } ) ;
3838 it ( testName + " should compile" , function ( done ) {
3939 this . timeout ( 30000 ) ;
40- var testDirectory = path . join ( casesPath , category . name , testName ) ;
41- var outputDirectory = path . join ( __dirname , "js" , "config" , category . name , testName ) ;
42- var options = require ( path . join ( testDirectory , "webpack.config.js" ) ) ;
43- var optionsArr = [ ] . concat ( options ) ;
44- optionsArr . forEach ( function ( options , idx ) {
40+ const testDirectory = path . join ( casesPath , category . name , testName ) ;
41+ const outputDirectory = path . join ( __dirname , "js" , "config" , category . name , testName ) ;
42+ const options = require ( path . join ( testDirectory , "webpack.config.js" ) ) ;
43+ const optionsArr = [ ] . concat ( options ) ;
44+ optionsArr . forEach ( ( options , idx ) => {
4545 if ( ! options . context ) options . context = testDirectory ;
4646 if ( ! options . entry ) options . entry = "./index.js" ;
4747 if ( ! options . target ) options . target = "async-node" ;
@@ -51,59 +51,60 @@ describe("ConfigTestCases", function() {
5151 if ( ! options . output . filename ) options . output . filename = "bundle" + idx + ".js" ;
5252 if ( ! options . output . chunkFilename ) options . output . chunkFilename = "[id].bundle" + idx + ".js" ;
5353 } ) ;
54- webpack ( options , function ( err , stats ) {
54+ webpack ( options , ( err , stats ) => {
5555 if ( err ) return done ( err ) ;
56- var statOptions = Stats . presetToOptions ( "verbose" ) ;
56+ const statOptions = Stats . presetToOptions ( "verbose" ) ;
5757 statOptions . colors = false ;
5858 fs . writeFileSync ( path . join ( outputDirectory , "stats.txt" ) , stats . toString ( statOptions ) , "utf-8" ) ;
59- var jsonStats = stats . toJson ( {
59+ const jsonStats = stats . toJson ( {
6060 errorDetails : true
6161 } ) ;
6262 if ( checkArrayExpectation ( testDirectory , jsonStats , "error" , "Error" , done ) ) return ;
6363 if ( checkArrayExpectation ( testDirectory , jsonStats , "warning" , "Warning" , done ) ) return ;
64- var exportedTests = 0 ;
64+ let exportedTests = 0 ;
6565
6666 function _it ( title , fn ) {
67- var test = new Test ( title , fn ) ;
67+ const test = new Test ( title , fn ) ;
6868 suite . addTest ( test ) ;
6969 exportedTests ++ ;
7070 return test ;
7171 }
7272
73- var globalContext = {
73+ const globalContext = {
7474 console : console
7575 } ;
7676
7777 function _require ( currentDirectory , module ) {
7878 if ( Array . isArray ( module ) || / ^ \. \. ? \/ / . test ( module ) ) {
79- var fn ;
80- var content ;
79+ let fn ;
80+ let content ;
81+ let p ;
8182 if ( Array . isArray ( module ) ) {
82- var p = path . join ( currentDirectory , module [ 0 ] ) ;
83- content = module . map ( function ( p ) {
84- var p = path . join ( currentDirectory , p ) ;
83+ p = path . join ( currentDirectory , module [ 0 ] ) ;
84+ content = module . map ( ( arg ) => {
85+ p = path . join ( currentDirectory , arg ) ;
8586 return fs . readFileSync ( p , "utf-8" ) ;
8687 } ) . join ( "\n" ) ;
8788 } else {
88- var p = path . join ( currentDirectory , module ) ;
89+ p = path . join ( currentDirectory , module ) ;
8990 content = fs . readFileSync ( p , "utf-8" ) ;
9091 }
9192 if ( options . target === "web" || options . target === "webworker" ) {
9293 fn = vm . runInNewContext ( "(function(require, module, exports, __dirname, __filename, it, window) {" + content + "\n})" , globalContext , p ) ;
9394 } else {
9495 fn = vm . runInThisContext ( "(function(require, module, exports, __dirname, __filename, it) {" + content + "\n})" , p ) ;
9596 }
96- var module = {
97+ const m = {
9798 exports : { }
9899 } ;
99- fn . call ( module . exports , _require . bind ( null , path . dirname ( p ) ) , module , module . exports , path . dirname ( p ) , p , _it , globalContext ) ;
100- return module . exports ;
100+ fn . call ( m . exports , _require . bind ( null , path . dirname ( p ) ) , m , m . exports , path . dirname ( p ) , p , _it , globalContext ) ;
101+ return m . exports ;
101102 } else if ( testConfig . modules && module in testConfig . modules ) {
102103 return testConfig . modules [ module ] ;
103104 } else return require ( module ) ;
104105 }
105- var filesCount = 0 ;
106- var testConfig = {
106+ let filesCount = 0 ;
107+ let testConfig = {
107108 findBundle : function ( i , options ) {
108109 if ( fs . existsSync ( path . join ( options . output . path , "bundle" + i + ".js" ) ) ) {
109110 return "./bundle" + i + ".js" ;
@@ -116,8 +117,8 @@ describe("ConfigTestCases", function() {
116117 } catch ( e ) { }
117118
118119 if ( testConfig . noTests ) return process . nextTick ( done ) ;
119- for ( var i = 0 ; i < optionsArr . length ; i ++ ) {
120- var bundlePath = testConfig . findBundle ( i , optionsArr [ i ] ) ;
120+ for ( let i = 0 ; i < optionsArr . length ; i ++ ) {
121+ const bundlePath = testConfig . findBundle ( i , optionsArr [ i ] ) ;
121122 if ( bundlePath ) {
122123 filesCount ++ ;
123124 _require ( outputDirectory , bundlePath ) ;
0 commit comments