@@ -32,89 +32,79 @@ describe('TestCases', () => {
3232 for ( const directory of fs . readdirSync ( casesDirectory ) ) {
3333 if ( ! / ^ ( \. | _ ) / . test ( directory ) ) {
3434 // eslint-disable-next-line no-loop-func
35- it (
36- `${ directory } should compile to the expected result` ,
37- ( done ) => {
38- const directoryForCase = path . resolve ( casesDirectory , directory ) ;
39- const outputDirectoryForCase = path . resolve (
40- outputDirectory ,
41- directory
35+ it ( `${ directory } should compile to the expected result` , ( done ) => {
36+ const directoryForCase = path . resolve ( casesDirectory , directory ) ;
37+ const outputDirectoryForCase = path . resolve ( outputDirectory , directory ) ;
38+ // eslint-disable-next-line import/no-dynamic-require, global-require
39+ const webpackConfig = require ( path . resolve (
40+ directoryForCase ,
41+ 'webpack.config.js'
42+ ) ) ;
43+ for ( const config of [ ] . concat ( webpackConfig ) ) {
44+ Object . assign (
45+ config ,
46+ {
47+ mode : 'none' ,
48+ context : directoryForCase ,
49+ output : Object . assign (
50+ {
51+ path : outputDirectoryForCase ,
52+ } ,
53+ config . output
54+ ) ,
55+ } ,
56+ config
4257 ) ;
43- // eslint-disable-next-line import/no-dynamic-require, global-require
44- const webpackConfig = require ( path . resolve (
45- directoryForCase ,
46- 'webpack.config.js'
47- ) ) ;
48- for ( const config of [ ] . concat ( webpackConfig ) ) {
49- Object . assign (
50- config ,
51- {
52- mode : 'none' ,
53- context : directoryForCase ,
54- output : Object . assign (
55- {
56- path : outputDirectoryForCase ,
57- } ,
58- config . output
59- ) ,
60- } ,
61- config
62- ) ;
58+ }
59+ webpack ( webpackConfig , ( err , stats ) => {
60+ if ( err ) {
61+ done ( err ) ;
62+ return ;
6363 }
64- webpack ( webpackConfig , ( err , stats ) => {
65- if ( err ) {
66- done ( err ) ;
67- return ;
68- }
69- done ( ) ;
70- // eslint-disable-next-line no-console
71- console . log (
72- stats . toString ( {
73- context : path . resolve ( __dirname , '..' ) ,
74- chunks : true ,
75- chunkModules : true ,
76- modules : false ,
77- } )
78- ) ;
79- if ( stats . hasErrors ( ) ) {
80- done (
81- new Error (
82- stats . toString ( {
83- context : path . resolve ( __dirname , '..' ) ,
84- errorDetails : true ,
85- } )
86- )
87- ) ;
88- return ;
89- }
90- const expectedDirectory = path . resolve (
91- directoryForCase ,
92- 'expected'
64+ done ( ) ;
65+ // eslint-disable-next-line no-console
66+ console . log (
67+ stats . toString ( {
68+ context : path . resolve ( __dirname , '..' ) ,
69+ chunks : true ,
70+ chunkModules : true ,
71+ modules : false ,
72+ } )
73+ ) ;
74+ if ( stats . hasErrors ( ) ) {
75+ done (
76+ new Error (
77+ stats . toString ( {
78+ context : path . resolve ( __dirname , '..' ) ,
79+ errorDetails : true ,
80+ } )
81+ )
9382 ) ;
83+ return ;
84+ }
85+ const expectedDirectory = path . resolve ( directoryForCase , 'expected' ) ;
9486
95- for ( const file of walkSync ( expectedDirectory ) ) {
96- const actualFilePath = file . replace (
97- new RegExp ( `/cases/${ directory } /expected/` ) ,
98- `/js/${ directory } /`
99- ) ;
100- const expectedContent = fs . readFileSync ( file , 'utf-8' ) ;
101- const actualContent = fs . readFileSync ( actualFilePath , 'utf-8' ) ;
87+ for ( const file of walkSync ( expectedDirectory ) ) {
88+ const actualFilePath = file . replace (
89+ new RegExp ( `/cases/${ directory } /expected/` ) ,
90+ `/js/${ directory } /`
91+ ) ;
92+ const expectedContent = fs . readFileSync ( file , 'utf-8' ) ;
93+ const actualContent = fs . readFileSync ( actualFilePath , 'utf-8' ) ;
10294
103- expect ( actualContent ) . toEqual ( expectedContent ) ;
104- }
105- done ( ) ;
106- } ) ;
107- } ,
108- 10000
109- ) ;
95+ expect ( actualContent ) . toEqual ( expectedContent ) ;
96+ }
97+ done ( ) ;
98+ } ) ;
99+ } , 10000 ) ;
110100 }
111101 }
112102} ) ;
113103
114104/**
115105 * Synchronously traverse directory of files
116106 * @param {String } dir
117- * @returns {String } // path to file or directory
107+ * @returns {String } path to file or directory
118108 */
119109function * walkSync ( dir ) {
120110 for ( const file of fs . readdirSync ( dir ) ) {
0 commit comments