From 763731bb4aa743e42c29346765976b7e9b40922c Mon Sep 17 00:00:00 2001 From: Edward Drapkin Date: Sun, 18 Nov 2018 15:50:51 -0500 Subject: [PATCH] Allow unknown arguments to pass through detox to the test runner --- detox/local-cli/detox-test.js | 15 +++++++++++++-- docs/APIRef.DetoxCLI.md | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/detox/local-cli/detox-test.js b/detox/local-cli/detox-test.js index a6fe59a13c..fcaf11cdb7 100644 --- a/detox/local-cli/detox-test.js +++ b/detox/local-cli/detox-test.js @@ -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]', @@ -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]; @@ -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'}); @@ -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, diff --git a/docs/APIRef.DetoxCLI.md b/docs/APIRef.DetoxCLI.md index fbc7bf9da2..057fca5eb4 100644 --- a/docs/APIRef.DetoxCLI.md +++ b/docs/APIRef.DetoxCLI.md @@ -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'