@@ -5,6 +5,8 @@ var fs = require("fs");
55
66var duneBinDir = require ( "./dune" ) . duneBinDir ;
77
8+ const { exec } = require ( "./utils.js" ) ;
9+
810var ounitTest = false ;
911var mochaTest = false ;
1012var bsbTest = false ;
@@ -37,7 +39,7 @@ if (all) {
3739 formatTest = true ;
3840}
3941
40- function runTests ( ) {
42+ async function runTests ( ) {
4143 if ( ounitTest ) {
4244 cp . execSync ( path . join ( duneBinDir , "ounit_tests" ) , {
4345 stdio : [ 0 , 1 , 2 ] ,
@@ -56,7 +58,7 @@ function runTests() {
5658 console . log ( "Doing build_tests" ) ;
5759 var buildTestDir = path . join ( __dirname , ".." , "jscomp" , "build_tests" ) ;
5860 var files = fs . readdirSync ( buildTestDir ) ;
59- files . forEach ( function ( file ) {
61+ for ( const file of files ) {
6062 var testDir = path . join ( buildTestDir , file ) ;
6163 if ( file === "node_modules" || ! fs . lstatSync ( testDir ) . isDirectory ( ) ) {
6264 return ;
@@ -65,23 +67,18 @@ function runTests() {
6567 console . warn ( `input.js does not exist in ${ testDir } ` ) ;
6668 } else {
6769 console . log ( `testing ${ file } ` ) ;
70+
6871 // 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 ) ;
7474
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+ }
8380 }
84- } ) ;
81+ }
8582 }
8683
8784 if ( formatTest ) {
@@ -92,12 +89,4 @@ function runTests() {
9289 }
9390}
9491
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