@@ -14,14 +14,12 @@ import * as gulp from 'gulp';
1414import gzip from 'gulp-gzip' ;
1515import * as fs from 'fs' ;
1616import * as path from 'path' ;
17- import { execSync } from 'child_process' ;
17+ import { spawnSync } from 'child_process' ;
1818import { rimraf } from 'rimraf' ;
1919
2020import { RELEASE_DIR , TEST_TSC_OUTPUT_DIR } from './config.mjs' ;
2121
2222import { runMochaTestsInBrowser } from '../../tests/mocha/webdriver.js' ;
23- import { runGeneratorsInBrowser } from '../../tests/generators/webdriver.js' ;
24- import { runCompileCheckInBrowser } from '../../tests/compile/webdriver.js' ;
2523
2624const OUTPUT_DIR = 'build/generators' ;
2725const GOLDEN_DIR = 'tests/generators/golden' ;
@@ -121,8 +119,20 @@ function reportTestResult() {
121119 * @return {Promise } Asynchronous result.
122120 */
123121async function runTestCommand ( id , command ) {
124- return runTestTask ( id , async ( ) => {
125- return execSync ( command , { stdio : 'inherit' } ) ;
122+ return runTestTask ( id , async ( ) => {
123+ const result = spawnSync ( command , {
124+ shell : true ,
125+ stdio : 'inherit' ,
126+ env : process . env ,
127+ } ) ;
128+ if ( result . error ) {
129+ throw result . error ;
130+ }
131+ if ( result . status !== 0 ) {
132+ throw new Error (
133+ `Command failed with exit code ${ result . status } : ${ command } ` ,
134+ ) ;
135+ }
126136 } ) ;
127137}
128138
@@ -257,24 +267,25 @@ async function metadata() {
257267 * Run Mocha tests inside a browser.
258268 * @return {Promise } Asynchronous result.
259269 */
260- async function mocha ( exitOnCompletion = true ) {
261- return runTestTask ( 'mocha' , async ( ) => {
262- const result = await runMochaTestsInBrowser ( exitOnCompletion ) . catch ( e => {
263- throw e ;
264- } ) ;
265- if ( result ) {
266- throw new Error ( 'Mocha tests failed' ) ;
267- }
268- console . log ( 'Mocha tests passed' ) ;
269- } ) ;
270+ function mocha ( ) {
271+ // Run in a subprocess so webdriverio is not loaded inside gulp's asyncDone
272+ // domain (which has been observed to exit the process on CI after ~2s).
273+ return runTestCommand ( 'mocha' , 'node tests/mocha/webdriver.js' ) ;
270274}
271275
272276/**
273277 * Run Mocha tests inside a browser and keep the browser open upon completion.
274278 * @return {Promise } Asynchronous result.
275279 */
276- export async function interactiveMocha ( ) {
277- return mocha ( false ) ;
280+ export function interactiveMocha ( ) {
281+ return runTestTask ( 'interactiveMocha' , ( ) => {
282+ return runMochaTestsInBrowser ( false ) . then ( ( result ) => {
283+ if ( result ) {
284+ throw new Error ( 'Mocha tests failed' ) ;
285+ }
286+ console . log ( 'Mocha tests passed' ) ;
287+ } ) ;
288+ } ) ;
278289}
279290
280291/**
@@ -335,7 +346,16 @@ export async function generators() {
335346 rimraf . sync ( OUTPUT_DIR ) ;
336347 fs . mkdirSync ( OUTPUT_DIR ) ;
337348
338- await runGeneratorsInBrowser ( OUTPUT_DIR ) ;
349+ const result = spawnSync ( 'node' , [ 'tests/generators/webdriver.js' , OUTPUT_DIR ] , {
350+ stdio : 'inherit' ,
351+ env : process . env ,
352+ } ) ;
353+ if ( result . error ) {
354+ throw result . error ;
355+ }
356+ if ( result . status !== 0 ) {
357+ throw new Error ( 'Generator browser tests failed.' ) ;
358+ }
339359
340360 const generatorSuffixes = [ 'js' , 'py' , 'dart' , 'lua' , 'php' ] ;
341361 let failed = 0 ;
@@ -375,7 +395,10 @@ function advancedCompile() {
375395 * @return {Promise } Asynchronous result.
376396 */
377397function advancedCompileInBrowser ( ) {
378- return runTestTask ( 'advanced_compile_in_browser' , runCompileCheckInBrowser ) ;
398+ return runTestCommand (
399+ 'advanced_compile_in_browser' ,
400+ 'node tests/compile/webdriver.js' ,
401+ ) ;
379402}
380403
381404/**
0 commit comments