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

Add CLI parameter for overriding device name #878

Merged
merged 3 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
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
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.')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'd forgotten about that. Done, thanks.

.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 [email protected] and will be removed in 9.0.0.

### build
Expand Down