@@ -12,7 +12,7 @@ const basicConfigPath = path.resolve(
1212 '../fixtures/cli/webpack.config.js'
1313) ;
1414
15- function runWebackDevServer ( testArgs , configPath ) {
15+ function testBin ( testArgs , configPath ) {
1616 const cwd = process . cwd ( ) ;
1717 const env = process . env . NODE_ENV ;
1818 let stdout = '' ;
@@ -36,14 +36,23 @@ function runWebackDevServer(testArgs, configPath) {
3636 child . on ( 'error' , ( error ) => reject ( error ) ) ;
3737
3838 child . stdout . on ( 'data' , ( data ) => {
39- stdout += data . toString ( ) ;
39+ const str = data . toString ( ) ;
40+
41+ stdout += str ;
42+
43+ // if webpack.config.js is a promise function, it won't be able to call `close`
44+ if ( str . includes ( 'Compiled successfully.' ) ) {
45+ child . kill ( 'SIGINT' ) ;
46+ }
4047 } ) ;
4148
4249 child . stderr . on ( 'data' , ( data ) => {
50+ console . log ( '======' ) ;
51+ console . log ( data . toString ( ) ) ;
4352 stderr += data . toString ( ) ;
4453 } ) ;
4554
46- child . on ( 'close ' , ( code ) => {
55+ child . on ( 'exit ' , ( code ) => {
4756 if ( code !== 0 ) {
4857 return reject ( stderr ) ;
4958 }
@@ -52,4 +61,4 @@ function runWebackDevServer(testArgs, configPath) {
5261 } ) ;
5362}
5463
55- module . exports = runWebackDevServer ;
64+ module . exports = testBin ;
0 commit comments