@@ -12,7 +12,7 @@ const basicConfigPath = path.resolve(
12
12
'../fixtures/cli/webpack.config.js'
13
13
) ;
14
14
15
- function runWebackDevServer ( testArgs , configPath ) {
15
+ function testBin ( testArgs , configPath ) {
16
16
const cwd = process . cwd ( ) ;
17
17
const env = process . env . NODE_ENV ;
18
18
let stdout = '' ;
@@ -36,13 +36,25 @@ function runWebackDevServer(testArgs, configPath) {
36
36
child . on ( 'error' , ( error ) => reject ( error ) ) ;
37
37
38
38
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 ( ) ;
46
+ }
40
47
} ) ;
41
48
42
49
child . stderr . on ( 'data' , ( data ) => {
43
50
stderr += data . toString ( ) ;
44
51
} ) ;
45
52
53
+ child . on ( 'end' , ( ) => {
54
+ console . log ( 'end' ) ;
55
+ } ) ;
56
+
57
+ // cannot catch when function is promise
46
58
child . on ( 'close' , ( code ) => {
47
59
if ( code !== 0 ) {
48
60
return reject ( stderr ) ;
@@ -52,4 +64,4 @@ function runWebackDevServer(testArgs, configPath) {
52
64
} ) ;
53
65
}
54
66
55
- module . exports = runWebackDevServer ;
67
+ module . exports = testBin ;
0 commit comments