@@ -32,70 +32,101 @@ describe('TestCases', () => {
3232 for ( const directory of fs . readdirSync ( casesDirectory ) ) {
3333 if ( ! / ^ ( \. | _ ) / . test ( directory ) ) {
3434 // eslint-disable-next-line no-loop-func
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-
44- for ( const config of [ ] . concat ( webpackConfig ) ) {
45- Object . assign (
46- config ,
47- {
48- mode : 'none' ,
49- context : directoryForCase ,
50- output : Object . assign (
51- {
52- path : outputDirectoryForCase ,
53- } ,
54- config . output
55- ) ,
56- } ,
57- config
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
5842 ) ;
59- }
60-
61- webpack ( webpackConfig , ( err , stats ) => {
62- if ( err ) {
63- done ( err ) ;
64- return ;
65- }
66-
67- done ( ) ;
68-
69- // eslint-disable-next-line no-console
70- console . log (
71- stats . toString ( {
72- context : path . resolve ( __dirname , '..' ) ,
73- chunks : true ,
74- chunkModules : true ,
75- modules : false ,
76- } )
77- ) ;
78-
79- if ( stats . hasErrors ( ) ) {
80- done (
81- new Error (
82- stats . toString ( {
83- context : path . resolve ( __dirname , '..' ) ,
84- errorDetails : true ,
85- } )
86- )
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
8762 ) ;
88-
89- return ;
9063 }
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'
93+ ) ;
9194
92- const expectedDirectory = path . resolve ( directoryForCase , 'expected' ) ;
93-
94- compareDirectory ( outputDirectoryForCase , expectedDirectory ) ;
95-
96- done ( ) ;
97- } ) ;
98- } , 10000 ) ;
95+ for ( const file of walkSync ( expectedDirectory ) ) {
96+ const expectedContent = fs . readFileSync (
97+ path . resolve ( expectedDirectory , path . basename ( file ) ) ,
98+ 'utf-8'
99+ ) ;
100+
101+ const actualContent = fs . readFileSync (
102+ path . resolve ( outputDirectoryForCase , file ) ,
103+ 'utf-8'
104+ ) ;
105+
106+ expect ( actualContent ) . toEqual ( expectedContent ) ;
107+ }
108+ done ( ) ;
109+ } ) ;
110+ } ,
111+ 10000
112+ ) ;
99113 }
100114 }
101115} ) ;
116+
117+ /**
118+ * Synchronously traverse directory of files
119+ * @param {String } dir
120+ * @returns {String } // path to file or directory
121+ */
122+ function * walkSync ( dir ) {
123+ for ( const file of fs . readdirSync ( dir ) ) {
124+ const pathToFile = path . join ( dir , file ) ;
125+ const isDirectory = fs . statSync ( pathToFile ) . isDirectory ( ) ;
126+ if ( isDirectory ) {
127+ yield * walkSync ( pathToFile ) ;
128+ } else {
129+ yield pathToFile ;
130+ }
131+ }
132+ }
0 commit comments