11#!/usr/bin/env node
22
33import fs from 'fs'
4- import rimraf from "rimraf" ;
4+ import { rimrafSync } from "rimraf" ;
55import path from 'path'
66import codeExport from './browserstack-mocha-export.mjs'
77import { project as projectProcessor } from '@seleniumhq/side-code-export'
88import pkg from '@seleniumhq/side-utils' ;
99import commander from 'commander' ;
1010import logger from 'cli-logger' ;
11- import glob from 'glob' ;
11+ import { globSync } from 'glob' ;
1212import spawn from 'cross-spawn' ;
1313import * as dotenv from 'dotenv' ;
1414import { exit } from 'process' ;
1515import sanitize from 'sanitize-filename' ;
16+ import { fileURLToPath } from 'url' ;
1617
1718dotenv . config ( ) ;
1819commander
@@ -36,14 +37,14 @@ var log = logger(conf);
3637
3738const sideFiles = [
3839 ...commander . args . reduce ( ( projects , project ) => {
39- glob . sync ( project ) . forEach ( p => {
40+ globSync ( project ) . forEach ( p => {
4041 projects . add ( p )
4142 } )
4243 return projects
4344 } , new Set ( ) ) ,
4445] ;
4546
46- rimraf . sync ( options . buildFolderPath )
47+ rimrafSync ( options . buildFolderPath )
4748fs . mkdirSync ( options . buildFolderPath ) ;
4849
4950function readFile ( filename ) {
@@ -90,9 +91,20 @@ var reporter = []
9091if ( options . outputFormat && options . outputFile )
9192 reporter = [ '--reporter' , options . outputFormat , '--reporter-options' , 'output=' + options . outputFile ]
9293
93- const testSuiteProcess = spawn . sync ( 'npx' , [ 'browserstack-node-sdk' , 'mocha' , '_generated' , '--timeouts' , options . testTimeout , '-g' , options . filter , '--browserstack.config' , options . browserstackConfig , ...reporter ] , { stdio : 'inherit' , env : { ...process . env , testTimeout : options . testTimeout } } ) ;
94+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
95+ const browserstackSdkPath = path . join ( __dirname , 'node_modules' , '.bin' , 'browserstack-node-sdk' ) ;
96+ const sideRunnerNodeModules = path . join ( __dirname , 'node_modules' ) ;
97+
98+ const testSuiteProcess = spawn . sync ( browserstackSdkPath , [ 'mocha' , '_generated' , '--timeouts' , options . testTimeout , '-g' , options . filter , '--browserstack.config' , options . browserstackConfig , ...reporter ] , {
99+ stdio : 'inherit' ,
100+ env : {
101+ ...process . env ,
102+ testTimeout : options . testTimeout ,
103+ NODE_PATH : `${ sideRunnerNodeModules } ${ path . delimiter } ${ process . env . NODE_PATH || '' } `
104+ }
105+ } ) ;
94106
95107if ( ! options . debug ) {
96- rimraf . sync ( options . buildFolderPath )
108+ rimrafSync ( options . buildFolderPath )
97109}
98110exit ( testSuiteProcess . status )
0 commit comments