From bd76fc7c97307b96c58e8fbc4279b45cd65f7c3a Mon Sep 17 00:00:00 2001 From: Jeremy Eaton Date: Sun, 11 Mar 2018 16:09:50 -0700 Subject: [PATCH] extend getConfigFor to support multiple keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and use “fallback” instead of “defaults” because it’s singular and not a keyword --- detox/local-cli/detox-test.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/detox/local-cli/detox-test.js b/detox/local-cli/detox-test.js index b16a1719b5..f5bfc01d70 100644 --- a/detox/local-cli/detox-test.js +++ b/detox/local-cli/detox-test.js @@ -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) {