Skip to content

Commit

Permalink
#98 (allow absolute app path) - done
Browse files Browse the repository at this point in the history
  • Loading branch information
silyevsk committed Nov 13, 2017
1 parent 7b10cab commit 564f1ae
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,4 @@ examples/demo-native-ios/ModuleCache

yarn.lock
detox/ios_src
package-lock.json
22 changes: 21 additions & 1 deletion detox/src/configurations.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -165,5 +184,6 @@ module.exports = {
invalidOneDeviceTypeEmulatorNoSession,
sessionPerConfiguration,
sessionInCommonAndInConfiguration,
validOneEmulator
validOneEmulator,
pathsTests
};
4 changes: 4 additions & 0 deletions detox/src/devices/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 29 additions & 4 deletions detox/src/devices/Device.test.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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`);
});
});

0 comments on commit 564f1ae

Please sign in to comment.