Skip to content

Commit

Permalink
Allow unknown arguments to pass through detox to the test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Drapkin committed Nov 23, 2018
1 parent b0e3b0f commit 763731b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions detox/local-cli/detox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const DetoxConfigError = require('../src/errors/DetoxConfigError');
const config = require(path.join(process.cwd(), 'package.json')).detox;

program
.allowUnknownOption()
.option('-o, --runner-config [config]',
`Test runner config file, defaults to e2e/mocha.opts for mocha and e2e/config.json' for jest`)
.option('-s, --specs [relativePath]',
Expand Down Expand Up @@ -89,6 +90,16 @@ function run() {
}
}

function collectExtraArgs() {
const parsed = program.parseOptions(program.normalize(process.argv.slice(2)));

if (parsed && Array.isArray(parsed.unknown) && parsed.unknown.length > 0) {
return parsed.unknown.join(' ');
}

return '';
}

function getConfigFor(keys, fallback) {
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
Expand Down Expand Up @@ -123,7 +134,7 @@ function runMocha() {
const binPath = path.join('node_modules', '.bin', 'mocha');
const command = `${binPath} ${testFolder} ${configFile} ${configuration} ${loglevel} ${color} ` +
`${cleanup} ${reuse} ${debugSynchronization} ${platformString} ${headless} ` +
`${logs} ${screenshots} ${videos} ${artifactsLocation} ${deviceName}`;
`${logs} ${screenshots} ${videos} ${artifactsLocation} ${deviceName} ${collectExtraArgs()}`;

console.log(command);
cp.execSync(command, {stdio: 'inherit'});
Expand All @@ -135,7 +146,7 @@ function runJest() {
const platformString = platform ? shellQuote(`--testNamePattern=^((?!${getPlatformSpecificString(platform)}).)*$`) : '';
const binPath = path.join('node_modules', '.bin', 'jest');
const color = program.color ? '' : ' --no-color';
const command = `${binPath} ${testFolder} ${configFile}${color} --maxWorkers=${program.workers} ${platformString}`;
const command = `${binPath} ${testFolder} ${configFile}${color} --maxWorkers=${program.workers} ${platformString} ${collectExtraArgs()}`;
const detoxEnvironmentVariables = {
configuration: program.configuration,
loglevel: program.loglevel,
Expand Down
1 change: 1 addition & 0 deletions docs/APIRef.DetoxCLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Initiating your test suite
| -w, --workers | [iOS Only] Specifies number of workers the test runner should spawn, requires a test runner with parallel execution support (Detox CLI currently supports Jest) |
| -n, --device-name [name] | Override the device name specified in a configuration. Useful for running a single build configuration on multiple devices. |
> NOTE: such log levels as `silly` and `wss` are deprecated since detox@8.1.0 and will be removed in 9.0.0.
> NOTE: extra arguments to Detox will be passed through to the test runner (e.g. --bail or --forceExit)
### build
Run a command defined in 'configuration.build'
Expand Down

0 comments on commit 763731b

Please sign in to comment.