Skip to content

Commit 2e1a4bb

Browse files
authored
Added initial support for filtering platform specific tests in cli (wix#435)
detox test -c ios.sim.release --platform ios will skip tests marked with :android: in their name detox test -c android.emu.release --platform android will skip tests marked with :ios: in their name
1 parent 6bc31a8 commit 2e1a4bb

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

detox/local-cli/detox-test.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@ const program = require('commander');
44
const path = require('path');
55
const cp = require('child_process');
66
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')
1317
.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.'
1519
+ '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\'')
1825
.parse(process.argv);
1926

2027
const config = require(path.join(process.cwd(), 'package.json')).detox;
@@ -45,17 +52,19 @@ function runMocha() {
4552
const reuse = program.reuse ? `--reuse` : '';
4653
const artifactsLocation = program.artifactsLocation ? `--artifacts-location ${program.artifactsLocation}` : '';
4754
const configFile = runnerConfig ? `--opts ${runnerConfig}` : '';
55+
const platform = program.platform ? `--grep ${getPlatformSpecificString(program.platform)} --invert` : '';
4856

4957
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}`;
5159

5260
console.log(command);
5361
cp.execSync(command, {stdio: 'inherit'});
5462
}
5563

5664
function runJest() {
5765
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}`;
5968
console.log(command);
6069
cp.execSync(command, {
6170
stdio: 'inherit',
@@ -70,16 +79,29 @@ function runJest() {
7079
});
7180
}
7281

73-
7482
function getDefaultRunnerConfig() {
7583
let defaultConfig;
7684
switch (runner) {
7785
case 'mocha':
7886
defaultConfig = 'e2e/mocha.opts';
7987
break;
8088
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}`);
8293
}
83-
console.log(`Missing 'runner-config' value in detox config in package.json, using '${defaultConfig}' as default for ${runner}`);
94+
8495
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;
85107
}

examples/demo-react-native/e2e/init.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require('babel-polyfill');
21
const detox = require('detox');
32
const config = require('../package.json').detox;
43

0 commit comments

Comments
 (0)