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

CLI: add -f option to run specific test file #616

Merged
merged 2 commits into from
Mar 14, 2018
Merged
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
20 changes: 14 additions & 6 deletions detox/local-cli/detox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,29 @@ program
.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\'')
.option('-f, --file [path]',
'Specify test file to run')
.parse(process.argv);

const config = require(path.join(process.cwd(), 'package.json')).detox;

const testFolder = getConfigFor('specs', 'e2e');
const runner = getConfigFor('testRunner', 'mocha');
const runnerConfig = getConfigFor('runnerConfig', getDefaultRunnerConfig());
const testFolder = getConfigFor(['file', 'specs'], 'e2e');
const runner = getConfigFor(['testRunner'], 'mocha');
const runnerConfig = getConfigFor(['runnerConfig'], getDefaultRunnerConfig());

if (typeof program.debugSynchronization === "boolean") {
program.debugSynchronization = 3000;
}

function getConfigFor(key, defaults) {
const keyKebabCase = camelToKebabCase(key);
return program[key] || config[key] || config[keyKebabCase] || defaults;
function getConfigFor(keys, fallback) {
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const keyKebabCase = camelToKebabCase(key);
const result = program[key] || config[key] || config[keyKebabCase];
if (result) return result;
}

return fallback;
}

function camelToKebabCase(string) {
Expand Down