11import readdir from "fs-readdir-recursive" ;
22import * as helper from "@babel/helper-fixtures" ;
33import rimraf from "rimraf" ;
4+ import semver from "semver" ;
45import child from "child_process" ;
56import path from "path" ;
67import fs from "fs" ;
@@ -150,13 +151,17 @@ const assertTest = function (stdout, stderr, opts, cwd) {
150151 }
151152} ;
152153
154+ const nodeGte8 = semver . gte ( process . version , "8.0.0" ) ;
155+
153156const buildTest = function ( binName , testName , opts ) {
154157 const binLoc = path . join ( dirname , "../lib" , binName ) ;
155158
156159 return function ( callback ) {
157160 saveInFiles ( opts . inFiles ) ;
158161
159- let args = [ binLoc ] ;
162+ let args = nodeGte8
163+ ? [ "--require" , path . join ( dirname , "./exit-loader.cjs" ) , binLoc ]
164+ : [ binLoc ] ;
160165
161166 if ( binName !== "babel-external-helpers" && ! opts . noDefaultPlugins ) {
162167 args . push ( "--presets" , presetLocs , "--plugins" , pluginLocs ) ;
@@ -165,7 +170,11 @@ const buildTest = function (binName, testName, opts) {
165170 args = args . concat ( opts . args ) ;
166171 const env = { ...process . env , ...opts . env } ;
167172
168- const spawn = child . spawn ( process . execPath , args , { env, cwd : tmpLoc } ) ;
173+ const spawn = child . spawn ( process . execPath , args , {
174+ env,
175+ cwd : tmpLoc ,
176+ stdio : [ null , null , null , "ipc" ] ,
177+ } ) ;
169178
170179 let stderr = "" ;
171180 let stdout = "" ;
@@ -211,7 +220,11 @@ const buildTest = function (binName, testName, opts) {
211220 spawn . stderr . pipe ( executor . stdin ) ;
212221
213222 executor . on ( "close" , function ( ) {
214- setTimeout ( ( ) => spawn . kill ( "SIGINT" ) , 250 ) ;
223+ if ( nodeGte8 ) {
224+ spawn . send ( "exit" ) ;
225+ } else {
226+ spawn . kill ( "SIGKILL" ) ;
227+ }
215228 } ) ;
216229
217230 captureOutput ( executor ) ;
0 commit comments