Skip to content

Commit

Permalink
Additional: Fixes #648: detox test fails to determine a default con…
Browse files Browse the repository at this point in the history
…figuration
  • Loading branch information
rotemmiz authored and yershalom committed Apr 4, 2018
1 parent 42f0f6c commit f90eeb0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
26 changes: 18 additions & 8 deletions detox/local-cli/detox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ const program = require('commander');
const path = require('path');
const cp = require('child_process');
const _ = require('lodash');
const CustomError = require('../src/errors/CustomError');
const config = require(path.join(process.cwd(), 'package.json')).detox;

class DetoxConfigError extends CustomError {}



program
.option('-o, --runner-config [config]',
Expand All @@ -15,7 +19,7 @@ program
.option('-l, --loglevel [value]',
'info, debug, verbose, silly, wss')
.option('-c, --configuration [device configuration]',
'Select a device configuration from your defined configurations, if not supplied, and there\'s only one configuration, detox will default to it', determineConfiguration())
'Select a device configuration from your defined configurations, if not supplied, and there\'s only one configuration, detox will default to it', getDefaultConfiguration())
.option('-r, --reuse',
'Reuse existing installed app (do not delete and re-install) for a faster run.')
.option('-u, --cleanup',
Expand All @@ -32,6 +36,16 @@ program
'Specify test file to run')
.parse(process.argv);

if (program.configuration) {
if (!config.configurations[program.configuration]) {
throw new DetoxConfigError(`Cannot determine configuration '${program.configuration}'.
Available configurations: ${_.keys(config.configurations).join(', ')}`);
}
} else if(!program.configuration) {
throw new DetoxConfigError(`Cannot determine which configuration to use.
Use --configuration to choose one of the following: ${_.keys(config.configurations).join(', ')}`);
}

const testFolder = getConfigFor(['file', 'specs'], 'e2e');
const runner = getConfigFor(['testRunner'], 'mocha');
const runnerConfig = getConfigFor(['runnerConfig'], getDefaultRunnerConfig());
Expand Down Expand Up @@ -133,14 +147,10 @@ function getPlatformSpecificString(platform) {
return platformRevertString;
}

function determineConfiguration() {
if (program.configuration) {
return program.configuration;
} else if (_.size(config.configurations) === 1) {
function getDefaultConfiguration() {
if (_.size(config.configurations) === 1) {
return _.keys(config.configurations)[0];
} else {
throw new Error(`Cannot determine which configuration to use. use --configuration to choose one of the following:
${Object.keys(config.configurations)}`);
}
}


1 change: 1 addition & 0 deletions detox/src/errors/CustomError.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class CustomError extends Error {
Object.defineProperty(this, "name", {
value: this.constructor.name
});
Error.stackTraceLimit = 0;
Error.captureStackTrace(this, this.constructor);
}
}
Expand Down

0 comments on commit f90eeb0

Please sign in to comment.