Skip to content

Commit

Permalink
feat: add CLI parameter -n, --device-name for overriding device name (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiemccorkell authored and noomorph committed Aug 9, 2018
1 parent 2b200c8 commit 6d4698e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
6 changes: 5 additions & 1 deletion detox/local-cli/detox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ program
'[Android Only] Launch Emulator in headless mode. Useful when running on CI.')
.option('-w, --workers <n>',
'[iOS Only] Specifies number of workers the test runner should spawn, requires a test runner with parallel execution support (Detox CLI currently supports Jest)', 1)
.option('-n, --device-name [name]',
'Override the device name specified in a configuration. Useful for running a single build configuration on multiple devices.')
.parse(process.argv);

program.artifactsLocation = buildDefaultArtifactsRootDirpath(program.configuration, program.artifactsLocation);
Expand Down Expand Up @@ -115,12 +117,13 @@ function runMocha() {
const videos = program.recordVideos ? `--record-videos ${program.recordVideos}` : '';
const headless = program.headless ? `--headless` : '';
const color = program.color ? '' : '--no-colors';
const deviceName = program.deviceName ? `--device-name "${program.deviceName}"` : '';

const debugSynchronization = program.debugSynchronization ? `--debug-synchronization ${program.debugSynchronization}` : '';
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}`;
`${logs} ${screenshots} ${videos} ${artifactsLocation} ${deviceName}`;

console.log(command);
cp.execSync(command, {stdio: 'inherit'});
Expand All @@ -144,6 +147,7 @@ function runJest() {
recordLogs: program.recordLogs,
takeScreenshots: program.takeScreenshots,
recordVideos: program.recordVideos,
deviceName: program.deviceName
};

console.log(printEnvironmentVariables(detoxEnvironmentVariables) + command);
Expand Down
6 changes: 6 additions & 0 deletions detox/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let detox;

function getDeviceConfig(configurations) {
const configurationName = argparse.getArgValue('configuration');
const deviceOverride = argparse.getArgValue('device-name');

const deviceConfig = (!configurationName && _.size(configurations) === 1)
? _.values(configurations)[0]
Expand All @@ -21,6 +22,11 @@ function getDeviceConfig(configurations) {
throw new Error(`Cannot determine which configuration to use. use --configuration to choose one of the following:
${Object.keys(configurations)}`);
}

if (deviceOverride) {
deviceConfig.name = deviceOverride;
}

if (!deviceConfig.type) {
configuration.throwOnEmptyType();
}
Expand Down
17 changes: 17 additions & 0 deletions detox/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ describe('index', () => {
expect(exception).toBeDefined();
});

it(`constructs detox with device name passed in '--device-name' cli value`, async () => {
process.env.deviceName = 'iPhone X';
const Detox = require('./Detox');

await detox.init(schemes.validOneDeviceNoSession);

const expectedConfig = {
...schemes.validOneDeviceNoSession.configurations['ios.sim.release'],
name: 'iPhone X'
}

expect(Detox).toHaveBeenCalledWith({
deviceConfig: expectedConfig,
session: undefined,
});
});

it(`throws if a device has no name`, async () => {
let exception = undefined;

Expand Down
2 changes: 1 addition & 1 deletion docs/APIRef.DetoxCLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Initiating your test suite
| -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` |
| -H, --headless | [Android Only] Launch Emulator in headless mode. Useful when running on CI. |
| -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.
### build
Expand Down

0 comments on commit 6d4698e

Please sign in to comment.