From 5a605103e10937ea08b228226ad6d062794e7477 Mon Sep 17 00:00:00 2001 From: Robbie McCorkell Date: Tue, 7 Aug 2018 14:56:09 +0100 Subject: [PATCH 1/3] add device-name cli option --- detox/local-cli/detox-test.js | 5 ++++- detox/src/index.js | 6 ++++++ detox/src/index.test.js | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/detox/local-cli/detox-test.js b/detox/local-cli/detox-test.js index dbbab72cbe..670f72b4fe 100644 --- a/detox/local-cli/detox-test.js +++ b/detox/local-cli/detox-test.js @@ -45,6 +45,8 @@ program '[Android Only] Launch Emulator in headless mode. Useful when running on CI.') .option('-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)', 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); @@ -120,7 +122,7 @@ function runMocha() { 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'}); @@ -144,6 +146,7 @@ function runJest() { recordLogs: program.recordLogs, takeScreenshots: program.takeScreenshots, recordVideos: program.recordVideos, + deviceName: program.deviceName }; console.log(printEnvironmentVariables(detoxEnvironmentVariables) + command); diff --git a/detox/src/index.js b/detox/src/index.js index d27b562b46..ce59e87904 100644 --- a/detox/src/index.js +++ b/detox/src/index.js @@ -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] @@ -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(); } diff --git a/detox/src/index.test.js b/detox/src/index.test.js index ba64154e56..5ea30b6fad 100644 --- a/detox/src/index.test.js +++ b/detox/src/index.test.js @@ -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; From 8f2007c5240a611a6528f2b11c215bc2d2573457 Mon Sep 17 00:00:00 2001 From: Robbie McCorkell Date: Tue, 7 Aug 2018 18:01:47 +0100 Subject: [PATCH 2/3] create argument for mocha bin --- detox/local-cli/detox-test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/detox/local-cli/detox-test.js b/detox/local-cli/detox-test.js index 670f72b4fe..a6fe59a13c 100644 --- a/detox/local-cli/detox-test.js +++ b/detox/local-cli/detox-test.js @@ -117,6 +117,7 @@ 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'); From c9eb32d81d73468056a26a8701cbb166fca22326 Mon Sep 17 00:00:00 2001 From: Robbie McCorkell Date: Thu, 9 Aug 2018 09:14:42 +0100 Subject: [PATCH 3/3] update docs --- docs/APIRef.DetoxCLI.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/APIRef.DetoxCLI.md b/docs/APIRef.DetoxCLI.md index 39050e5956..0f1a49b731 100644 --- a/docs/APIRef.DetoxCLI.md +++ b/docs/APIRef.DetoxCLI.md @@ -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