From 25f5c62951af78ec928d77a03c379c604340ab4b Mon Sep 17 00:00:00 2001 From: Rotem M Date: Mon, 27 Nov 2017 21:39:19 +0200 Subject: [PATCH] Added initial support for filtering platform specific tests in cli --- detox/local-cli/detox-test.js | 50 ++++++++++++++++++-------- examples/demo-react-native/e2e/init.js | 1 - 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/detox/local-cli/detox-test.js b/detox/local-cli/detox-test.js index 8eeb1b2e2a..7396d7d500 100644 --- a/detox/local-cli/detox-test.js +++ b/detox/local-cli/detox-test.js @@ -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; @@ -45,9 +52,10 @@ 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'}); @@ -55,7 +63,8 @@ function runMocha() { 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', @@ -70,7 +79,6 @@ function runJest() { }); } - function getDefaultRunnerConfig() { let defaultConfig; switch (runner) { @@ -78,8 +86,22 @@ function getDefaultRunnerConfig() { 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; } \ No newline at end of file diff --git a/examples/demo-react-native/e2e/init.js b/examples/demo-react-native/e2e/init.js index 1484fd9eb0..5326ee5239 100644 --- a/examples/demo-react-native/e2e/init.js +++ b/examples/demo-react-native/e2e/init.js @@ -1,4 +1,3 @@ -require('babel-polyfill'); const detox = require('detox'); const config = require('../package.json').detox;