@@ -41,115 +41,114 @@ function convertToArrayOfLines(outputArray) {
4141 return outputArray . join ( "" ) . split ( "\n" ) ;
4242}
4343
44+ function findTestsRecursive ( readPath ) {
45+ const entries = fs . readdirSync ( readPath ) ;
46+ const isAnyTests = entries . indexOf ( "test.js" ) !== - 1 ;
47+
48+ const folders = entries
49+ . map ( entry => path . join ( readPath , entry ) )
50+ . filter ( entry => fs . statSync ( entry ) . isDirectory ( ) ) ;
51+
52+ const result = isAnyTests ? [ readPath ] : [ ]
53+
54+ return result . concat ( folders . map ( findTestsRecursive ) . reduce ( ( acc , list ) => acc . concat ( list ) , [ ] ) ) ;
55+ }
56+
4457const casesPath = path . join ( __dirname , "binCases" ) ;
4558const defaultArgs = loadOptsFile ( path . join ( casesPath , "test.opts" ) ) ;
4659
4760describe ( "BinTestCases" , function ( ) {
48- const categoryDirectories = fs . readdirSync ( casesPath ) . filter ( ( folder ) => {
49- return fs . statSync ( path . join ( casesPath , folder ) ) . isDirectory ( ) ;
50- } ) ;
61+ const tests = findTestsRecursive ( casesPath ) ;
62+
63+ tests . forEach ( testDirectory => {
64+ const testName = testDirectory . replace ( casesPath , "" ) ;
65+ const testArgs = getTestSpecificArguments ( testDirectory ) || defaultArgs ;
66+ const testAssertions = require ( path . join ( testDirectory , "test.js" ) ) ;
67+ const outputPath = path . join ( path . resolve ( casesPath , "../js/bin" ) , testName ) ;
68+
69+ const cmd = `${ path . resolve ( process . cwd ( ) , "bin/webpack.js" ) } ` ;
70+ const args = testArgs . concat ( [ "--output-path" , `${ outputPath } ` ] ) ;
71+ const opts = {
72+ cwd : path . resolve ( "./" , testDirectory )
73+ } ;
74+
75+ const asyncExists = fs . existsSync ( path . join ( testDirectory , "async" ) ) ;
5176
52- const categories = categoryDirectories . map ( function ( categoryDirectory ) {
53- return {
54- name : categoryDirectory ,
55- tests : fs . readdirSync ( path . join ( casesPath , categoryDirectory ) )
77+ const env = {
78+ stdout : [ ] ,
79+ stderr : [ ] ,
80+ error : [ ]
5681 } ;
57- } ) ;
5882
59- categories . forEach ( function ( category ) {
60- describe ( category . name , function ( ) {
61-
62- category . tests . forEach ( function ( testName ) {
63- const testDirectory = path . join ( casesPath , category . name , testName ) ;
64- const testArgs = getTestSpecificArguments ( testDirectory ) || defaultArgs ;
65- const testAssertions = require ( path . join ( testDirectory , "test.js" ) ) ;
66- const outputPath = path . join ( path . resolve ( casesPath , "../js/bin" ) , category . name , testName ) ;
67-
68- const cmd = `${ path . resolve ( process . cwd ( ) , "bin/webpack.js" ) } ` ;
69- const args = testArgs . concat ( [ "--output-path" , `${ outputPath } ` ] ) ;
70- const opts = {
71- cwd : path . resolve ( "./" , testDirectory )
72- } ;
73-
74- const asyncExists = fs . existsSync ( path . join ( testDirectory , "async" ) ) ;
75-
76- const env = {
77- stdout : [ ] ,
78- stderr : [ ] ,
79- error : [ ]
80- } ;
81-
82- if ( asyncExists ) {
83- describe ( testName , function ( ) {
84- it ( "should run successfully" , function ( done ) {
85- this . timeout ( 10000 ) ;
86- const child = spawn ( [ cmd ] . concat ( args ) , opts ) ;
87-
88- child . on ( "close" , function ( code ) {
89- env . code = code ;
90- } ) ;
91-
92- child . on ( "error" , function ( error ) {
93- env . error . push ( error ) ;
94- } ) ;
95-
96- child . stdout . on ( "data" , ( data ) => {
97- env . stdout . push ( data ) ;
98- } ) ;
99-
100- child . stderr . on ( "data" , ( data ) => {
101- env . stderr . push ( data ) ;
102- } ) ;
103-
104- setTimeout ( ( ) => {
105- if ( env . code ) {
106- done ( `Watch didn't run ${ env . error } ` ) ;
107- }
108-
109- const stdout = convertToArrayOfLines ( env . stdout ) ;
110- const stderr = convertToArrayOfLines ( env . stderr ) ;
111- testAssertions ( stdout , stderr , done ) ;
112- child . kill ( ) ;
113- } , 8000 ) ; // wait a little to get an output
114- } ) ;
83+ if ( asyncExists ) {
84+ describe ( testName , function ( ) {
85+ it ( "should run successfully" , function ( done ) {
86+ this . timeout ( 10000 ) ;
87+ const child = spawn ( [ cmd ] . concat ( args ) , opts ) ;
88+
89+ child . on ( "close" , function ( code ) {
90+ env . code = code ;
91+ } ) ;
92+
93+ child . on ( "error" , function ( error ) {
94+ env . error . push ( error ) ;
11595 } ) ;
116- } else {
117- describe ( testName , function ( ) {
118- before ( function ( done ) {
119- this . timeout ( 20000 ) ;
120-
121- const child = spawn ( [ cmd ] . concat ( args ) , opts ) ;
122-
123- child . on ( "close" , function ( code ) {
124- env . code = code ;
125- done ( ) ;
126- } ) ;
127-
128- child . on ( "error" , function ( error ) {
129- env . error . push ( error ) ;
130- } ) ;
131-
132- child . stdout . on ( "data" , ( data ) => {
133- env . stdout . push ( data ) ;
134- } ) ;
135-
136- child . stderr . on ( "data" , ( data ) => {
137- env . stderr . push ( data ) ;
138- } ) ;
139- } ) ;
140-
141- it ( "should not cause any errors" , function ( ) {
142- should ( env . error ) . be . empty ( ) ;
143- } ) ;
144-
145- it ( "should run successfully" , function ( ) {
146- const stdout = convertToArrayOfLines ( env . stdout ) ;
147- const stderr = convertToArrayOfLines ( env . stderr ) ;
148- testAssertions ( env . code , stdout , stderr ) ;
149- } ) ;
96+
97+ child . stdout . on ( "data" , ( data ) => {
98+ env . stdout . push ( data ) ;
99+ } ) ;
100+
101+ child . stderr . on ( "data" , ( data ) => {
102+ env . stderr . push ( data ) ;
150103 } ) ;
151- }
104+
105+ setTimeout ( ( ) => {
106+ if ( env . code ) {
107+ done ( `Watch didn't run ${ env . error } ` ) ;
108+ }
109+
110+ const stdout = convertToArrayOfLines ( env . stdout ) ;
111+ const stderr = convertToArrayOfLines ( env . stderr ) ;
112+ testAssertions ( stdout , stderr , done ) ;
113+ child . kill ( ) ;
114+ } , 8000 ) ; // wait a little to get an output
115+ } ) ;
152116 } ) ;
153- } ) ;
117+ } else {
118+ describe ( testName , function ( ) {
119+ before ( function ( done ) {
120+ this . timeout ( 20000 ) ;
121+
122+ const child = spawn ( [ cmd ] . concat ( args ) , opts ) ;
123+
124+ child . on ( "close" , function ( code ) {
125+ env . code = code ;
126+ done ( ) ;
127+ } ) ;
128+
129+ child . on ( "error" , function ( error ) {
130+ env . error . push ( error ) ;
131+ } ) ;
132+
133+ child . stdout . on ( "data" , ( data ) => {
134+ env . stdout . push ( data ) ;
135+ } ) ;
136+
137+ child . stderr . on ( "data" , ( data ) => {
138+ env . stderr . push ( data ) ;
139+ } ) ;
140+ } ) ;
141+
142+ it ( "should not cause any errors" , function ( ) {
143+ should ( env . error ) . be . empty ( ) ;
144+ } ) ;
145+
146+ it ( "should run successfully" , function ( ) {
147+ const stdout = convertToArrayOfLines ( env . stdout ) ;
148+ const stderr = convertToArrayOfLines ( env . stderr ) ;
149+ testAssertions ( env . code , stdout , stderr ) ;
150+ } ) ;
151+ } ) ;
152+ }
154153 } ) ;
155154} ) ;
0 commit comments