Skip to content

Commit 6d4698e

Browse files
robbiemccorkellnoomorph
authored andcommitted
feat: add CLI parameter -n, --device-name for overriding device name (#878)
1 parent 2b200c8 commit 6d4698e

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

detox/local-cli/detox-test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ program
4545
'[Android Only] Launch Emulator in headless mode. Useful when running on CI.')
4646
.option('-w, --workers <n>',
4747
'[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)
48+
.option('-n, --device-name [name]',
49+
'Override the device name specified in a configuration. Useful for running a single build configuration on multiple devices.')
4850
.parse(process.argv);
4951

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

119122
const debugSynchronization = program.debugSynchronization ? `--debug-synchronization ${program.debugSynchronization}` : '';
120123
const binPath = path.join('node_modules', '.bin', 'mocha');
121124
const command = `${binPath} ${testFolder} ${configFile} ${configuration} ${loglevel} ${color} ` +
122125
`${cleanup} ${reuse} ${debugSynchronization} ${platformString} ${headless} ` +
123-
`${logs} ${screenshots} ${videos} ${artifactsLocation}`;
126+
`${logs} ${screenshots} ${videos} ${artifactsLocation} ${deviceName}`;
124127

125128
console.log(command);
126129
cp.execSync(command, {stdio: 'inherit'});
@@ -144,6 +147,7 @@ function runJest() {
144147
recordLogs: program.recordLogs,
145148
takeScreenshots: program.takeScreenshots,
146149
recordVideos: program.recordVideos,
150+
deviceName: program.deviceName
147151
};
148152

149153
console.log(printEnvironmentVariables(detoxEnvironmentVariables) + command);

detox/src/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ let detox;
1212

1313
function getDeviceConfig(configurations) {
1414
const configurationName = argparse.getArgValue('configuration');
15+
const deviceOverride = argparse.getArgValue('device-name');
1516

1617
const deviceConfig = (!configurationName && _.size(configurations) === 1)
1718
? _.values(configurations)[0]
@@ -21,6 +22,11 @@ function getDeviceConfig(configurations) {
2122
throw new Error(`Cannot determine which configuration to use. use --configuration to choose one of the following:
2223
${Object.keys(configurations)}`);
2324
}
25+
26+
if (deviceOverride) {
27+
deviceConfig.name = deviceOverride;
28+
}
29+
2430
if (!deviceConfig.type) {
2531
configuration.throwOnEmptyType();
2632
}

detox/src/index.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ describe('index', () => {
9797
expect(exception).toBeDefined();
9898
});
9999

100+
it(`constructs detox with device name passed in '--device-name' cli value`, async () => {
101+
process.env.deviceName = 'iPhone X';
102+
const Detox = require('./Detox');
103+
104+
await detox.init(schemes.validOneDeviceNoSession);
105+
106+
const expectedConfig = {
107+
...schemes.validOneDeviceNoSession.configurations['ios.sim.release'],
108+
name: 'iPhone X'
109+
}
110+
111+
expect(Detox).toHaveBeenCalledWith({
112+
deviceConfig: expectedConfig,
113+
session: undefined,
114+
});
115+
});
116+
100117
it(`throws if a device has no name`, async () => {
101118
let exception = undefined;
102119

docs/APIRef.DetoxCLI.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Initiating your test suite
5959
| -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` |
6060
| -H, --headless | [Android Only] Launch Emulator in headless mode. Useful when running on CI. |
6161
| -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) |
62-
62+
| -n, --device-name [name] | Override the device name specified in a configuration. Useful for running a single build configuration on multiple devices. |
6363
> NOTE: such log levels as `silly` and `wss` are deprecated since [email protected] and will be removed in 9.0.0.
6464
6565
### build

0 commit comments

Comments
 (0)