Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for filtering platform specific tests in detox-cli #435

Merged
merged 1 commit into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 36 additions & 14 deletions detox/local-cli/detox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ const program = require('commander');
const path = require('path');
const cp = require('child_process');
program
.option('-o, --runner-config [config]', `Test runner config file, defaults to e2e/mocha.opts for mocha and e2e/config.json' for jest`)
.option('-l, --loglevel [value]', 'info, debug, verbose, silly, wss')
.option('-c, --configuration [device configuration]', 'Select a device configuration from your defined configurations,'
+ 'if not supplied, and there\'s only one configuration, detox will default to it')
.option('-r, --reuse', 'Reuse existing installed app (do not delete and re-install) for a faster run.')
.option('-u, --cleanup', 'Shutdown simulator when test is over, useful for CI scripts, to make sure detox exists cleanly with no residue')
.option('-o, --runner-config [config]',
`Test runner config file, defaults to e2e/mocha.opts for mocha and e2e/config.json' for jest`)
.option('-l, --loglevel [value]',
'info, debug, verbose, silly, wss')
.option('-c, --configuration [device configuration]',
'Select a device configuration from your defined configurations, if not supplied, and there\'s only one configuration, detox will default to it')
.option('-r, --reuse',
'Reuse existing installed app (do not delete and re-install) for a faster run.')
.option('-u, --cleanup',
'Shutdown simulator when test is over, useful for CI scripts, to make sure detox exists cleanly with no residue')
.option('-d, --debug-synchronization [value]',
'When an action/expectation takes a significant amount of time use this option to print device synchronization status. '
'When an action/expectation takes a significant amount of time use this option to print device synchronization status.'
+ 'The status will be printed if the action takes more than [value]ms to complete')
.option('-a, --artifacts-location [path]', 'Artifacts destination path (currently will contain only logs). '
+ 'If the destination already exists, it will be removed first')
.option('-a, --artifacts-location [path]',
'Artifacts destination path (currently will contain only logs). If the destination already exists, it will be removed first')
.option('-p, --platform [ios/android]',
'Run platform specific tests. Runs tests with invert grep on \':platform:\', '
+ 'e.g test with substring \':ios:\' in its name will not run when passing \'--platform android\'')
.parse(process.argv);

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

const debugSynchronization = program.debugSynchronization ? `--debug-synchronization ${program.debugSynchronization}` : '';
const command = `node_modules/.bin/mocha ${testFolder} ${configFile} ${configuration} ${loglevel} ${cleanup} ${reuse} ${debugSynchronization} ${artifactsLocation}`;
const command = `node_modules/.bin/mocha ${testFolder} ${configFile} ${configuration} ${loglevel} ${cleanup} ${reuse} ${debugSynchronization} ${platform} ${artifactsLocation}`;

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

function runJest() {
const configFile = runnerConfig ? `--config=${runnerConfig}` : '';
const command = `node_modules/.bin/jest ${testFolder} ${configFile} --runInBand`;
const platform = program.platform ? `--testNamePattern='^((?!${getPlatformSpecificString(program.platform)}).)*$'` : '';
const command = `node_modules/.bin/jest ${testFolder} ${configFile} --runInBand ${platform}`;
console.log(command);
cp.execSync(command, {
stdio: 'inherit',
Expand All @@ -70,16 +79,29 @@ function runJest() {
});
}


function getDefaultRunnerConfig() {
let defaultConfig;
switch (runner) {
case 'mocha':
defaultConfig = 'e2e/mocha.opts';
break;
case 'jest':
defaultConfig = 'e2e/config.json'
defaultConfig = 'e2e/config.json';
break;
default:
console.log(`Missing 'runner-config' value in detox config in package.json, using '${defaultConfig}' as default for ${runner}`);
}
console.log(`Missing 'runner-config' value in detox config in package.json, using '${defaultConfig}' as default for ${runner}`);

return defaultConfig;
}

function getPlatformSpecificString(platform) {
let platformRevertString;
if (platform === 'ios') {
platformRevertString = ':android:';
} else if (platform === 'android') {
platformRevertString = ':ios:';
}

return platformRevertString;
}
1 change: 0 additions & 1 deletion examples/demo-react-native/e2e/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require('babel-polyfill');
const detox = require('detox');
const config = require('../package.json').detox;

Expand Down