@@ -10,26 +10,28 @@ import commander from 'commander';
10
10
import logger from 'cli-logger' ;
11
11
import glob from 'glob' ;
12
12
import spawn from 'cross-spawn' ;
13
- import * as dotenv from 'dotenv' ;
13
+ import * as dotenv from 'dotenv' ;
14
14
import { exit } from 'process' ;
15
+ import sanitize from 'sanitize-filename' ;
16
+
15
17
dotenv . config ( ) ;
16
18
commander
17
19
. usage ( '[options] project.side [project.side] [*.side]' )
18
20
. option ( '-d, --debug' , 'output extra debugging' )
19
21
. option ( '-f, --filter <grep regex>' , 'Run tests matching name' )
20
22
. option ( '--base-url <url>' , 'Override the base URL that was set in the IDE' )
21
23
. option ( '--test-timeout <ms>' , 'Timeout value for each tests (default: 30000)' )
22
- . option ( '--browserstack.config <path>' , 'path to browserstack config file, default to browserstack.yml' )
24
+ . option ( '--browserstack.config <path>' , 'path to browserstack config file, default to browserstack.yml' )
23
25
. option ( '--output-format <json|xunit>' , 'Format for the output file.' )
24
- . option ( '--output-file <path>' , 'path for the report file. required if --output-format provided' )
26
+ . option ( '--output-file <path>' , 'path for the report file. required if --output-format provided' )
25
27
26
28
commander . parse ( process . argv ) ;
27
29
const options = commander . opts ( ) ;
28
30
options . testTimeout = options . testTimeout ? options . testTimeout : 30000
29
31
options . filter = options . filter ? options . filter : ''
30
32
options . browserstackConfig = options [ 'browserstack.config' ] ? options [ 'browserstack.config' ] : 'browserstack.yml'
31
33
options . buildFolderPath = '_generated'
32
- var conf = { level : options . debug ? logger . DEBUG :logger . INFO } ;
34
+ var conf = { level : options . debug ? logger . DEBUG : logger . INFO } ;
33
35
var log = logger ( conf ) ;
34
36
35
37
const sideFiles = [
@@ -49,7 +51,7 @@ function readFile(filename) {
49
51
fs . readFileSync (
50
52
path . join (
51
53
'.' ,
52
- filename
54
+ sanitize ( filename )
53
55
)
54
56
)
55
57
)
@@ -64,21 +66,18 @@ function normalizeProject(project) {
64
66
return _project
65
67
}
66
68
67
- for ( const sideFileName of sideFiles )
68
- {
69
+ for ( const sideFileName of sideFiles ) {
69
70
const project = normalizeProject ( readFile ( sideFileName ) )
70
- for ( const aSuite of project . suites )
71
- {
72
- for ( const aTestCase of aSuite . tests )
73
- {
71
+ for ( const aSuite of project . suites ) {
72
+ for ( const aTestCase of aSuite . tests ) {
74
73
const test = project . tests . find ( test => test . name === aTestCase ) ;
75
74
var results = await codeExport . default . emit . test ( {
76
75
baseUrl : options . baseUrl ? options . baseUrl : project . url ,
77
76
test : test ,
78
77
tests : project . tests ,
79
78
project : project
80
79
} )
81
- fs . writeFileSync ( path . join (
80
+ fs . writeFileSync ( path . join (
82
81
options . buildFolderPath ,
83
82
results . filename
84
83
) , results . body ) ;
@@ -88,13 +87,12 @@ for(const sideFileName of sideFiles)
88
87
}
89
88
90
89
var reporter = [ ]
91
- if ( options . outputFormat && options . outputFile )
92
- reporter = [ '--reporter' , options . outputFormat , '--reporter-options' , 'output=' + options . outputFile ]
90
+ if ( options . outputFormat && options . outputFile )
91
+ reporter = [ '--reporter' , options . outputFormat , '--reporter-options' , 'output=' + options . outputFile ]
93
92
94
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 } } ) ;
95
94
96
- if ( ! options . debug )
97
- {
95
+ if ( ! options . debug ) {
98
96
rimraf . sync ( options . buildFolderPath )
99
97
}
100
98
exit ( testSuiteProcess . status )
0 commit comments