Skip to content

Commit

Permalink
extend getConfigFor to support multiple keys
Browse files Browse the repository at this point in the history
and use “fallback” instead of “defaults” because it’s singular and not a keyword
  • Loading branch information
jeremyeaton89 committed Mar 11, 2018
1 parent 744c426 commit bd76fc7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions detox/local-cli/detox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,22 @@ program

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

const testFolder = getConfigFor('file', '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 keyKebabCase = camelToKebabCase(key);
const config = program[keys[i]] || config[keys[i]] || config[keyKebabCase];
if (config) return config;
}

return fallback;
}

function camelToKebabCase(string) {
Expand Down

0 comments on commit bd76fc7

Please sign in to comment.