@@ -4,17 +4,24 @@ const program = require('commander');
4
4
const path = require ( 'path' ) ;
5
5
const cp = require ( 'child_process' ) ;
6
6
program
7
- . option ( '-o, --runner-config [config]' , `Test runner config file, defaults to e2e/mocha.opts for mocha and e2e/config.json' for jest` )
8
- . option ( '-l, --loglevel [value]' , 'info, debug, verbose, silly, wss' )
9
- . option ( '-c, --configuration [device configuration]' , 'Select a device configuration from your defined configurations,'
10
- + 'if not supplied, and there\'s only one configuration, detox will default to it' )
11
- . option ( '-r, --reuse' , 'Reuse existing installed app (do not delete and re-install) for a faster run.' )
12
- . option ( '-u, --cleanup' , 'Shutdown simulator when test is over, useful for CI scripts, to make sure detox exists cleanly with no residue' )
7
+ . option ( '-o, --runner-config [config]' ,
8
+ `Test runner config file, defaults to e2e/mocha.opts for mocha and e2e/config.json' for jest` )
9
+ . option ( '-l, --loglevel [value]' ,
10
+ 'info, debug, verbose, silly, wss' )
11
+ . option ( '-c, --configuration [device configuration]' ,
12
+ 'Select a device configuration from your defined configurations, if not supplied, and there\'s only one configuration, detox will default to it' )
13
+ . option ( '-r, --reuse' ,
14
+ 'Reuse existing installed app (do not delete and re-install) for a faster run.' )
15
+ . option ( '-u, --cleanup' ,
16
+ 'Shutdown simulator when test is over, useful for CI scripts, to make sure detox exists cleanly with no residue' )
13
17
. option ( '-d, --debug-synchronization [value]' ,
14
- 'When an action/expectation takes a significant amount of time use this option to print device synchronization status. '
18
+ 'When an action/expectation takes a significant amount of time use this option to print device synchronization status.'
15
19
+ 'The status will be printed if the action takes more than [value]ms to complete' )
16
- . option ( '-a, --artifacts-location [path]' , 'Artifacts destination path (currently will contain only logs). '
17
- + 'If the destination already exists, it will be removed first' )
20
+ . option ( '-a, --artifacts-location [path]' ,
21
+ 'Artifacts destination path (currently will contain only logs). If the destination already exists, it will be removed first' )
22
+ . option ( '-p, --platform [ios/android]' ,
23
+ 'Run platform specific tests. Runs tests with invert grep on \':platform:\', '
24
+ + 'e.g test with substring \':ios:\' in its name will not run when passing \'--platform android\'' )
18
25
. parse ( process . argv ) ;
19
26
20
27
const config = require ( path . join ( process . cwd ( ) , 'package.json' ) ) . detox ;
@@ -45,17 +52,19 @@ function runMocha() {
45
52
const reuse = program . reuse ? `--reuse` : '' ;
46
53
const artifactsLocation = program . artifactsLocation ? `--artifacts-location ${ program . artifactsLocation } ` : '' ;
47
54
const configFile = runnerConfig ? `--opts ${ runnerConfig } ` : '' ;
55
+ const platform = program . platform ? `--grep ${ getPlatformSpecificString ( program . platform ) } --invert` : '' ;
48
56
49
57
const debugSynchronization = program . debugSynchronization ? `--debug-synchronization ${ program . debugSynchronization } ` : '' ;
50
- const command = `node_modules/.bin/mocha ${ testFolder } ${ configFile } ${ configuration } ${ loglevel } ${ cleanup } ${ reuse } ${ debugSynchronization } ${ artifactsLocation } ` ;
58
+ const command = `node_modules/.bin/mocha ${ testFolder } ${ configFile } ${ configuration } ${ loglevel } ${ cleanup } ${ reuse } ${ debugSynchronization } ${ platform } ${ artifactsLocation } ` ;
51
59
52
60
console . log ( command ) ;
53
61
cp . execSync ( command , { stdio : 'inherit' } ) ;
54
62
}
55
63
56
64
function runJest ( ) {
57
65
const configFile = runnerConfig ? `--config=${ runnerConfig } ` : '' ;
58
- const command = `node_modules/.bin/jest ${ testFolder } ${ configFile } --runInBand` ;
66
+ const platform = program . platform ? `--testNamePattern='^((?!${ getPlatformSpecificString ( program . platform ) } ).)*$'` : '' ;
67
+ const command = `node_modules/.bin/jest ${ testFolder } ${ configFile } --runInBand ${ platform } ` ;
59
68
console . log ( command ) ;
60
69
cp . execSync ( command , {
61
70
stdio : 'inherit' ,
@@ -70,16 +79,29 @@ function runJest() {
70
79
} ) ;
71
80
}
72
81
73
-
74
82
function getDefaultRunnerConfig ( ) {
75
83
let defaultConfig ;
76
84
switch ( runner ) {
77
85
case 'mocha' :
78
86
defaultConfig = 'e2e/mocha.opts' ;
79
87
break ;
80
88
case 'jest' :
81
- defaultConfig = 'e2e/config.json'
89
+ defaultConfig = 'e2e/config.json' ;
90
+ break ;
91
+ default :
92
+ console . log ( `Missing 'runner-config' value in detox config in package.json, using '${ defaultConfig } ' as default for ${ runner } ` ) ;
82
93
}
83
- console . log ( `Missing 'runner-config' value in detox config in package.json, using ' ${ defaultConfig } ' as default for ${ runner } ` ) ;
94
+
84
95
return defaultConfig ;
96
+ }
97
+
98
+ function getPlatformSpecificString ( platform ) {
99
+ let platformRevertString ;
100
+ if ( platform === 'ios' ) {
101
+ platformRevertString = ':android:' ;
102
+ } else if ( platform === 'android' ) {
103
+ platformRevertString = ':ios:' ;
104
+ }
105
+
106
+ return platformRevertString ;
85
107
}
0 commit comments