1
1
#!/usr/bin/env node
2
2
3
3
import fs from 'fs'
4
- import rimraf from "rimraf" ;
4
+ import { rimrafSync } from "rimraf" ;
5
5
import path from 'path'
6
6
import codeExport from './browserstack-mocha-export.mjs'
7
7
import { project as projectProcessor } from '@seleniumhq/side-code-export'
8
8
import pkg from '@seleniumhq/side-utils' ;
9
9
import commander from 'commander' ;
10
10
import logger from 'cli-logger' ;
11
- import glob from 'glob' ;
11
+ import { globSync } from 'glob' ;
12
12
import spawn from 'cross-spawn' ;
13
13
import * as dotenv from 'dotenv' ;
14
14
import { exit } from 'process' ;
15
15
import sanitize from 'sanitize-filename' ;
16
+ import { fileURLToPath } from 'url' ;
16
17
17
18
dotenv . config ( ) ;
18
19
commander
@@ -36,14 +37,14 @@ var log = logger(conf);
36
37
37
38
const sideFiles = [
38
39
...commander . args . reduce ( ( projects , project ) => {
39
- glob . sync ( project ) . forEach ( p => {
40
+ globSync ( project ) . forEach ( p => {
40
41
projects . add ( p )
41
42
} )
42
43
return projects
43
44
} , new Set ( ) ) ,
44
45
] ;
45
46
46
- rimraf . sync ( options . buildFolderPath )
47
+ rimrafSync ( options . buildFolderPath )
47
48
fs . mkdirSync ( options . buildFolderPath ) ;
48
49
49
50
function readFile ( filename ) {
@@ -90,9 +91,20 @@ var reporter = []
90
91
if ( options . outputFormat && options . outputFile )
91
92
reporter = [ '--reporter' , options . outputFormat , '--reporter-options' , 'output=' + options . outputFile ]
92
93
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
+ } ) ;
94
106
95
107
if ( ! options . debug ) {
96
- rimraf . sync ( options . buildFolderPath )
108
+ rimrafSync ( options . buildFolderPath )
97
109
}
98
110
exit ( testSuiteProcess . status )
0 commit comments