@@ -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,38 @@ 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 . setEncoding ( "utf8" ) . on ( "data" , line => {
79
+ console . log ( line ) ;
80
+ } ) ;
81
+
82
+ let stderr = "" ;
83
+ p . stderr . setEncoding ( "utf8" ) . on ( "data" , line => {
84
+ stderr += line + "\n" ;
85
+ } ) ;
86
+
87
+ p . once ( "error" , err => {
88
+ console . log ( `❌ error in ${ file } with stderr:\n` , stderr ) ;
89
+ // @ts -ignore
90
+ reject ( err ) ;
91
+ } ) ;
92
+
93
+ p . once ( "close" , ( ) => {
94
+ if ( ! stderr ) {
95
+ console . log ( "✅ success in" , file ) ;
81
96
}
82
- ) ;
97
+ // @ts -ignore
98
+ resolve ( ) ;
99
+ } ) ;
83
100
}
101
+
102
+ return promise ;
84
103
} ) ;
104
+
105
+ await Promise . all ( tasks ) ;
85
106
}
86
107
87
108
if ( formatTest ) {
@@ -92,9 +113,9 @@ function runTests() {
92
113
}
93
114
}
94
115
95
- function main ( ) {
116
+ async function main ( ) {
96
117
try {
97
- runTests ( ) ;
118
+ await runTests ( ) ;
98
119
} catch ( err ) {
99
120
console . error ( err ) ;
100
121
process . exit ( 2 ) ;
0 commit comments