@@ -37,7 +37,7 @@ if (all) {
37
37
formatTest = true ;
38
38
}
39
39
40
- function runTests ( ) {
40
+ async function runTests ( ) {
41
41
if ( ounitTest ) {
42
42
cp . execSync ( path . join ( duneBinDir , "ounit_tests" ) , {
43
43
stdio : [ 0 , 1 , 2 ] ,
@@ -56,7 +56,13 @@ function runTests() {
56
56
console . log ( "Doing build_tests" ) ;
57
57
var buildTestDir = path . join ( __dirname , ".." , "jscomp" , "build_tests" ) ;
58
58
var files = fs . readdirSync ( buildTestDir ) ;
59
- files . forEach ( function ( file ) {
59
+ var tasks = files . map ( async function ( file ) {
60
+ // @ts -ignore
61
+ let resolve , reject ;
62
+ let promise = new Promise ( ( res , rej ) => {
63
+ resolve = res ;
64
+ reject = rej ;
65
+ } ) ;
60
66
var testDir = path . join ( buildTestDir , file ) ;
61
67
if ( file === "node_modules" || ! fs . lstatSync ( testDir ) . isDirectory ( ) ) {
62
68
return ;
@@ -65,23 +71,40 @@ function runTests() {
65
71
console . warn ( `input.js does not exist in ${ testDir } ` ) ;
66
72
} else {
67
73
console . log ( `testing ${ file } ` ) ;
74
+
68
75
// note existsSync test already ensure that it is a directory
69
- cp . exec (
70
- `node input.js` ,
71
- { cwd : testDir , encoding : "utf8" } ,
72
- function ( error , stdout , stderr ) {
73
- console . log ( stdout ) ;
74
-
75
- if ( error !== null ) {
76
- console . log ( `❌ error in ${ file } with stderr:\n` , stderr ) ;
77
- throw error ;
78
- } else {
79
- console . log ( "✅ success in" , file ) ;
80
- }
76
+ let p = cp . spawn ( `node` , [ "input.js" ] , { cwd : testDir } ) ;
77
+
78
+ p . stdout
79
+ . setEncoding ( "utf8" )
80
+ . on ( "data" , line => {
81
+ console . log ( line ) ;
82
+ } ) ;
83
+
84
+ let error = '' ;
85
+ p . stderr
86
+ . setEncoding ( "utf8" )
87
+ . on ( "data" , line => {
88
+ error += line + "\n" ;
89
+ } ) ;
90
+
91
+ p . on ( "close" , ( ) => {
92
+ if ( error ) {
93
+ console . log ( `❌ error in ${ file } with stderr:\n` , error ) ;
94
+ // @ts -ignore
95
+ reject ( error ) ;
96
+ } else {
97
+ console . log ( "✅ success in" , file ) ;
98
+ // @ts -ignore
99
+ resolve ( ) ;
81
100
}
82
- ) ;
101
+ } ) ;
83
102
}
103
+
104
+ return promise ;
84
105
} ) ;
106
+
107
+ await Promise . all ( tasks ) ;
85
108
}
86
109
87
110
if ( formatTest ) {
@@ -92,9 +115,9 @@ function runTests() {
92
115
}
93
116
}
94
117
95
- function main ( ) {
118
+ async function main ( ) {
96
119
try {
97
- runTests ( ) ;
120
+ await runTests ( ) ;
98
121
} catch ( err ) {
99
122
console . error ( err ) ;
100
123
process . exit ( 2 ) ;
0 commit comments