From 564f1ae2e91c9ebfa45a58ea39c170eb28d7d190 Mon Sep 17 00:00:00 2001 From: Sergey Ilyevsky Date: Mon, 13 Nov 2017 14:19:53 +0200 Subject: [PATCH] #98 (allow absolute app path) - done --- .gitignore | 1 + detox/src/configurations.mock.js | 22 ++++++++++++++++++++- detox/src/devices/Device.js | 4 ++++ detox/src/devices/Device.test.js | 33 ++++++++++++++++++++++++++++---- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index b254816a3f..b6075e9f2f 100644 --- a/.gitignore +++ b/.gitignore @@ -220,3 +220,4 @@ examples/demo-native-ios/ModuleCache yarn.lock detox/ios_src +package-lock.json diff --git a/detox/src/configurations.mock.js b/detox/src/configurations.mock.js index b126a34fce..39cdb9b151 100644 --- a/detox/src/configurations.mock.js +++ b/detox/src/configurations.mock.js @@ -78,6 +78,25 @@ const validOneDeviceAndSession = { } }; +const pathsTests = { + "session": { + "server": "ws://localhost:8099", + "sessionId": "test" + }, + "configurations": { + "absolutePath": { + "binaryPath": "/tmp/abcdef/123", + "type": "ios.simulator", + "name": "iPhone 7 Plus, iOS 10.2" + }, + "relativePath": { + "binaryPath": "abcdef/123", + "type": "ios.simulator", + "name": "iPhone 7 Plus, iOS 10.2" + } + } +}; + const invalidSessionNoSessionId = { "session": { "server": "ws://localhost:8099" @@ -165,5 +184,6 @@ module.exports = { invalidOneDeviceTypeEmulatorNoSession, sessionPerConfiguration, sessionInCommonAndInConfiguration, - validOneEmulator + validOneEmulator, + pathsTests }; diff --git a/detox/src/devices/Device.js b/detox/src/devices/Device.js index 4c137d9488..0f39d9c013 100644 --- a/detox/src/devices/Device.js +++ b/detox/src/devices/Device.js @@ -195,6 +195,10 @@ class Device { } _getAbsolutePath(appPath) { + if(path.isAbsolute(appPath)) { + return appPath; + } + const absPath = path.join(process.cwd(), appPath); if (fs.existsSync(absPath)) { return absPath; diff --git a/detox/src/devices/Device.test.js b/detox/src/devices/Device.test.js index 1f56255228..95f2d756b0 100644 --- a/detox/src/devices/Device.test.js +++ b/detox/src/devices/Device.test.js @@ -1,9 +1,11 @@ const _ = require('lodash'); -const validScheme = require('../configurations.mock').validOneDeviceAndSession; -const validIosNoneScheme = require('../configurations.mock').validOneIosNoneDeviceNoSession; +const configurationsMock = require('../configurations.mock'); -const invalidDeviceNoBinary = require('../configurations.mock').invalidDeviceNoBinary; -const invalidDeviceNoDeviceName = require('../configurations.mock').invalidDeviceNoDeviceName; +const validScheme = configurationsMock.validOneDeviceAndSession; +const validIosNoneScheme = configurationsMock.validOneIosNoneDeviceNoSession; + +const invalidDeviceNoBinary = configurationsMock.invalidDeviceNoBinary; +const invalidDeviceNoDeviceName = configurationsMock.invalidDeviceNoDeviceName; describe('Device', () => { let fs; @@ -512,4 +514,27 @@ describe('Device', () => { expect(device.deviceDriver.sendUserNotification).toHaveBeenCalledTimes(0); }); + + async function launchAndTestBinaryPath(configuration) { + const scheme = configurationsMock.pathsTests; + const device = new Device(scheme.configurations[configuration], scheme.session, new DeviceDriverBase(client)); + fs.existsSync.mockReturnValue(true); + device.deviceDriver.defaultLaunchArgsPrefix.mockReturnValue('-'); + device.deviceDriver.acquireFreeDevice.mockReturnValue('mockDeviceId'); + + await device.prepare(); + await device.launchApp(); + + return device.deviceDriver.installApp.mock.calls[0][1]; + } + + it(`should accept absolute path for binary`, async () => { + const actualPath = await launchAndTestBinaryPath('absolutePath'); + expect(actualPath).toEqual('/tmp/abcdef/123'); + }); + + it(`should accept relative path for binary`, async () => { + const actualPath = await launchAndTestBinaryPath('relativePath'); + expect(actualPath).toEqual(`${process.cwd()}/abcdef/123`); + }); });