@@ -5,6 +5,8 @@ var fs = require("fs");
5
5
6
6
var duneBinDir = require ( "./dune" ) . duneBinDir ;
7
7
8
+ const { exec } = require ( "./utils.js" ) ;
9
+
8
10
var ounitTest = false ;
9
11
var mochaTest = false ;
10
12
var bsbTest = false ;
@@ -37,7 +39,7 @@ if (all) {
37
39
formatTest = true ;
38
40
}
39
41
40
- function runTests ( ) {
42
+ async function runTests ( ) {
41
43
if ( ounitTest ) {
42
44
cp . execSync ( path . join ( duneBinDir , "ounit_tests" ) , {
43
45
stdio : [ 0 , 1 , 2 ] ,
@@ -56,7 +58,7 @@ function runTests() {
56
58
console . log ( "Doing build_tests" ) ;
57
59
var buildTestDir = path . join ( __dirname , ".." , "jscomp" , "build_tests" ) ;
58
60
var files = fs . readdirSync ( buildTestDir ) ;
59
- files . forEach ( function ( file ) {
61
+ for ( const file of files ) {
60
62
var testDir = path . join ( buildTestDir , file ) ;
61
63
if ( file === "node_modules" || ! fs . lstatSync ( testDir ) . isDirectory ( ) ) {
62
64
return ;
@@ -65,23 +67,18 @@ function runTests() {
65
67
console . warn ( `input.js does not exist in ${ testDir } ` ) ;
66
68
} else {
67
69
console . log ( `testing ${ file } ` ) ;
70
+
68
71
// 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 ) ;
72
+ const out = await exec ( `node` , [ "input.js" ] , { cwd : testDir } ) ;
73
+ console . log ( out . stdout ) ;
74
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
- }
81
- }
82
- ) ;
75
+ if ( out . code === 0 ) {
76
+ console . log ( "✅ success in" , file ) ;
77
+ } else {
78
+ console . log ( `❌ error in ${ file } with stderr:\n` , out . stderr ) ;
79
+ }
83
80
}
84
- } ) ;
81
+ }
85
82
}
86
83
87
84
if ( formatTest ) {
@@ -92,12 +89,4 @@ function runTests() {
92
89
}
93
90
}
94
91
95
- function main ( ) {
96
- try {
97
- runTests ( ) ;
98
- } catch ( err ) {
99
- console . error ( err ) ;
100
- process . exit ( 2 ) ;
101
- }
102
- }
103
- main ( ) ;
92
+ runTests ( ) ;
0 commit comments