@@ -21,66 +21,63 @@ const swapPkgName = (current, isSubPackage = false) => {
2121
2222const CLI_ENTRY_PATH = path . resolve ( ROOT_PATH , "./packages/webpack-cli/bin/cli.js" ) ;
2323
24- const runTest = ( pkg , cliArgs = [ ] , logMessage = undefined , isSubPackage = false ) => {
24+ const runTest = async ( pkg , cliArgs = [ ] , logMessage = undefined , isSubPackage = false ) => {
2525 // Simulate package missing
2626 swapPkgName ( pkg , isSubPackage ) ;
2727
28- return Promise . resolve ( )
29- . then ( ( ) => import ( "execa" ) )
30- . then ( ( { execa } ) =>
31- execa ( CLI_ENTRY_PATH , cliArgs , {
32- cwd : __dirname ,
33- } ) ,
34- )
35- . then ( ( proc ) => {
36- proc . stdin . setDefaultEncoding ( "utf8" ) ;
28+ const { execa } = await import ( "execa" ) ;
29+ const proc = execa ( CLI_ENTRY_PATH , cliArgs , {
30+ cwd : __dirname ,
31+ } ) ;
3732
38- proc . stdout . on ( "data" , ( chunk ) => {
39- console . log ( ` stdout: ${ chunk . toString ( ) } ` ) ;
40- } ) ;
41- return new Promise ( ( resolve ) => {
42- const timeout = setTimeout ( ( ) => {
43- console . log ( " timeout: killing process" ) ;
44- proc . kill ( ) ;
45- } , 60000 ) ;
33+ proc . stdin . setDefaultEncoding ( "utf8" ) ;
4634
47- const prompt = "Would you like to install" ;
48- let hasLogMessage = false ;
49- let hasPrompt = false ;
50- let hasPassed = false ;
35+ proc . stdout . on ( "data" , ( chunk ) => {
36+ console . log ( ` stdout: ${ chunk . toString ( ) } ` ) ;
37+ } ) ;
5138
52- proc . stderr . on ( "data" , ( chunk ) => {
53- const data = stripVTControlCharacters ( chunk . toString ( ) ) ;
39+ return new Promise ( ( resolve ) => {
40+ const timeout = setTimeout ( ( ) => {
41+ console . log ( " timeout: killing process" ) ;
42+ proc . kill ( ) ;
43+ } , 60000 ) ;
5444
55- console . log ( ` stderr: ${ data } ` ) ;
45+ const prompt = "Would you like to install" ;
46+ let hasLogMessage = false ;
47+ let hasPrompt = false ;
48+ let hasPassed = false ;
5649
57- if ( data . includes ( logMessage ) ) {
58- hasLogMessage = true ;
59- }
50+ proc . stderr . on ( "data" , ( chunk ) => {
51+ const data = stripVTControlCharacters ( chunk . toString ( ) ) ;
6052
61- if ( data . includes ( prompt ) ) {
62- hasPrompt = true ;
63- }
53+ console . log ( ` stderr: ${ data } ` ) ;
6454
65- if ( hasLogMessage && hasPrompt ) {
66- hasPassed = true ;
67- proc . kill ( ) ;
68- }
69- } ) ;
55+ if ( data . includes ( logMessage ) ) {
56+ hasLogMessage = true ;
57+ }
7058
71- proc . on ( "exit" , ( ) => {
72- swapPkgName ( `.${ pkg } ` , isSubPackage ) ;
73- clearTimeout ( timeout ) ;
74- resolve ( hasPassed ) ;
75- } ) ;
59+ if ( data . includes ( prompt ) ) {
60+ hasPrompt = true ;
61+ }
7662
77- proc . on ( "error" , ( ) => {
78- swapPkgName ( `.${ pkg } ` , isSubPackage ) ;
79- clearTimeout ( timeout ) ;
80- resolve ( false ) ;
81- } ) ;
82- } ) ;
63+ if ( hasLogMessage && hasPrompt ) {
64+ hasPassed = true ;
65+ proc . kill ( ) ;
66+ }
67+ } ) ;
68+
69+ proc . on ( "exit" , ( ) => {
70+ swapPkgName ( `.${ pkg } ` , isSubPackage ) ;
71+ clearTimeout ( timeout ) ;
72+ resolve ( hasPassed ) ;
73+ } ) ;
74+
75+ proc . on ( "error" , ( ) => {
76+ swapPkgName ( `.${ pkg } ` , isSubPackage ) ;
77+ clearTimeout ( timeout ) ;
78+ resolve ( false ) ;
8379 } ) ;
80+ } ) ;
8481} ;
8582
8683const runTestStdout = ( { packageName, cliArgs, logMessage, isSubPackage } = { } ) => {
0 commit comments