From 3c0990453954dc7c1e1274b0a8ca85d8be169f19 Mon Sep 17 00:00:00 2001 From: wixmobile Date: Sun, 23 May 2021 07:33:53 -0400 Subject: [PATCH 1/5] Publish 18.14.0 [ci skip] --- detox/package.json | 2 +- detox/test/package.json | 4 ++-- examples/demo-native-android/package.json | 4 ++-- examples/demo-native-ios/package.json | 4 ++-- examples/demo-react-native-detox-instruments/package.json | 4 ++-- examples/demo-react-native-jest/package.json | 4 ++-- examples/demo-react-native/package.json | 4 ++-- lerna.json | 2 +- package.json | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/detox/package.json b/detox/package.json index cf02a0a3cb..6d14288b3d 100644 --- a/detox/package.json +++ b/detox/package.json @@ -1,7 +1,7 @@ { "name": "detox", "description": "E2E tests and automation for mobile", - "version": "18.13.0", + "version": "18.14.0", "bin": { "detox": "local-cli/cli.js" }, diff --git a/detox/test/package.json b/detox/test/package.json index 26d3c11bf0..9d9db2b310 100644 --- a/detox/test/package.json +++ b/detox/test/package.json @@ -1,6 +1,6 @@ { "name": "detox-test", - "version": "18.13.0", + "version": "18.14.0", "private": true, "engines": { "node": ">=8.3.0" @@ -38,7 +38,7 @@ "devDependencies": { "@babel/core": "^7.8.7", "@types/node": "^14.14.20", - "detox": "^18.13.0", + "detox": "^18.14.0", "dtslint": "^4.0.6", "express": "^4.15.3", "jest": "^26.5.0", diff --git a/examples/demo-native-android/package.json b/examples/demo-native-android/package.json index 714c25a89c..5742efb553 100644 --- a/examples/demo-native-android/package.json +++ b/examples/demo-native-android/package.json @@ -1,6 +1,6 @@ { "name": "detox-demo-native-android", - "version": "18.13.0", + "version": "18.14.0", "private": true, "scripts": { "packager": "react-native start", @@ -8,7 +8,7 @@ "e2e": "mocha e2e --opts ./e2e/mocha.opts" }, "devDependencies": { - "detox": "^18.13.0", + "detox": "^18.14.0", "mocha": "^6.1.3" }, "detox": {} diff --git a/examples/demo-native-ios/package.json b/examples/demo-native-ios/package.json index 649af7199e..1ea91c54f5 100644 --- a/examples/demo-native-ios/package.json +++ b/examples/demo-native-ios/package.json @@ -1,9 +1,9 @@ { "name": "detox-demo-native-ios", - "version": "18.13.0", + "version": "18.14.0", "private": true, "devDependencies": { - "detox": "^18.13.0", + "detox": "^18.14.0", "mocha": "^6.1.3" }, "detox": { diff --git a/examples/demo-react-native-detox-instruments/package.json b/examples/demo-react-native-detox-instruments/package.json index 16a9ae5064..7e4e7a7f15 100644 --- a/examples/demo-react-native-detox-instruments/package.json +++ b/examples/demo-react-native-detox-instruments/package.json @@ -1,10 +1,10 @@ { "name": "demo-react-native-detox-instruments", - "version": "18.13.0", + "version": "18.14.0", "private": true, "scripts": {}, "devDependencies": { - "detox": "^18.13.0", + "detox": "^18.14.0", "mocha": "6.x.x" }, "detox": { diff --git a/examples/demo-react-native-jest/package.json b/examples/demo-react-native-jest/package.json index 307a93083a..06cb47549b 100644 --- a/examples/demo-react-native-jest/package.json +++ b/examples/demo-react-native-jest/package.json @@ -1,6 +1,6 @@ { "name": "demo-react-native-jest", - "version": "18.13.0", + "version": "18.14.0", "private": true, "scripts": { "test:ios-release": "detox test --configuration ios.sim.release -l verbose", @@ -10,7 +10,7 @@ }, "devDependencies": { "@types/jest": "^26.0.19", - "detox": "^18.13.0", + "detox": "^18.14.0", "jest": "^26.5.0", "jest-circus": "^26.5.2", "sanitize-filename": "^1.6.1", diff --git a/examples/demo-react-native/package.json b/examples/demo-react-native/package.json index 8dcce4fcf2..dc86c10335 100644 --- a/examples/demo-react-native/package.json +++ b/examples/demo-react-native/package.json @@ -1,6 +1,6 @@ { "name": "example", - "version": "18.13.0", + "version": "18.14.0", "private": true, "scripts": { "start": "react-native start", @@ -25,7 +25,7 @@ }, "devDependencies": { "@types/mocha": "^8.2.0", - "detox": "^18.13.0", + "detox": "^18.14.0", "mocha": "^6.1.3", "ts-node": "^9.1.1", "typescript": "^4.1.3" diff --git a/lerna.json b/lerna.json index 874dcd9e16..b18b2deb15 100644 --- a/lerna.json +++ b/lerna.json @@ -13,7 +13,7 @@ "generation", "." ], - "version": "18.13.0", + "version": "18.14.0", "npmClient": "npm", "command": { "publish": { diff --git a/package.json b/package.json index d4a2ac201b..4c71bcd1d3 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,5 @@ "semver": "5.x.x", "shell-utils": "1.x.x" }, - "version": "18.13.0" + "version": "18.14.0" } From 1cdb50746643a68af29c7dc199050b75573dcd33 Mon Sep 17 00:00:00 2001 From: d4vidi Date: Sun, 23 May 2021 16:42:27 +0300 Subject: [PATCH 2/5] Make DeviceRegistry DB-like: hold ids+data instead of objects (#2778) --- detox/src/devices/DeviceRegistry.js | 113 +++++++------ detox/src/devices/DeviceRegistry.test.js | 156 ++++++------------ .../android/genycloud/GenyCloudDriver.js | 12 +- .../android/genycloud/GenyCloudDriver.test.js | 36 ++-- .../genycloud/GenyCloudInstanceHandle.js | 8 - .../helpers/GenyCloudInstanceLauncher.js | 14 +- .../helpers/GenyCloudInstanceLauncher.test.js | 13 +- .../services/GenyInstanceLookupService.js | 4 +- .../GenyInstanceLookupService.test.js | 3 +- .../devices/drivers/ios/SimulatorDriver.js | 5 +- .../drivers/ios/SimulatorDriver.test.js | 51 +++++- 11 files changed, 207 insertions(+), 208 deletions(-) delete mode 100644 detox/src/devices/drivers/android/genycloud/GenyCloudInstanceHandle.js diff --git a/detox/src/devices/DeviceRegistry.js b/detox/src/devices/DeviceRegistry.js index 02f6783d74..cd5a253b83 100644 --- a/detox/src/devices/DeviceRegistry.js +++ b/detox/src/devices/DeviceRegistry.js @@ -4,25 +4,35 @@ const fs = require('fs-extra'); const ExclusiveLockfile = require('../utils/ExclusiveLockfile'); const safeAsync = require('../utils/safeAsync'); -const getDeviceEqualsFn = (deviceHandle) => (otherDeviceHandle) => _.isEqual(otherDeviceHandle, deviceHandle); -const getDeviceDifferFn = (deviceHandle) => (otherDeviceHandle) => !_.isEqual(otherDeviceHandle, deviceHandle); const readOptions = { encoding: 'utf8', }; -class DeviceHandlesList { +const FIELD_NAME_ID = 'id'; +const FIELD_NAME_DATA = 'data'; + +class DevicesList { constructor(devices) { - this.rawDevices = Object.freeze(devices); + this._devices = Object.freeze(devices); + } + + /** + * @returns {{id: string, data: *?}[]} + */ + get rawDevices() { + return this._devices; } - includes(deviceHandle) { - return DeviceHandlesList._includes(deviceHandle, this.rawDevices); + /** + * @param {string} deviceId + * @returns {boolean} + */ + includes(deviceId) { + return DevicesList._includes(deviceId, this._devices); } - static _includes(deviceHandle, devices) { - const rawDeviceHandle = getRawDeviceHandle(deviceHandle); - const deviceEqualsFn = getDeviceEqualsFn(rawDeviceHandle); - return !!_.find(devices, deviceEqualsFn); + static _includes(deviceId, devices) { + return _.some(devices, [FIELD_NAME_ID, deviceId]); } } @@ -52,65 +62,66 @@ class DeviceRegistry { } /*** - * @param {string|Object|Function} getDeviceHandle + * @param {string|Function} getDeviceId + * @param {*?} data * @returns {Promise} */ - async allocateDevice(getDeviceHandle) { + async allocateDevice(getDeviceId, data) { return this._lockfile.exclusively(async () => { - const deviceHandle = await safeAsync(getDeviceHandle); - this._toggleDeviceStatus(deviceHandle, true); - return deviceHandle; + const deviceId = await safeAsync(getDeviceId); + this._registerDevice(deviceId, data); + return deviceId; }); } /*** - * @param {string|Object|Function} getDeviceHandle - * @returns {void} + * @param {string|Function} getDeviceId + * @returns {Promise} */ - async disposeDevice(getDeviceHandle) { + async disposeDevice(getDeviceId) { await this._lockfile.exclusively(async () => { - const deviceId = await safeAsync(getDeviceHandle); + const deviceId = await safeAsync(getDeviceId); if (deviceId) { - this._toggleDeviceStatus(deviceId, false); + this._unregisterDevice(deviceId); } }); } /*** - * @param {Object} deviceHandle + * @param {string} deviceId * @returns {boolean} */ - includes(deviceHandle) { + includes(deviceId) { const devices = this._lockfile.read(); - return DeviceHandlesList._includes(deviceHandle, devices); + return DevicesList._includes(deviceId, devices); } /*** - * @returns {DeviceHandlesList} + * @returns {DevicesList} + */ + getRegisteredDevices() { + const devices = this._lockfile.read(); + return new DevicesList(devices); + } + + /*** + * @returns {DevicesList} */ async readRegisteredDevices() { let result = null; await this._lockfile.exclusively(() => { - result = new DeviceHandlesList(this._lockfile.read()); + result = this.getRegisteredDevices(); }) return result; } /*** - * @returns {DeviceHandlesList} - */ - getRegisteredDevices() { - const deviceHandles = this._lockfile.read(); - return new DeviceHandlesList(deviceHandles); - } - - /*** - * @returns {DeviceHandlesList} + * @returns {DevicesList} */ readRegisteredDevicesUNSAFE() { const contents = fs.readFileSync(this._lockfilePath, readOptions); const devices = JSON.parse(contents); - return new DeviceHandlesList(devices); + return new DevicesList(devices); } /*** @@ -120,16 +131,30 @@ class DeviceRegistry { return []; } - /*** + /** + * @private + */ + _registerDevice(deviceId, data) { + const state = this._lockfile.read(); + let newState = _.reject(state, [FIELD_NAME_ID, deviceId]); + + const device = {}; + device[FIELD_NAME_ID] = deviceId; + + if (data) { + device[FIELD_NAME_DATA] = data; + } + + newState = _.concat(newState, device); + this._lockfile.write(newState); + } + + /** * @private */ - _toggleDeviceStatus(deviceHandle, busy) { - const rawDeviceHandle = getRawDeviceHandle(deviceHandle); - const deviceDifferFn = getDeviceDifferFn(rawDeviceHandle); + _unregisterDevice(deviceId) { const state = this._lockfile.read(); - const newState = busy - ? _.concat(state, rawDeviceHandle) - : _.filter(state, deviceDifferFn); + const newState = _.reject(state, [FIELD_NAME_ID, deviceId]); this._lockfile.write(newState); } @@ -146,8 +171,4 @@ class DeviceRegistry { } } -function getRawDeviceHandle(deviceHandle) { - return JSON.parse(JSON.stringify(deviceHandle)); -} - module.exports = DeviceRegistry; diff --git a/detox/src/devices/DeviceRegistry.test.js b/detox/src/devices/DeviceRegistry.test.js index 39e33c4021..f65e210493 100644 --- a/detox/src/devices/DeviceRegistry.test.js +++ b/detox/src/devices/DeviceRegistry.test.js @@ -2,32 +2,9 @@ const fs = require('fs-extra'); const tempfile = require('tempfile'); const environment = require('../utils/environment'); -const deviceHandle = 'emulator-5554'; - -const deviceHandleAsRawObj = { - type: 'mocked-device-type', - adbName: 'emulator-5556', -}; -const deviceHandleAsObj = { - ...deviceHandleAsRawObj, - mockFn: () => 'mock-fn-result', -}; - -class DeviceHandle { - constructor() { - this.type = 'mocked-device-type'; - this.adbName = 'localhost:11111'; - } - - mockFunc() { - return 'mocked-func-result'; - } -} -const deviceHandleAsClassInstance = new DeviceHandle(); -const deviceHandleInstanceRaw = { - type: 'mocked-device-type', - adbName: 'localhost:11111', -} +const deviceId = 'emulator-5554'; +const deviceId2 = 'emulator-5556'; +const mockData = { mock: 'data' }; describe('DeviceRegistry', () => { let DeviceRegistry; @@ -46,14 +23,14 @@ describe('DeviceRegistry', () => { await fs.remove(lockfilePath); }); - async function allocateDevice(deviceHandle) { - return registry.allocateDevice(() => deviceHandle); + async function allocateDevice(deviceId, data) { + return registry.allocateDevice(() => deviceId, data); } - async function checkDeviceRegisteredAndDispose(deviceHandle) { + async function checkDeviceRegisteredAndDispose(deviceId) { return registry.disposeDevice(async () => { - expect(registry.includes(deviceHandle)).toBe(true); - return deviceHandle; + expect(registry.includes(deviceId)).toBe(true); + return deviceId; }); } @@ -61,34 +38,34 @@ describe('DeviceRegistry', () => { return registry.disposeDevice(() => deviceHandle); } - async function expectDeviceNotRegistered(deviceHandle) { + async function expectDeviceNotRegistered(deviceId) { return registry.allocateDevice(async () => { - expect(registry.includes(deviceHandle)).toBe(false); + expect(registry.includes(deviceId)).toBe(false); throw new Error('ignored'); // So it wouldn't really allocate anything }).catch((e) => { if (e.message !== 'ignored') throw e }); } - function expectIncludedInDevicesList(deviceHandle) { + function expectIncludedInDevicesList(deviceId) { return registry.allocateDevice(() => { const registeredDevices = registry.getRegisteredDevices(); - expect(registeredDevices.includes(deviceHandle)).toEqual(true); + expect(registeredDevices.includes(deviceId)).toEqual(true); throw new Error('ignored'); // So it wouldn't really allocate anything }).catch((e) => { if (e.message !== 'ignored') throw e }); } - function expectDevicesListEquals(rawDevicesHandles) { + function expectDevicesListEquals(rawDevices) { return registry.allocateDevice(() => { const registeredDevices = registry.getRegisteredDevices(); - expect(registeredDevices.rawDevices).toStrictEqual(rawDevicesHandles); + expect(registeredDevices.rawDevices).toStrictEqual(rawDevices); throw new Error('ignored'); // So it wouldn't really allocate anything }).catch((e) => { if (e.message !== 'ignored') throw e }); } - async function expectIncludedInReadDevicesList(deviceHandle) { + async function expectIncludedInReadDevicesList(deviceId) { const registeredDevices = await registry.readRegisteredDevices(); - expect(registeredDevices.includes(deviceHandle)).toEqual(true); + expect(registeredDevices.includes(deviceId)).toEqual(true); } async function expectNotIncludedInReadDevicesList(deviceHandle) { @@ -118,112 +95,81 @@ describe('DeviceRegistry', () => { expect(() => registry.getRegisteredDevices()).toThrowError(); it('should be able to tell whether a device is registered - for query and disposal', async () => { - await allocateDevice(deviceHandle); - await checkDeviceRegisteredAndDispose(deviceHandle); - await expectDeviceNotRegistered(deviceHandle); - }); - - it('should be able to tell whether a device is registered, given objects as handles', async () => { - await allocateDevice(deviceHandleAsObj); - await checkDeviceRegisteredAndDispose(deviceHandleAsObj); - await expectDeviceNotRegistered(deviceHandleAsObj); + await allocateDevice(deviceId); + await checkDeviceRegisteredAndDispose(deviceId); + await expectDeviceNotRegistered(deviceId); }); - it('should be able to tell whether a device is registered, given class instances as handles', async () => { - await allocateDevice(deviceHandleAsClassInstance); - await checkDeviceRegisteredAndDispose(deviceHandleAsClassInstance); - await expectDeviceNotRegistered(deviceHandleAsClassInstance); + it('should be able to tell whether a device is registered, even with custom data associated with it', async () => { + await allocateDevice(deviceId, { mock: 'data' }); + await checkDeviceRegisteredAndDispose(deviceId); + await expectDeviceNotRegistered(deviceId); }); it('should throw on attempt of checking whether a device is registered outside of allocation/disposal context', async () => { assertForbiddenOutOfContextRegistryQuery(); - await allocateDevice(deviceHandle); + await allocateDevice(deviceId); assertForbiddenOutOfContextRegistryQuery(); }); it('should be able to in-context get a valid list of registered devices, and query its content', async () => { - await allocateDevice(deviceHandle); - await allocateDevice(deviceHandleAsObj); - await allocateDevice(deviceHandleAsClassInstance); - await expectIncludedInDevicesList(deviceHandle); - await expectIncludedInDevicesList(deviceHandleAsObj); - await expectIncludedInDevicesList(deviceHandleAsClassInstance); + await allocateDevice(deviceId); + await allocateDevice(deviceId2, { mock: 'data' }); + await expectIncludedInDevicesList(deviceId); + await expectIncludedInDevicesList(deviceId2); }); - it('should be able to in-context-get a valid list of (raw) registered devices as an array', async () => { - const expectedrawDevicesList = [ - deviceHandle, - deviceHandleAsRawObj, - deviceHandleInstanceRaw, + it('should be able to in-context-get a valid list of registered devices as a raw objects array, also containing custom data', async () => { + const expectedDevicesList = [ + { id: deviceId, }, + { id: deviceId2, data: mockData, }, ]; - await allocateDevice(deviceHandle); - await allocateDevice(deviceHandleAsObj); - await allocateDevice(deviceHandleAsClassInstance); - await expectDevicesListEquals(expectedrawDevicesList); + await allocateDevice(deviceId); + await allocateDevice(deviceId2, mockData); + await expectDevicesListEquals(expectedDevicesList); }); it('should throw on an attempt of in-context getting registered devices list when outside of allocation/disposal context', async () => { assertForbiddenOutOfContextDeviceListQuery(); - await allocateDevice(deviceHandle); + await allocateDevice(deviceId); assertForbiddenOutOfContextDeviceListQuery(); }); it('should be able to out-of-context read a valid list of registered devices and query its content', async () => { - await allocateDevice(deviceHandle); - await allocateDevice(deviceHandleAsObj); - await allocateDevice(deviceHandleAsClassInstance); - await expectIncludedInReadDevicesList(deviceHandle); - await expectIncludedInReadDevicesList(deviceHandleAsObj); + await allocateDevice(deviceId); + await allocateDevice(deviceId2, { mock: 'data' }); + await expectIncludedInReadDevicesList(deviceId); + await expectIncludedInReadDevicesList(deviceId2); }); - it('should be able to out-of-context-read a valid list of (raw) registered devices as an array', async () => { + it('should be able to out-of-context-read a valid list of registered devices as a raw objects array, also containing custom data', async () => { const expectedDevicesList = [ - deviceHandle, - deviceHandleAsRawObj, - deviceHandleInstanceRaw, + { id: deviceId, }, + { id: deviceId2, data: mockData, }, ]; - await allocateDevice(deviceHandle); - await allocateDevice(deviceHandleAsObj); - await allocateDevice(deviceHandleAsClassInstance); + await allocateDevice(deviceId); + await allocateDevice(deviceId2, mockData); await expectReadDevicesListEquals(expectedDevicesList); }); it('should allow for UNSAFE (non-concurrent) reading of registered devices list, even outside of allocation/disposal context', async () => { const expectedDevicesList = [ - deviceHandle, - deviceHandleAsRawObj, - deviceHandleInstanceRaw, + { id: deviceId, }, + { id: deviceId2, data: mockData, }, ]; - await allocateDevice(deviceHandle); - await allocateDevice(deviceHandleAsObj); - await allocateDevice(deviceHandleAsClassInstance); + await allocateDevice(deviceId); + await allocateDevice(deviceId2, mockData); - await expectIncludedInUnsafeDevicesList(deviceHandle); - await expectIncludedInUnsafeDevicesList(deviceHandleAsObj); - await expectIncludedInUnsafeDevicesList(deviceHandleAsClassInstance); + await expectIncludedInUnsafeDevicesList(deviceId); + await expectIncludedInUnsafeDevicesList(deviceId2); await expectedUnsafeDevicesListEquals(expectedDevicesList); }); - it('should be able to dispose devices of all types', async () => { - await allocateDevice(deviceHandle); - await allocateDevice(deviceHandleAsObj); - await allocateDevice(deviceHandleAsClassInstance); - - await disposeDevice(deviceHandle); - await expectNotIncludedInReadDevicesList(deviceHandle); - - await disposeDevice(deviceHandleAsObj); - await expectNotIncludedInReadDevicesList(deviceHandleAsObj); - - await disposeDevice(deviceHandleAsClassInstance); - await expectNotIncludedInReadDevicesList(deviceHandleAsClassInstance); - }); - it('should not fail when there were no actual device to dispose', async () => { await expect(disposeDevice(undefined)).resolves.not.toThrowError(); }); diff --git a/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.js b/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.js index f2f4554aeb..e9298add36 100644 --- a/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.js +++ b/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.js @@ -116,7 +116,8 @@ class GenyCloudDriver extends AndroidDriver { onSignalExit((code, signal) => { if (signal) { const deviceCleanupRegistry = GenyDeviceRegistryFactory.forGlobalShutdown(); - const { rawDevices: instanceHandles } = deviceCleanupRegistry.readRegisteredDevicesUNSAFE(); + const { rawDevices } = deviceCleanupRegistry.readRegisteredDevicesUNSAFE(); + const instanceHandles = rawDevicesToInstanceHandles(rawDevices); if (instanceHandles.length) { reportGlobalCleanupSummary(instanceHandles); } @@ -126,7 +127,8 @@ class GenyCloudDriver extends AndroidDriver { static async globalCleanup() { const deviceCleanupRegistry = GenyDeviceRegistryFactory.forGlobalShutdown(); - const { rawDevices: instanceHandles } = await deviceCleanupRegistry.readRegisteredDevices(); + const { rawDevices } = await deviceCleanupRegistry.readRegisteredDevices(); + const instanceHandles = rawDevicesToInstanceHandles(rawDevices); if (instanceHandles.length) { const exec = new GenyCloudExec(environment.getGmsaasPath()); const instanceLifecycleService = new InstanceLifecycleService(exec, null); @@ -165,4 +167,10 @@ function reportGlobalCleanupSummary(deletionLeaks) { } } +function rawDevicesToInstanceHandles(rawDevices) { + return rawDevices.map((rawDevice) => ({ + uuid: rawDevice.id, + name: rawDevice.data.name, + })); +} module.exports = GenyCloudDriver; diff --git a/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.test.js b/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.test.js index dc616942b3..8dd4b81074 100644 --- a/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.test.js +++ b/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.test.js @@ -198,10 +198,7 @@ describe('Genymotion-cloud driver', () => { const deviceQuery = aDeviceQuery(); const result = await uut.acquireFreeDevice(deviceQuery); - expect(result).toEqual(expect.objectContaining({ - adbName: instance.adbName, - uuid: instance.uuid, - })); + expect(result).toEqual(instance); expect(recipeQuerying().getRecipeFromQuery).toHaveBeenCalledWith(deviceQuery); expect(instanceAllocation().allocateDevice).toHaveBeenCalledWith(recipe); }); @@ -321,12 +318,16 @@ describe('Genymotion-cloud driver', () => { GenyCloudDriver = require('./GenyCloudDriver'); }); - const aPendingInstanceHandle = (name, uuid) => ({ name, uuid }); + // As typically returned by the DeviceRegistry + const aPendingRawDevice = (name, uuid) => ({ + id: uuid, + data: { name }, + }); describe('global clean-up', () => { - const givenDeletionPendingDevices = (devicesHandles) => deviceCleanupRegistry.readRegisteredDevices.mockResolvedValue({ rawDevices: devicesHandles }); + const givenDeletionPendingDevices = (rawDevices) => deviceCleanupRegistry.readRegisteredDevices.mockResolvedValue({ rawDevices }); const givenNoDeletionPendingDevices = () => givenDeletionPendingDevices([]); - const givenDeletionPendingInstances = (instances) => givenDeletionPendingDevices( _.map(instances, ({ uuid, name }) => ({ uuid, name }) )); + const givenDeletionPendingInstances = (instances) => givenDeletionPendingDevices( _.map(instances, ({ uuid, name }) => aPendingRawDevice(name, uuid)) ); const givenDeletionResult = (deletedInstance) => instanceLifecycleService.deleteInstance.mockResolvedValue(deletedInstance); const anAssertablePendingPromise = () => { @@ -343,11 +344,10 @@ describe('Genymotion-cloud driver', () => { .mockReturnValueOnce(killPromise1) .mockReturnValueOnce(killPromise2); - const deviceHandles = [ - aPendingInstanceHandle('device1', 'uuid1'), - aPendingInstanceHandle('device2', 'uuid2'), - ]; - givenDeletionPendingDevices(deviceHandles); + givenDeletionPendingDevices([ + aPendingRawDevice('device1', 'uuid1'), + aPendingRawDevice('device2', 'uuid2'), + ]); await GenyCloudDriver.globalCleanup(); @@ -364,9 +364,9 @@ describe('Genymotion-cloud driver', () => { .mockRejectedValueOnce(new Error('mock-error2')); givenDeletionPendingDevices([ - aPendingInstanceHandle('failing1', 'uuid1'), - aPendingInstanceHandle('nonfailing', 'uuid'), - aPendingInstanceHandle('failing2', 'uuid2'), + aPendingRawDevice('failing1', 'uuid1'), + aPendingRawDevice('nonfailing', 'uuid'), + aPendingRawDevice('failing2', 'uuid2'), ]); await GenyCloudDriver.globalCleanup(); @@ -414,7 +414,7 @@ describe('Genymotion-cloud driver', () => { describe('global *emergency* clean-up', () => { const signalExitCallback = () => signalExit.mock.calls[0][0]; const invokeExitCallback = (signal = 'SIGINT') => signalExitCallback()(null, signal); - const givenCleanupPendingDevices = (devicesHandles) => deviceCleanupRegistry.readRegisteredDevicesUNSAFE.mockReturnValue({ rawDevices: devicesHandles }); + const givenCleanupPendingDevices = (rawDevices) => deviceCleanupRegistry.readRegisteredDevicesUNSAFE.mockReturnValue({ rawDevices }); const givenNoCleanupPendingDevices = () => givenCleanupPendingDevices([]); it('should register a callback on global init via signal-exit, for an emergency global clean-up', async () => { @@ -425,7 +425,7 @@ describe('Genymotion-cloud driver', () => { it('should warn of leaking instances in signal-exit callback', async () => { givenCleanupPendingDevices([ - aPendingInstanceHandle('aDevice', 'uuid'), + aPendingRawDevice('aDevice', 'uuid'), ]); await GenyCloudDriver.globalInit(); @@ -447,7 +447,7 @@ describe('Genymotion-cloud driver', () => { it('should not warn if called with no signal', async () => { givenCleanupPendingDevices([ - aPendingInstanceHandle('aDevice', 'uuid'), + aPendingRawDevice('aDevice', 'uuid'), ]); await GenyCloudDriver.globalInit(); diff --git a/detox/src/devices/drivers/android/genycloud/GenyCloudInstanceHandle.js b/detox/src/devices/drivers/android/genycloud/GenyCloudInstanceHandle.js deleted file mode 100644 index 3045ef0236..0000000000 --- a/detox/src/devices/drivers/android/genycloud/GenyCloudInstanceHandle.js +++ /dev/null @@ -1,8 +0,0 @@ -class GenyCloudInstanceHandle { - constructor(instance) { - this.uuid = instance.uuid; - this.name = instance.name; - } -} - -module.exports = GenyCloudInstanceHandle; diff --git a/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.js b/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.js index 1557bd854e..1cd8ca4c69 100644 --- a/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.js +++ b/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.js @@ -1,5 +1,4 @@ const AndroidDeviceLauncher = require('../../AndroidDeviceLauncher'); -const GenyCloudInstanceHandle = require('../GenyCloudInstanceHandle'); class GenyCloudInstanceLauncher extends AndroidDeviceLauncher { constructor(instanceLifecycleService, deviceCleanupRegistry, eventEmitter) { @@ -19,17 +18,16 @@ class GenyCloudInstanceLauncher extends AndroidDeviceLauncher { * @returns {Promise} */ async launch(instance) { - const instanceHandle = new GenyCloudInstanceHandle(instance); - await this._deviceCleanupRegistry.allocateDevice(instanceHandle); + await this._deviceCleanupRegistry.allocateDevice(instance.uuid, { name: instance.name }); } async shutdown(instance) { - const instanceHandle = new GenyCloudInstanceHandle(instance); + const { uuid } = instance; - await this._notifyPreShutdown(instance.adbName); - await this._instanceLifecycleService.deleteInstance(instance.uuid); - await this._deviceCleanupRegistry.disposeDevice(instanceHandle); - await this._notifyShutdownCompleted(instance.adbName); + await this._notifyPreShutdown(uuid); + await this._instanceLifecycleService.deleteInstance(uuid); + await this._deviceCleanupRegistry.disposeDevice(uuid); + await this._notifyShutdownCompleted(uuid); } } diff --git a/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.test.js b/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.test.js index 816f7d1d75..0886691a3f 100644 --- a/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.test.js +++ b/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.test.js @@ -34,10 +34,7 @@ describe('Genymotion-Cloud instance launcher', () => { const instance = anInstance(); await uut.launch(instance); - expect(deviceCleanupRegistry.allocateDevice).toHaveBeenCalledWith({ - uuid: instance.uuid, - name: instance.name, - }) + expect(deviceCleanupRegistry.allocateDevice).toHaveBeenCalledWith(instance.uuid, { name: instance.name }); }); }); @@ -58,17 +55,15 @@ describe('Genymotion-Cloud instance launcher', () => { it('should remove the instance from the cleanup registry', async () => { const instance = anInstance(); await uut.shutdown(instance); - expect(deviceCleanupRegistry.disposeDevice).toHaveBeenCalledWith(expect.objectContaining({ - uuid: instance.uuid, - })); + expect(deviceCleanupRegistry.disposeDevice).toHaveBeenCalledWith(instance.uuid); }); it('should emit associated events', async () => { const instance = anInstance(); await uut.shutdown(instance); - expect(eventEmitter.emit).toHaveBeenCalledWith('beforeShutdownDevice', { deviceId: instance.adbName }); - expect(eventEmitter.emit).toHaveBeenCalledWith('shutdownDevice', { deviceId: instance.adbName }); + expect(eventEmitter.emit).toHaveBeenCalledWith('beforeShutdownDevice', { deviceId: instance.uuid }); + expect(eventEmitter.emit).toHaveBeenCalledWith('shutdownDevice', { deviceId: instance.uuid }); }); it('should not emit shutdownDevice prematurely', async () => { diff --git a/detox/src/devices/drivers/android/genycloud/services/GenyInstanceLookupService.js b/detox/src/devices/drivers/android/genycloud/services/GenyInstanceLookupService.js index 394775f8ca..213f482c09 100644 --- a/detox/src/devices/drivers/android/genycloud/services/GenyInstanceLookupService.js +++ b/detox/src/devices/drivers/android/genycloud/services/GenyInstanceLookupService.js @@ -18,11 +18,11 @@ class GenyInstanceLookupService { } async _getRelevantInstances() { - const { rawDevices: takenInstanceUUIDs } = this.deviceRegistry.getRegisteredDevices(); + const takenInstances = this.deviceRegistry.getRegisteredDevices(); const isRelevant = (instance) => (instance.isOnline() || instance.isInitializing()) && this.instanceNaming.isFamilial(instance.name) && - !takenInstanceUUIDs.includes(instance.uuid); + !takenInstances.includes(instance.uuid); const instances = await this._getAllInstances(); return instances.filter(isRelevant); diff --git a/detox/src/devices/drivers/android/genycloud/services/GenyInstanceLookupService.test.js b/detox/src/devices/drivers/android/genycloud/services/GenyInstanceLookupService.test.js index 08ee7260b2..65faf6600a 100644 --- a/detox/src/devices/drivers/android/genycloud/services/GenyInstanceLookupService.test.js +++ b/detox/src/devices/drivers/android/genycloud/services/GenyInstanceLookupService.test.js @@ -44,8 +44,7 @@ describe('Genymotion-Cloud instances lookup service', () => { function givenRegisteredInstances(...instances) { const instanceUUIDs = _.map(instances, 'uuid'); deviceRegistry.getRegisteredDevices.mockReturnValue({ - rawDevices: instanceUUIDs, - includes: instanceUUIDs.includes, + includes: instanceUUIDs.includes.bind(instanceUUIDs), }); } const givenNoRegisteredInstances = () => givenRegisteredInstances([]); diff --git a/detox/src/devices/drivers/ios/SimulatorDriver.js b/detox/src/devices/drivers/ios/SimulatorDriver.js index 73817ddf01..5b6f79083e 100644 --- a/detox/src/devices/drivers/ios/SimulatorDriver.js +++ b/detox/src/devices/drivers/ios/SimulatorDriver.js @@ -10,7 +10,6 @@ const SimulatorLogPlugin = require('../../../artifacts/log/ios/SimulatorLogPlugi const SimulatorRecordVideoPlugin = require('../../../artifacts/video/SimulatorRecordVideoPlugin'); const SimulatorScreenshotPlugin = require('../../../artifacts/screenshot/SimulatorScreenshotPlugin'); const temporaryPath = require('../../../artifacts/utils/temporaryPath'); -const DetoxConfigError = require('../../../errors/DetoxConfigError'); const DetoxRuntimeError = require('../../../errors/DetoxRuntimeError'); const environment = require('../../../utils/environment'); const argparse = require('../../../utils/argparse'); @@ -249,7 +248,8 @@ class SimulatorDriver extends IosDriver { async _groupDevicesByStatus(deviceQuery) { const searchResults = await this._queryDevices(deviceQuery); const { rawDevices: takenDevices } = this.deviceRegistry.getRegisteredDevices(); - const { taken, free } = _.groupBy(searchResults, ({ udid }) => takenDevices.includes(udid) ? 'taken' : 'free'); + const takenUDIDs = _.map(takenDevices, 'id'); + const { taken, free } = _.groupBy(searchResults, ({ udid }) => takenUDIDs.includes(udid) ? 'taken' : 'free'); const targetOS = _.get(taken, '0.os.identifier'); const isMatching = targetOS && { os: { identifier: targetOS } }; @@ -273,7 +273,6 @@ class SimulatorDriver extends IosDriver { `It is advised only to specify a device type, e.g., "iPhone Xʀ" and avoid explicit search by OS version.` }); } - return result; } diff --git a/detox/src/devices/drivers/ios/SimulatorDriver.test.js b/detox/src/devices/drivers/ios/SimulatorDriver.test.js index e5dbcb9aef..04d9c7407a 100644 --- a/detox/src/devices/drivers/ios/SimulatorDriver.test.js +++ b/detox/src/devices/drivers/ios/SimulatorDriver.test.js @@ -120,17 +120,29 @@ describe('IOS simulator driver', () => { }); describe('acquireFreeDevice', () => { + const givenUsedSimulators = (...UDIDs) => { + jest.spyOn(uut.deviceRegistry, 'getRegisteredDevices').mockReturnValue({ + rawDevices: UDIDs.map((UDID) => ({ id: UDID })), // as typically returned by getRegisteredDevices() + includes: UDIDs.includes.bind(UDIDs), + }); + } + const givenNoUsedSimulators = () => givenUsedSimulators(); + const givenSystemDevices = (...deviceSpecs) => uut.applesimutils.list.mockResolvedValue([ ...deviceSpecs ]); + const givenCreatedDeviceUDID = (udid) => uut.applesimutils.create.mockReturnValue(udid); + const aDeviceSpec = (udid) => ({ + udid, + os: { + identifier: 'mock-OS', + }, + }); + let applesimutils; beforeEach(() => { const SimulatorDriver = require('./SimulatorDriver'); uut = new SimulatorDriver({ client: {}, emitter }); - jest.spyOn(uut.deviceRegistry, 'includes').mockReturnValue(false); - jest.spyOn(uut.deviceRegistry, 'getRegisteredDevices').mockReturnValue({ - rawDevices: [], - includes: jest.fn().mockReturnValue(false), - }); + givenNoUsedSimulators(); applesimutils = uut.applesimutils; applesimutils.list.mockImplementation(async () => require('./tools/applesimutils.mock')['--list']); @@ -189,12 +201,41 @@ describe('IOS simulator driver', () => { 'Searching for device by type = "iPad 2" and by OS = "iOS 9.3.6" ...' ); }); + + it('should create a device', async () => { + const udidUsed = 'mock-used-udid'; + const udidNew = 'mock-new-udid'; + const specUsed = aDeviceSpec(udidUsed); + + givenSystemDevices(specUsed); + givenCreatedDeviceUDID(udidNew); + givenUsedSimulators(udidUsed); + + const result = await uut.acquireFreeDevice('iPhone Mock'); + + expect(uut.applesimutils.create).toHaveBeenCalledWith(specUsed); + expect(result).toEqual(udidNew); + }); + + it('should reuse a matching device', async () => { + const udid = 'mock-device-udid'; + const specUsed = aDeviceSpec(udid); + + givenSystemDevices(specUsed); + givenNoUsedSimulators(); + + const result = await uut.acquireFreeDevice('iPhone Mock'); + + expect(result).toEqual(udid); + expect(uut.applesimutils.create).not.toHaveBeenCalled(); + }); }); }); class mockAppleSimUtils { constructor() { this.launch = jest.fn(); + this.create = jest.fn(); this.setBiometricEnrollment = jest.fn(); this.matchBiometric = jest.fn(); this.unmatchBiometric = jest.fn(); From bc0d0797dfb63ef6cebbf2c16a223511bea8b54e Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Mon, 24 May 2021 14:20:03 +0300 Subject: [PATCH 3/5] hotfix(detox-cli): do not check -g on win32 (#2794) --- detox-cli/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detox-cli/cli.js b/detox-cli/cli.js index 6db8d5995d..69fb3d53d7 100755 --- a/detox-cli/cli.js +++ b/detox-cli/cli.js @@ -15,7 +15,7 @@ function log(msg) { function main([_$0, _detox, ...cliArgs]) { const [command] = cliArgs; - if (!isInstalledGlobally) { + if (process.platform !== 'win32' && !isInstalledGlobally) { log('Error: "detox-cli" package is not meant to be installed locally, exiting...'); log('HINT: Remove the local installation and reinstall it globally:'); log(' npm uninstall detox-cli'); From 61b95b2081b8f82ff8dcf2a258a67c48666852e0 Mon Sep 17 00:00:00 2001 From: wixmobile Date: Mon, 24 May 2021 08:14:31 -0400 Subject: [PATCH 4/5] Publish 18.14.1 [ci skip] --- detox-cli/package.json | 2 +- detox/package.json | 2 +- detox/test/package.json | 4 ++-- examples/demo-native-android/package.json | 4 ++-- examples/demo-native-ios/package.json | 4 ++-- examples/demo-react-native-detox-instruments/package.json | 4 ++-- examples/demo-react-native-jest/package.json | 4 ++-- examples/demo-react-native/package.json | 4 ++-- lerna.json | 2 +- package.json | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/detox-cli/package.json b/detox-cli/package.json index 1f73f1e5ad..ed3edda5f1 100644 --- a/detox-cli/package.json +++ b/detox-cli/package.json @@ -1,6 +1,6 @@ { "name": "detox-cli", - "version": "18.13.0", + "version": "18.14.1", "description": "Optional wrapper for Detox CLI, meant to be installed globally", "main": "cli.js", "scripts": { diff --git a/detox/package.json b/detox/package.json index 6d14288b3d..5ae47c9b33 100644 --- a/detox/package.json +++ b/detox/package.json @@ -1,7 +1,7 @@ { "name": "detox", "description": "E2E tests and automation for mobile", - "version": "18.14.0", + "version": "18.14.1", "bin": { "detox": "local-cli/cli.js" }, diff --git a/detox/test/package.json b/detox/test/package.json index 9d9db2b310..53a84824ec 100644 --- a/detox/test/package.json +++ b/detox/test/package.json @@ -1,6 +1,6 @@ { "name": "detox-test", - "version": "18.14.0", + "version": "18.14.1", "private": true, "engines": { "node": ">=8.3.0" @@ -38,7 +38,7 @@ "devDependencies": { "@babel/core": "^7.8.7", "@types/node": "^14.14.20", - "detox": "^18.14.0", + "detox": "^18.14.1", "dtslint": "^4.0.6", "express": "^4.15.3", "jest": "^26.5.0", diff --git a/examples/demo-native-android/package.json b/examples/demo-native-android/package.json index 5742efb553..704699dd0a 100644 --- a/examples/demo-native-android/package.json +++ b/examples/demo-native-android/package.json @@ -1,6 +1,6 @@ { "name": "detox-demo-native-android", - "version": "18.14.0", + "version": "18.14.1", "private": true, "scripts": { "packager": "react-native start", @@ -8,7 +8,7 @@ "e2e": "mocha e2e --opts ./e2e/mocha.opts" }, "devDependencies": { - "detox": "^18.14.0", + "detox": "^18.14.1", "mocha": "^6.1.3" }, "detox": {} diff --git a/examples/demo-native-ios/package.json b/examples/demo-native-ios/package.json index 1ea91c54f5..949e4ef663 100644 --- a/examples/demo-native-ios/package.json +++ b/examples/demo-native-ios/package.json @@ -1,9 +1,9 @@ { "name": "detox-demo-native-ios", - "version": "18.14.0", + "version": "18.14.1", "private": true, "devDependencies": { - "detox": "^18.14.0", + "detox": "^18.14.1", "mocha": "^6.1.3" }, "detox": { diff --git a/examples/demo-react-native-detox-instruments/package.json b/examples/demo-react-native-detox-instruments/package.json index 7e4e7a7f15..ad3cc86fe2 100644 --- a/examples/demo-react-native-detox-instruments/package.json +++ b/examples/demo-react-native-detox-instruments/package.json @@ -1,10 +1,10 @@ { "name": "demo-react-native-detox-instruments", - "version": "18.14.0", + "version": "18.14.1", "private": true, "scripts": {}, "devDependencies": { - "detox": "^18.14.0", + "detox": "^18.14.1", "mocha": "6.x.x" }, "detox": { diff --git a/examples/demo-react-native-jest/package.json b/examples/demo-react-native-jest/package.json index 06cb47549b..d8ce36e0f2 100644 --- a/examples/demo-react-native-jest/package.json +++ b/examples/demo-react-native-jest/package.json @@ -1,6 +1,6 @@ { "name": "demo-react-native-jest", - "version": "18.14.0", + "version": "18.14.1", "private": true, "scripts": { "test:ios-release": "detox test --configuration ios.sim.release -l verbose", @@ -10,7 +10,7 @@ }, "devDependencies": { "@types/jest": "^26.0.19", - "detox": "^18.14.0", + "detox": "^18.14.1", "jest": "^26.5.0", "jest-circus": "^26.5.2", "sanitize-filename": "^1.6.1", diff --git a/examples/demo-react-native/package.json b/examples/demo-react-native/package.json index dc86c10335..9702094ab1 100644 --- a/examples/demo-react-native/package.json +++ b/examples/demo-react-native/package.json @@ -1,6 +1,6 @@ { "name": "example", - "version": "18.14.0", + "version": "18.14.1", "private": true, "scripts": { "start": "react-native start", @@ -25,7 +25,7 @@ }, "devDependencies": { "@types/mocha": "^8.2.0", - "detox": "^18.14.0", + "detox": "^18.14.1", "mocha": "^6.1.3", "ts-node": "^9.1.1", "typescript": "^4.1.3" diff --git a/lerna.json b/lerna.json index b18b2deb15..7c3a65792e 100644 --- a/lerna.json +++ b/lerna.json @@ -13,7 +13,7 @@ "generation", "." ], - "version": "18.14.0", + "version": "18.14.1", "npmClient": "npm", "command": { "publish": { diff --git a/package.json b/package.json index 4c71bcd1d3..9f6c0a74a3 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,5 @@ "semver": "5.x.x", "shell-utils": "1.x.x" }, - "version": "18.14.0" + "version": "18.14.1" } From a4b370e3d2dd75942453d66cf264596c0abd3e7b Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Tue, 25 May 2021 15:17:24 +0300 Subject: [PATCH 5/5] lint: stricter rules (#2798) --- detox/.eslintignore | 1 + detox/.eslintrc | 73 +++++++++++++--- detox/.nvmrc | 2 +- detox/package.json | 2 + detox/runners/jest-circus/environment.js | 10 ++- detox/runners/jest-circus/index.js | 5 +- .../listeners/DetoxCoreListener.js | 11 +-- .../utils/assertExistingContext.js | 2 +- .../jest-circus/utils/assertJestCircus26.js | 1 + .../utils/wrapErrorWithNoopLifecycle.js | 1 + detox/runners/jest/DetoxAdapterCircus.js | 9 +- detox/runners/jest/DetoxAdapterImpl.js | 12 +-- detox/runners/jest/DetoxAdapterJasmine.js | 5 +- .../jest/DetoxStreamlineJestReporter.js | 3 +- detox/runners/jest/FailingTestsReporter.js | 1 + detox/runners/jest/SpecReporterCircus.js | 1 + detox/runners/jest/SpecReporterImpl.js | 20 +++-- .../runners/jest/WorkerAssignReporterImpl.js | 5 +- .../jest/WorkerAssignReporterJasmine.js | 1 + detox/runners/jest/adapter.js | 3 +- detox/runners/jest/assignReporter.js | 1 + detox/runners/jest/specReporter.js | 1 + detox/runners/mocha/adapter.js | 1 + detox/scripts/build.js | 18 ++-- detox/scripts/postinstall.js | 6 +- detox/src/Detox.js | 32 +++---- detox/src/Detox.test.js | 11 +-- detox/src/DetoxConstants.js | 18 ++-- detox/src/DetoxExportWrapper.js | 5 +- detox/src/android/AndroidExpect.js | 3 +- detox/src/android/AndroidExpect.test.js | 8 +- detox/src/android/actions/native.js | 4 +- detox/src/android/actions/web.js | 2 +- detox/src/android/core/NativeElement.js | 8 +- detox/src/android/core/NativeExpect.js | 4 +- detox/src/android/core/NativeWaitFor.js | 4 +- detox/src/android/core/WebElement.js | 3 +- detox/src/android/core/WebExpect.js | 6 +- detox/src/android/interactions/native.js | 4 +- detox/src/android/matchers/native.js | 4 +- detox/src/android/matchers/web.js | 2 +- detox/src/artifacts/ArtifactsManager.js | 11 ++- detox/src/artifacts/ArtifactsManager.test.js | 2 + .../android/AndroidInstrumentsPlugin.js | 1 + .../ios/SimulatorInstrumentsPlugin.js | 7 +- .../ios/SimulatorInstrumentsPlugin.test.js | 5 +- .../ios/SimulatorInstrumentsRecording.js | 5 +- .../ios/SimulatorInstrumentsRecording.test.js | 5 +- .../artifacts/log/android/ADBLogcatPlugin.js | 1 + .../log/android/ADBLogcatRecording.js | 2 +- .../artifacts/log/ios/SimulatorLogPlugin.js | 2 + .../log/ios/SimulatorLogPlugin.test.js | 12 +-- .../log/ios/SimulatorLogRecording.js | 3 +- .../screenshot/ADBScreencapPlugin.js | 3 +- .../screenshot/ScreenshotArtifactPlugin.js | 3 +- .../screenshot/SimulatorScreenshotPlugin.js | 6 +- .../templates/artifact/Artifact.test.js | 4 +- .../templates/artifact/FileArtifact.js | 23 ++--- .../templates/artifact/FileArtifact.test.js | 14 ++-- .../templates/plugin/ArtifactPlugin.js | 3 +- .../templates/plugin/ArtifactPlugin.test.js | 7 +- .../StartupAndTestRecorderPlugin.test.js | 7 +- .../plugin/TwoSnapshotsPerTestPlugin.js | 4 +- .../plugin/TwoSnapshotsPerTestPlugin.test.js | 7 +- .../plugin/WholeTestRecorderPlugin.js | 2 +- .../plugin/WholeTestRecorderPlugin.test.js | 7 +- .../plugin/__mocks__/testSuite.mock.js | 4 +- .../timeline/TimelineArtifactPlugin.js | 11 +-- .../timeline/TimelineArtifactPlugin.test.js | 18 ++-- .../uiHierarchy/IosUIHierarchyPlugin.js | 7 +- .../artifacts/utils/ArtifactPathBuilder.js | 1 + .../utils/ArtifactPathBuilder.test.js | 16 ++-- .../utils/buildDefaultArtifactsRootDirpath.js | 1 + .../buildDefaultArtifactsRootDirpath.test.js | 3 +- detox/src/artifacts/utils/temporaryPath.js | 1 + .../src/artifacts/utils/temporaryPath.test.js | 2 + .../video/ADBScreenrecorderPlugin.js | 2 +- .../video/SimulatorRecordVideoPlugin.js | 8 +- detox/src/client/AsyncWebSocket.js | 8 +- detox/src/client/AsyncWebSocket.test.js | 13 +-- detox/src/client/Client.js | 23 ++--- detox/src/client/Client.test.js | 52 ++++++------ detox/src/client/__mocks__/Client.js | 2 +- detox/src/client/actions/actions.js | 7 +- .../__mocks__/configuration/extends/middle.js | 2 +- detox/src/configuration/collectCliConfig.js | 1 + detox/src/configuration/composeAppsConfig.js | 1 + .../configuration/composeAppsConfig.test.js | 6 +- .../configuration/composeArtifactsConfig.js | 8 +- .../composeArtifactsConfig.test.js | 24 +++--- .../composeBehaviorConfig.test.js | 2 +- .../src/configuration/composeDeviceConfig.js | 1 + .../configuration/composeDeviceConfig.test.js | 8 +- .../src/configuration/composeSessionConfig.js | 3 +- .../src/configuration/configurations.mock.js | 40 ++++----- detox/src/configuration/index.js | 6 +- detox/src/configuration/index.test.js | 4 +- detox/src/configuration/loadExternalConfig.js | 6 +- .../configuration/loadExternalConfig.test.js | 16 ++-- .../configuration/selectConfiguration.test.js | 3 +- detox/src/devices/Device.js | 6 +- detox/src/devices/Device.test.js | 84 +++++++++---------- detox/src/devices/DeviceRegistry.js | 7 +- detox/src/devices/DeviceRegistry.test.js | 9 +- detox/src/devices/LaunchArgsEditor.js | 1 + detox/src/devices/LaunchArgsEditor.test.js | 2 +- detox/src/devices/drivers/DeviceDriverBase.js | 8 +- .../devices/drivers/android/AndroidDriver.js | 44 +++++----- .../drivers/android/AndroidDriver.test.js | 28 +++---- .../android/attached/AttachedAndroidDriver.js | 3 +- .../drivers/android/emulator/AVDValidator.js | 3 +- .../android/emulator/AVDValidator.test.js | 2 +- .../android/emulator/EmulatorDriver.js | 25 +++--- .../emulator/EmulatorVersionResolver.js | 4 +- .../emulator/EmulatorVersionResolver.test.js | 26 +++--- .../emulator/FreeEmulatorFinder.test.js | 2 +- .../helpers/EmulatorDeviceAllocation.js | 2 +- .../emulator/helpers/EmulatorLauncher.js | 14 ++-- .../src/devices/drivers/android/exec/AAPT.js | 4 +- .../devices/drivers/android/exec/AAPT.test.js | 4 +- detox/src/devices/drivers/android/exec/ADB.js | 17 ++-- .../devices/drivers/android/exec/ADB.test.js | 12 +-- .../drivers/android/exec/BinaryExec.js | 1 + .../drivers/android/exec/BinaryExec.test.js | 14 ++-- .../drivers/android/exec/EmulatorExec.js | 7 +- .../android/genycloud/GenyCloudDriver.js | 20 +++-- .../genycloud/GenyDeviceRegistryFactory.js | 2 +- .../GenyDeviceRegistryFactory.test.js | 1 + .../genycloud/exec/GenyCloudExec.test.js | 4 +- .../helpers/GenyCloudInstanceAllocation.js | 6 +- .../GenyCloudInstanceAllocation.test.js | 4 +- .../helpers/GenyCloudInstanceLauncher.test.js | 2 +- .../services/GenyInstanceNaming.test.js | 2 +- .../genycloud/services/GenyRecipesService.js | 2 +- .../services/GenyRecipesService.test.js | 4 +- .../genycloud/services/dto/GenyInstance.js | 2 +- .../services/dto/GenyInstance.test.js | 2 +- .../devices/drivers/android/tools/APKPath.js | 2 + .../drivers/android/tools/EmulatorTelnet.js | 6 +- .../android/tools/FreeDeviceFinder.test.js | 2 +- .../drivers/android/tools/Instrumentation.js | 2 + .../android/tools/Instrumentation.test.js | 12 +-- .../android/tools/MonitoredInstrumentation.js | 6 +- .../tools/MonitoredInstrumentation.test.js | 6 +- .../android/tools/instrumentationArgs.js | 3 +- detox/src/devices/drivers/ios/IosDriver.js | 14 ++-- .../devices/drivers/ios/SimulatorDriver.js | 27 +++--- .../drivers/ios/SimulatorDriver.test.js | 8 +- .../drivers/ios/tools/AppleSimUtils.js | 34 ++++---- detox/src/errors/DetoxConfigErrorComposer.js | 6 +- .../errors/DetoxConfigErrorComposer.test.js | 20 +++-- detox/src/errors/DetoxError.js | 5 +- detox/src/errors/DetoxInternalError.test.js | 2 +- detox/src/errors/DetoxRuntimeError.js | 1 + detox/src/errors/DetoxRuntimeError.test.js | 3 +- detox/src/errors/DetoxRuntimeErrorComposer.js | 3 +- .../longreads/failedToReachTheApp.test.js | 2 +- detox/src/invoke.js | 2 +- detox/src/invoke.test.js | 12 +-- detox/src/invoke/Invoke.test.js | 2 +- detox/src/ios/expectTwo.js | 9 +- detox/src/ios/expectTwo.test.js | 3 +- detox/src/ios/expectTwoApiCoverage.test.js | 5 +- detox/src/matchersRegistry.test.js | 2 +- detox/src/server/DetoxConnection.js | 4 +- detox/src/server/DetoxServer.js | 6 +- detox/src/server/DetoxServer.test.js | 2 +- detox/src/server/DetoxSessionManager.js | 3 +- detox/src/server/__mocks__/FakeWebSocket.js | 2 +- .../__tests__/server-integration.test.js | 6 +- .../handlers/AnonymousConnectionHandler.js | 3 +- .../server/handlers/AppConnectionHandler.js | 1 + .../handlers/RegisteredConnectionHandler.js | 7 +- .../handlers/TesterConnectionHandler.js | 3 +- detox/src/utils/AsyncEmitter.js | 1 + detox/src/utils/ChromeTracingExporter.js | 5 +- detox/src/utils/ChromeTracingExporter.test.js | 10 +-- detox/src/utils/ExclusiveLockfile.js | 6 +- detox/src/utils/ExclusiveLockfile.test.js | 5 +- detox/src/utils/Timer.js | 1 + detox/src/utils/__mocks__/trace.js | 2 +- detox/src/utils/appdatapath.js | 1 + detox/src/utils/appendFile.js | 2 +- detox/src/utils/appendFile.test.js | 1 + detox/src/utils/argparse.js | 7 +- detox/src/utils/argparse.test.js | 6 +- detox/src/utils/callsites.js | 3 +- detox/src/utils/constructSafeFilename.js | 3 +- detox/src/utils/customConsoleLogger.js | 1 + detox/src/utils/customConsoleLogger.test.js | 4 +- detox/src/utils/environment.js | 17 ++-- detox/src/utils/environment.test.js | 13 +-- detox/src/utils/errorUtils.test.js | 11 +-- detox/src/utils/exec.interruptProcess.test.js | 4 +- detox/src/utils/exec.js | 12 +-- detox/src/utils/exec.test.js | 22 ++--- detox/src/utils/fsext.js | 3 +- detox/src/utils/getAbsoluteBinaryPath.js | 1 + detox/src/utils/getAbsoluteBinaryPath.test.js | 1 + detox/src/utils/lastFailedTests.js | 1 + detox/src/utils/logger.js | 9 +- detox/src/utils/pipeCommands.js | 2 +- detox/src/utils/pressAnyKey.js | 2 +- detox/src/utils/resolveModuleFromPath.js | 2 +- detox/src/utils/resolveModuleFromPath.test.js | 4 +- detox/src/utils/retry.js | 1 + detox/src/utils/retry.test.js | 12 +-- detox/src/utils/setUniqueProperty.test.js | 6 +- detox/src/utils/sh.js | 3 +- detox/src/utils/sh.test.js | 1 - detox/src/utils/shellQuote.js | 1 + detox/src/utils/shellQuote.test.js | 2 +- detox/src/utils/shellUtils.js | 6 +- detox/src/utils/shellUtils.test.js | 12 +-- detox/src/utils/string.js | 2 +- detox/src/utils/trace.js | 2 +- detox/src/utils/trace.test.js | 6 +- 217 files changed, 918 insertions(+), 683 deletions(-) create mode 100644 detox/.eslintignore diff --git a/detox/.eslintignore b/detox/.eslintignore new file mode 100644 index 0000000000..6ba95d9f51 --- /dev/null +++ b/detox/.eslintignore @@ -0,0 +1 @@ +src/android/espressoapi/**/*.js diff --git a/detox/.eslintrc b/detox/.eslintrc index 6b338a5965..41426d34d6 100644 --- a/detox/.eslintrc +++ b/detox/.eslintrc @@ -1,24 +1,77 @@ { "env": { - "node": true, - "jest": true + "jest": true, + "node": true }, - "plugins": ["node"], - "extends": ["plugin:node/recommended"], + "extends": [ + "eslint:recommended", + "plugin:import/recommended", + "plugin:node/recommended" + ], "globals": { - "fail": true, + "fail": true }, "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module", "ecmaFeatures": { "experimentalObjectRestSpread": true - } + }, + "ecmaVersion": 2018, + "sourceType": "module" }, + "plugins": [ + "import", + "node", + "no-only-tests" + ], "rules": { + "array-bracket-spacing": [ + "error", + "never" + ], + "computed-property-spacing": [ + "error", + "never" + ], + "import/order": [ + "error", + { + "alphabetize": { + "order": "asc" + }, + "newlines-between": "always" + } + ], + "no-case-declarations": "off", "no-debugger": "error", - "no-undef": "warn", + "no-empty": "off", "no-mixed-spaces-and-tabs": "error", - "node/no-unpublished-require": "warn" + "no-multiple-empty-lines": [ + "error", + { + "max": 2, + "maxBOF": 1 + } + ], + "no-only-tests/no-only-tests": "error", + "no-undef": "warn", + "no-unused-vars": [ + "warn", + { + "argsIgnorePattern": "^_" + } + ], + "node/no-unpublished-require": "warn", + "object-curly-spacing": [ + "error", + "always" + ], + "semi": [ + "error", + "always" + ], + "quotes": ["error", "single", { + "avoidEscape": true, + "allowTemplateLiterals": true + }] } } diff --git a/detox/.nvmrc b/detox/.nvmrc index 45a4fb75db..25615cc6a8 100644 --- a/detox/.nvmrc +++ b/detox/.nvmrc @@ -1 +1 @@ -8 +12.22.1 diff --git a/detox/package.json b/detox/package.json index 5ae47c9b33..572f147bf1 100644 --- a/detox/package.json +++ b/detox/package.json @@ -33,6 +33,8 @@ "@types/child-process-promise": "^2.2.1", "@types/ws": "^7.4.0", "eslint": "^4.11.0", + "eslint-plugin-import": "^2.23.3", + "eslint-plugin-no-only-tests": "^2.6.0", "eslint-plugin-node": "^6.0.1", "jest": "^26.5.0", "jest-circus": "^26.5.2", diff --git a/detox/runners/jest-circus/environment.js b/detox/runners/jest-circus/environment.js index c739c1fbdf..2399840d33 100644 --- a/detox/runners/jest-circus/environment.js +++ b/detox/runners/jest-circus/environment.js @@ -1,12 +1,14 @@ -const _ = require('lodash'); const NodeEnvironment = require('jest-environment-node'); +const _ = require('lodash'); + +const DetoxError = require('../../src/errors/DetoxError'); +const Timer = require('../../src/utils/Timer'); + const DetoxCoreListener = require('./listeners/DetoxCoreListener'); const DetoxInitErrorListener = require('./listeners/DetoxInitErrorListener'); -const assertJestCircus26 = require('./utils/assertJestCircus26'); const assertExistingContext = require('./utils/assertExistingContext'); +const assertJestCircus26 = require('./utils/assertJestCircus26'); const wrapErrorWithNoopLifecycle = require('./utils/wrapErrorWithNoopLifecycle'); -const DetoxError = require('../../src/errors/DetoxError'); -const Timer = require('../../src/utils/Timer'); const SYNC_CIRCUS_EVENTS = new Set([ 'start_describe_definition', diff --git a/detox/runners/jest-circus/index.js b/detox/runners/jest-circus/index.js index c393add1c2..75a956bccf 100644 --- a/detox/runners/jest-circus/index.js +++ b/detox/runners/jest-circus/index.js @@ -1,6 +1,7 @@ -const DetoxCircusEnvironment = require('./environment'); -const WorkerAssignReporterCircus = require('../jest/WorkerAssignReporterCircus'); const SpecReporterCircus = require('../jest/SpecReporterCircus'); +const WorkerAssignReporterCircus = require('../jest/WorkerAssignReporterCircus'); + +const DetoxCircusEnvironment = require('./environment'); module.exports = { DetoxCircusEnvironment, diff --git a/detox/runners/jest-circus/listeners/DetoxCoreListener.js b/detox/runners/jest-circus/listeners/DetoxCoreListener.js index 4f52b3a238..69c38b3e6b 100644 --- a/detox/runners/jest-circus/listeners/DetoxCoreListener.js +++ b/detox/runners/jest-circus/listeners/DetoxCoreListener.js @@ -1,5 +1,6 @@ +const { RETRY_TIMES } = require('jest-circus/build/types'); const _ = require('lodash'); -const {getFullTestName, hasTimedOut} = require('../../jest/utils'); + const { onRunDescribeStart, onTestStart, @@ -8,7 +9,7 @@ const { onTestDone, onRunDescribeFinish, } = require('../../integration').lifecycle; -const { RETRY_TIMES } = require('jest-circus/build/types'); +const { getFullTestName, hasTimedOut } = require('../../jest/utils'); class DetoxCoreListener { constructor({ detox, env }) { @@ -20,7 +21,7 @@ class DetoxCoreListener { } _getTestInvocations(test) { - const {DETOX_RERUN_INDEX} = process.env; + const { DETOX_RERUN_INDEX } = process.env; if (!isNaN(DETOX_RERUN_INDEX)) { return Number(DETOX_RERUN_INDEX) * this._testRunTimes + test.invocations; @@ -29,13 +30,13 @@ class DetoxCoreListener { } } - async run_describe_start({describeBlock: {name, children}}) { + async run_describe_start({ describeBlock: { name, children } }) { if (children.length) { await this.detox[onRunDescribeStart]({ name }); } } - async run_describe_finish({describeBlock: {name, children}}) { + async run_describe_finish({ describeBlock: { name, children } }) { if (children.length) { await this.detox[onRunDescribeFinish]({ name }); } diff --git a/detox/runners/jest-circus/utils/assertExistingContext.js b/detox/runners/jest-circus/utils/assertExistingContext.js index 21a4129819..fe12dd7e57 100644 --- a/detox/runners/jest-circus/utils/assertExistingContext.js +++ b/detox/runners/jest-circus/utils/assertExistingContext.js @@ -1,5 +1,5 @@ -const { filterErrorStack } = require('../../../src/utils/errorUtils'); const { DetoxRuntimeError } = require('../../../src/errors/DetoxRuntimeError'); +const { filterErrorStack } = require('../../../src/utils/errorUtils'); function findUserConstructor() { let wasInBaseClass = false; diff --git a/detox/runners/jest-circus/utils/assertJestCircus26.js b/detox/runners/jest-circus/utils/assertJestCircus26.js index 5591a0669b..c926d682f5 100644 --- a/detox/runners/jest-circus/utils/assertJestCircus26.js +++ b/detox/runners/jest-circus/utils/assertJestCircus26.js @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); + const DetoxRuntimeError = require('../../../src/errors/DetoxRuntimeError'); function assertJestCircus26(config) { diff --git a/detox/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js b/detox/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js index 9f5ffef504..68b7ba0ee6 100644 --- a/detox/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js +++ b/detox/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const lifecycleSymbols = require('../../integration').lifecycle; function wrapErrorWithNoopLifecycle(error) { diff --git a/detox/runners/jest/DetoxAdapterCircus.js b/detox/runners/jest/DetoxAdapterCircus.js index 8ec039f271..80b37c660f 100644 --- a/detox/runners/jest/DetoxAdapterCircus.js +++ b/detox/runners/jest/DetoxAdapterCircus.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const DetoxAdapter = require('./DetoxAdapterImpl'); const { getFullTestName, hasTimedOut } = require('./utils'); @@ -24,12 +25,12 @@ class DetoxAdapterCircus { await this._adapter.afterAll(); } - async run_describe_start({describeBlock: {name, children}}, state) { - if (children.length) await this._adapter.suiteStart({name}); + async run_describe_start({ describeBlock: { name, children } }, state) { + if (children.length) await this._adapter.suiteStart({ name }); } - async run_describe_finish({describeBlock: {name, children}}, state) { - if (children.length) await this._adapter.suiteEnd({name}); + async run_describe_finish({ describeBlock: { name, children } }, state) { + if (children.length) await this._adapter.suiteEnd({ name }); } test_start(event) { diff --git a/detox/runners/jest/DetoxAdapterImpl.js b/detox/runners/jest/DetoxAdapterImpl.js index ae30f3e283..eb311c8561 100644 --- a/detox/runners/jest/DetoxAdapterImpl.js +++ b/detox/runners/jest/DetoxAdapterImpl.js @@ -32,15 +32,15 @@ class DetoxAdapterImpl { await this._flush(); } - async suiteStart({name}) { - this._enqueue(() => this.detox.suiteStart({name})); + async suiteStart({ name }) { + this._enqueue(() => this.detox.suiteStart({ name })); } - async suiteEnd({name}) { - this._enqueue(() => this.detox.suiteEnd({name})); + async suiteEnd({ name }) { + this._enqueue(() => this.detox.suiteEnd({ name })); } - testStart({title, fullName, status}) { + testStart({ title, fullName, status }) { this._currentTest = { title, fullName, @@ -48,7 +48,7 @@ class DetoxAdapterImpl { }; } - testComplete({status, timedOut}) { + testComplete({ status, timedOut }) { if (this._currentTest) { const _test = { ...this._currentTest, diff --git a/detox/runners/jest/DetoxAdapterJasmine.js b/detox/runners/jest/DetoxAdapterJasmine.js index 1788a978be..a4f09572ed 100644 --- a/detox/runners/jest/DetoxAdapterJasmine.js +++ b/detox/runners/jest/DetoxAdapterJasmine.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const DetoxAdapter = require('./DetoxAdapterImpl'); class DetoxAdapterJasmine /* extends JasmineReporter */ { @@ -24,11 +25,11 @@ class DetoxAdapterJasmine /* extends JasmineReporter */ { } async suiteStarted(result) { - await this._adapter.suiteStart({name: result.description}); + await this._adapter.suiteStart({ name: result.description }); } async suiteDone(result) { - await this._adapter.suiteEnd({name: result.description}); + await this._adapter.suiteEnd({ name: result.description }); } specStarted(result) { diff --git a/detox/runners/jest/DetoxStreamlineJestReporter.js b/detox/runners/jest/DetoxStreamlineJestReporter.js index 85bd4147eb..cdfadc478b 100644 --- a/detox/runners/jest/DetoxStreamlineJestReporter.js +++ b/detox/runners/jest/DetoxStreamlineJestReporter.js @@ -1,4 +1,5 @@ -const {VerboseReporter: JestVerboseReporter} = require('@jest/reporters'); // eslint-disable-line node/no-extraneous-require +const { VerboseReporter: JestVerboseReporter } = require('@jest/reporters'); // eslint-disable-line node/no-extraneous-require + const DetoxRuntimeError = require('../../src/errors/DetoxRuntimeError'); class DetoxStreamlineJestReporter extends JestVerboseReporter { diff --git a/detox/runners/jest/FailingTestsReporter.js b/detox/runners/jest/FailingTestsReporter.js index 201d46d918..2b286fc8b3 100644 --- a/detox/runners/jest/FailingTestsReporter.js +++ b/detox/runners/jest/FailingTestsReporter.js @@ -1,4 +1,5 @@ const path = require('path'); + const { saveLastFailedTests } = require('../../src/utils/lastFailedTests'); class FailingTestsReporter { diff --git a/detox/runners/jest/SpecReporterCircus.js b/detox/runners/jest/SpecReporterCircus.js index fa61de6532..fe01ae21f4 100644 --- a/detox/runners/jest/SpecReporterCircus.js +++ b/detox/runners/jest/SpecReporterCircus.js @@ -1,4 +1,5 @@ const argparse = require('../../src/utils/argparse'); + const SpecReporter = require('./SpecReporterImpl'); class SpecReporterCircus { diff --git a/detox/runners/jest/SpecReporterImpl.js b/detox/runners/jest/SpecReporterImpl.js index 5bebd2cab0..fb4d99f99f 100644 --- a/detox/runners/jest/SpecReporterImpl.js +++ b/detox/runners/jest/SpecReporterImpl.js @@ -1,7 +1,9 @@ const chalk = require('chalk').default; -const { traceln } = require('./utils/stdout'); + const log = require('../../src/utils/logger').child(); +const { traceln } = require('./utils/stdout'); + const RESULT_SKIPPED = chalk.yellow('SKIPPED'); const RESULT_FAILED = chalk.red('FAIL'); const RESULT_PENDING = chalk.yellow('PENDING'); @@ -14,8 +16,8 @@ class SpecReporter { this._suitesDesc = ''; } - onSuiteStart({description}) { - this._suites.push({description}); + onSuiteStart({ description }) { + this._suites.push({ description }); this._regenerateSuitesDesc(); } @@ -28,11 +30,11 @@ class SpecReporter { } } - onTestStart({description, invocations = 1}) { - this._traceTest({description, invocations}); + onTestStart({ description, invocations = 1 }) { + this._traceTest({ description, invocations }); } - onTestEnd({description, invocations = 1}, result) { + onTestEnd({ description, invocations = 1 }, result) { let status; switch (result) { case 'skipped': status = RESULT_SKIPPED; break; @@ -41,7 +43,7 @@ class SpecReporter { case 'success': status = RESULT_SUCCESS; break; default: status = RESULT_OTHER; break; } - this._traceTest({description, invocations}, status); + this._traceTest({ description, invocations }, status); } _regenerateSuitesDesc() { @@ -57,12 +59,12 @@ class SpecReporter { this._suitesDesc = chalk.bold.white(this._suitesDesc); } - _traceTest({description, invocations}, _status = undefined) { + _traceTest({ description, invocations }, _status = undefined) { const testDescription = chalk.gray(description); const retriesDescription = (invocations > 1) ? chalk.gray(` [Retry #${invocations - 1}]`) : ''; const status = chalk.gray(_status ? ` [${_status}]` : ''); const desc = this._suitesDesc + testDescription + retriesDescription + status; - log.info({event: 'SPEC_STATE_CHANGE'}, desc); + log.info({ event: 'SPEC_STATE_CHANGE' }, desc); } } diff --git a/detox/runners/jest/WorkerAssignReporterImpl.js b/detox/runners/jest/WorkerAssignReporterImpl.js index 0dc80f6d83..ea7757878e 100644 --- a/detox/runners/jest/WorkerAssignReporterImpl.js +++ b/detox/runners/jest/WorkerAssignReporterImpl.js @@ -1,5 +1,6 @@ -const _ = require('lodash'); const chalk = require('chalk').default; +const _ = require('lodash'); + const log = require('../../src/utils/logger').child(); class WorkerAssignReporterImpl { @@ -13,7 +14,7 @@ class WorkerAssignReporterImpl { ? chalk.redBright('undefined') : chalk.blueBright(deviceName); - log.info({event: 'WORKER_ASSIGN'}, `${chalk.whiteBright(workerName)} is assigned to ${formattedDeviceName}`); + log.info({ event: 'WORKER_ASSIGN' }, `${chalk.whiteBright(workerName)} is assigned to ${formattedDeviceName}`); } } diff --git a/detox/runners/jest/WorkerAssignReporterJasmine.js b/detox/runners/jest/WorkerAssignReporterJasmine.js index 3b9756b1b4..d5b5591dfe 100644 --- a/detox/runners/jest/WorkerAssignReporterJasmine.js +++ b/detox/runners/jest/WorkerAssignReporterJasmine.js @@ -1,4 +1,5 @@ const path = require('path'); + const WorkerAssignReporter = require('./WorkerAssignReporterImpl'); class WorkerAssignReporterJasmine { diff --git a/detox/runners/jest/adapter.js b/detox/runners/jest/adapter.js index 2bb2e46426..4d9b4f124a 100644 --- a/detox/runners/jest/adapter.js +++ b/detox/runners/jest/adapter.js @@ -1,5 +1,6 @@ -const runnerInfo = require('./runnerInfo'); const detox = require('../../src/index'); + +const runnerInfo = require('./runnerInfo'); const DetoxAdapter = runnerInfo.isJestCircus ? require('./DetoxAdapterCircus') : require('./DetoxAdapterJasmine'); module.exports = new DetoxAdapter(detox); diff --git a/detox/runners/jest/assignReporter.js b/detox/runners/jest/assignReporter.js index 0d6d1166b3..55bf48dc1d 100644 --- a/detox/runners/jest/assignReporter.js +++ b/detox/runners/jest/assignReporter.js @@ -1,4 +1,5 @@ const detox = require('../../src/index'); + const runnerInfo = require('./runnerInfo'); const Reporter = runnerInfo.isJestCircus ? require('./WorkerAssignReporterCircus') : require('./WorkerAssignReporterJasmine'); diff --git a/detox/runners/jest/specReporter.js b/detox/runners/jest/specReporter.js index 75c0fd1162..ff98306b98 100644 --- a/detox/runners/jest/specReporter.js +++ b/detox/runners/jest/specReporter.js @@ -1,4 +1,5 @@ const argparse = require('../../src/utils/argparse'); + const runnerInfo = require('./runnerInfo'); if (argparse.getArgValue('reportSpecs') === 'true') { diff --git a/detox/runners/mocha/adapter.js b/detox/runners/mocha/adapter.js index 09e398f7ec..83c186f105 100644 --- a/detox/runners/mocha/adapter.js +++ b/detox/runners/mocha/adapter.js @@ -1,4 +1,5 @@ const detox = require('../../src/index'); + const DetoxMochaAdapter = require('./DetoxMochaAdapter'); module.exports = new DetoxMochaAdapter(detox); diff --git a/detox/scripts/build.js b/detox/scripts/build.js index dde44f4982..9ef40ef1e1 100755 --- a/detox/scripts/build.js +++ b/detox/scripts/build.js @@ -1,21 +1,23 @@ const fs = require('fs-extra'); -const {sh} = require('./utils'); + +const { sh } = require('./utils'); //No need to pack iOS artifacts here. The build_framework.ios.sh script will be called during the post-install phase. -if (process.argv[2] === "android" || process.argv[3] === "android") { - console.log("\nBuilding Detox aars"); +if (process.argv[2] === 'android' || process.argv[3] === 'android') { + // eslint-disable-next-line no-console + console.log('\nBuilding Detox aars'); const aars = [ - "detox-debug.aar", - "detox-release.aar" + 'detox-debug.aar', + 'detox-release.aar' ]; aars.forEach(aar => { fs.removeSync(aar); }); - sh("./gradlew assembleDebug assembleRelease", { - cwd: "android", - stdio: "inherit", + sh('./gradlew assembleDebug assembleRelease', { + cwd: 'android', + stdio: 'inherit', shell: true }); diff --git a/detox/scripts/postinstall.js b/detox/scripts/postinstall.js index 44c050a092..e448f0ce4a 100755 --- a/detox/scripts/postinstall.js +++ b/detox/scripts/postinstall.js @@ -1,5 +1,5 @@ -if (process.platform === "darwin" && !process.env.DETOX_DISABLE_POSTINSTALL) { - require("child_process").execFileSync(`${__dirname}/build_framework.ios.sh`, { - stdio: "inherit" +if (process.platform === 'darwin' && !process.env.DETOX_DISABLE_POSTINSTALL) { + require('child_process').execFileSync(`${__dirname}/build_framework.ios.sh`, { + stdio: 'inherit' }); } diff --git a/detox/src/Detox.js b/detox/src/Detox.js index 8e980236f4..815d40374e 100644 --- a/detox/src/Detox.js +++ b/detox/src/Detox.js @@ -1,25 +1,27 @@ -const _ = require('lodash'); +const { URL } = require('url'); const util = require('util'); -const {URL} = require('url'); -const logger = require('./utils/logger'); -const Deferred = require('./utils/Deferred'); + +const _ = require('lodash'); + +const lifecycleSymbols = require('../runners/integration').lifecycle; + +const ArtifactsManager = require('./artifacts/ArtifactsManager'); +const Client = require('./client/Client'); const Device = require('./devices/Device'); +const driverRegistry = require('./devices/DriverRegistry').default; const DetoxRuntimeErrorComposer = require('./errors/DetoxRuntimeErrorComposer'); -const AsyncEmitter = require('./utils/AsyncEmitter'); -const MissingDetox = require('./utils/MissingDetox'); -const Client = require('./client/Client'); const { InvocationManager } = require('./invoke'); +const matchersRegistry = require('./matchersRegistry'); const DetoxServer = require('./server/DetoxServer'); -const ArtifactsManager = require('./artifacts/ArtifactsManager'); +const AsyncEmitter = require('./utils/AsyncEmitter'); +const Deferred = require('./utils/Deferred'); +const MissingDetox = require('./utils/MissingDetox'); +const logger = require('./utils/logger'); const log = logger.child({ __filename }); -const driverRegistry = require('./devices/DriverRegistry').default; -const matchersRegistry = require('./matchersRegistry'); const _initHandle = Symbol('_initHandle'); const _assertNoPendingInit = Symbol('_assertNoPendingInit'); -const lifecycleSymbols = require('../runners/integration').lifecycle; - class Detox { constructor(config) { log.trace( @@ -37,7 +39,7 @@ class Detox { this[lifecycleSymbols.onTestStart] = this.beforeEach; this[lifecycleSymbols.onTestDone] = this.afterEach; - const {appsConfig, artifactsConfig, behaviorConfig, deviceConfig, sessionConfig} = config; + const { appsConfig, artifactsConfig, behaviorConfig, deviceConfig, sessionConfig } = config; this._appsConfig = appsConfig; this._artifactsConfig = artifactsConfig; @@ -218,7 +220,7 @@ class Detox { const appNames = Object.keys(this._appsConfig); for (const appName of appNames) { - await this.device.selectApp(appName) + await this.device.selectApp(appName); await this.device.uninstallApp(); await this.device.installApp(); } @@ -249,7 +251,7 @@ class Detox { async _dumpUnhandledErrorsIfAny({ testName, pendingRequests }) { if (pendingRequests) { - this._client.dumpPendingRequests({testName}); + this._client.dumpPendingRequests({ testName }); } } diff --git a/detox/src/Detox.test.js b/detox/src/Detox.test.js index b421981563..cf81b0a822 100644 --- a/detox/src/Detox.test.js +++ b/detox/src/Detox.test.js @@ -1,6 +1,7 @@ const _ = require('lodash'); -const configuration = require('./configuration'); + const testSummaries = require('./artifacts/__mocks__/testSummaries.mock'); +const configuration = require('./configuration'); jest.mock('./utils/logger'); jest.mock('./devices/DriverRegistry'); @@ -257,7 +258,7 @@ describe('Detox', () => { const { emitter } = Device.mock.calls[0][0]; const testError = new Error(); - emitter.on('bootDevice', async () => { throw testError; }) + emitter.on('bootDevice', async () => { throw testError; }); await emitter.emit('bootDevice', {}); expect(logger.error).toHaveBeenCalledWith( @@ -288,7 +289,7 @@ describe('Detox', () => { const initPromise = detox.init(); await expect(detox.beforeEach(testSummaries.running())).rejects.toThrowError(/Aborted detox.init/); await expect(initPromise).rejects.toThrowError(/Aborted detox.init/); - }) + }); }); describe('after detox.init() is finished', () => { @@ -360,7 +361,7 @@ describe('Detox', () => { const initPromise = detox.init(); await expect(detox.afterEach(testSummaries.running())).rejects.toThrowError(/Aborted detox.init/); await expect(initPromise).rejects.toThrowError(/Aborted detox.init/); - }) + }); }); describe('after detox.init() is finished', () => { @@ -425,7 +426,7 @@ describe('Detox', () => { await expect(detox.cleanup()).resolves.not.toThrowError(); await expect(initPromise).rejects.toThrowError(/Aborted detox.init.*execution/); }); - }) + }); describe('before device has been prepared', () => { beforeEach(() => Device.setInfiniteMethod('prepare')); diff --git a/detox/src/DetoxConstants.js b/detox/src/DetoxConstants.js index 405f142a23..0b2fb92d5c 100644 --- a/detox/src/DetoxConstants.js +++ b/detox/src/DetoxConstants.js @@ -1,13 +1,13 @@ module.exports = Object.freeze({ - "userNotificationTriggers": { - "push": "push", - "calendar": "calendar", - "timeInterval": "timeInterval", - "location": "location" + 'userNotificationTriggers': { + 'push': 'push', + 'calendar': 'calendar', + 'timeInterval': 'timeInterval', + 'location': 'location' }, - "userActivityTypes": { - "searchableItem": "com.apple.corespotlightitem", - "browsingWeb": "NSUserActivityTypeBrowsingWeb", + 'userActivityTypes': { + 'searchableItem': 'com.apple.corespotlightitem', + 'browsingWeb': 'NSUserActivityTypeBrowsingWeb', }, - "searchableItemActivityIdentifier": "kCSSearchableItemActivityIdentifier" + 'searchableItemActivityIdentifier': 'kCSSearchableItemActivityIdentifier' }); \ No newline at end of file diff --git a/detox/src/DetoxExportWrapper.js b/detox/src/DetoxExportWrapper.js index 7d73fac0a5..2cf4d18834 100644 --- a/detox/src/DetoxExportWrapper.js +++ b/detox/src/DetoxExportWrapper.js @@ -1,4 +1,5 @@ const funpermaproxy = require('funpermaproxy'); + const Detox = require('./Detox'); const DetoxConstants = require('./DetoxConstants'); const configuration = require('./configuration'); @@ -118,7 +119,7 @@ DetoxExportWrapper.prototype.globalInit = async function() { } catch (error) { log.warn({ event: 'GLOBAL_INIT' }, 'An error occurred trying to globally-init Genymotion-cloud emulator instances!', error); } -} +}; DetoxExportWrapper.prototype.globalCleanup = async function() { try { @@ -128,6 +129,6 @@ DetoxExportWrapper.prototype.globalCleanup = async function() { } catch (error) { log.warn({ event: 'GLOBAL_CLEANUP' }, 'An error occurred trying to shut down Genymotion-cloud emulator instances!', error); } -} +}; module.exports = DetoxExportWrapper; diff --git a/detox/src/android/AndroidExpect.js b/detox/src/android/AndroidExpect.js index d68eba583f..c57391ba66 100644 --- a/detox/src/android/AndroidExpect.js +++ b/detox/src/android/AndroidExpect.js @@ -1,7 +1,8 @@ const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); + const { NativeElement } = require('./core/NativeElement'); -const { NativeMatcher } = require('./core/NativeMatcher'); const { NativeExpectElement } = require('./core/NativeExpect'); +const { NativeMatcher } = require('./core/NativeMatcher'); const { NativeWaitForElement } = require('./core/NativeWaitFor'); const { WebElement, WebViewElement } = require('./core/WebElement'); const { WebExpectElement } = require('./core/WebExpect'); diff --git a/detox/src/android/AndroidExpect.test.js b/detox/src/android/AndroidExpect.test.js index 0c916f1c6c..f632b724be 100644 --- a/detox/src/android/AndroidExpect.test.js +++ b/detox/src/android/AndroidExpect.test.js @@ -151,7 +151,7 @@ describe('AndroidExpect', () => { it('should tap and long-press', async () => { await e.element(e.by.label('Tap Me')).tap(); await e.element(e.by.label('Tap Me')).tap({ x: 10, y: 10 }); - await e.element(e.by.label('Tap Me')).tapAtPoint({x: 100, y: 200}); + await e.element(e.by.label('Tap Me')).tapAtPoint({ x: 100, y: 200 }); await e.element(e.by.label('Tap Me')).longPress(); await e.element(e.by.id('UniqueId819')).multiTap(3); }); @@ -230,7 +230,7 @@ describe('AndroidExpect', () => { const execResult = { text: 'hello', value: 1, - } + }; mockExecutor.executeResult = Promise.resolve(JSON.stringify(execResult)); const result = await e.element(e.by.id('UniqueId005')).getAttributes(); expect(result).toEqual(execResult); @@ -293,7 +293,7 @@ describe('AndroidExpect', () => { mockExecutor.executeResult = Promise.resolve(undefined); await e.web(e.by.id('webview_id')).element(e.by.web.id('any')).tap(); }); - }) + }); describe('web', () => { @@ -496,7 +496,7 @@ describe('AndroidExpect', () => { const webview = await e.web; await webview.element(e.by.web.id('id')).tap(); }); - }) + }); describe('Web Matchers',() => { it('by.web.id', async () => { diff --git a/detox/src/android/actions/native.js b/detox/src/android/actions/native.js index 9edf525ec4..cc9ba88774 100644 --- a/detox/src/android/actions/native.js +++ b/detox/src/android/actions/native.js @@ -1,9 +1,9 @@ const invoke = require('../../invoke'); +const { assertEnum, assertNormalized } = require('../../utils/assertArgument'); const DetoxActionApi = require('../espressoapi/DetoxAction'); -const ViewActionsApi = require('../espressoapi/ViewActions'); const DetoxViewActionsApi = require('../espressoapi/DetoxViewActions'); +const ViewActionsApi = require('../espressoapi/ViewActions'); -const { assertEnum, assertNormalized } = require('../../utils/assertArgument'); const assertDirection = assertEnum(['left', 'right', 'up', 'down']); const assertSpeed = assertEnum(['fast', 'slow']); diff --git a/detox/src/android/actions/web.js b/detox/src/android/actions/web.js index e6e2e544c8..af4c542de1 100644 --- a/detox/src/android/actions/web.js +++ b/detox/src/android/actions/web.js @@ -1,6 +1,6 @@ -const simpleAtoms = require('../espressoapi/web/simpleAtoms'); const WebElementApi = require('../espressoapi/web/WebElement'); const WebExpectApi = require('../espressoapi/web/WebExpect'); +const simpleAtoms = require('../espressoapi/web/simpleAtoms'); class WebAction { } diff --git a/detox/src/android/core/NativeElement.js b/detox/src/android/core/NativeElement.js index 176445ad63..5c5da7fea1 100644 --- a/detox/src/android/core/NativeElement.js +++ b/detox/src/android/core/NativeElement.js @@ -1,11 +1,13 @@ -const fs = require('fs-extra'); const path = require('path'); + +const fs = require('fs-extra'); const tempfile = require('tempfile'); + const DetoxRuntimeError = require('../../errors/DetoxRuntimeError'); const invoke = require('../../invoke'); +const actions = require('../actions/native'); const DetoxMatcherApi = require('../espressoapi/DetoxMatcher'); -const { ActionInteraction } = require('../interactions/native') -const actions = require('../actions/native') +const { ActionInteraction } = require('../interactions/native'); class NativeElement { constructor(invocationManager, emitter, matcher) { diff --git a/detox/src/android/core/NativeExpect.js b/detox/src/android/core/NativeExpect.js index 0836006815..1ff131e958 100644 --- a/detox/src/android/core/NativeExpect.js +++ b/detox/src/android/core/NativeExpect.js @@ -1,5 +1,5 @@ -const { MatcherAssertionInteraction } = require('../interactions/native') -const matchers = require('../matchers/native') +const { MatcherAssertionInteraction } = require('../interactions/native'); +const matchers = require('../matchers/native'); class NativeExpect { constructor(invocationManager) { diff --git a/detox/src/android/core/NativeWaitFor.js b/detox/src/android/core/NativeWaitFor.js index 7008ad7a41..1e2deeb84f 100644 --- a/detox/src/android/core/NativeWaitFor.js +++ b/detox/src/android/core/NativeWaitFor.js @@ -1,5 +1,5 @@ -const { WaitForInteraction } = require('../interactions/native') -const matchers = require('../matchers/native') +const { WaitForInteraction } = require('../interactions/native'); +const matchers = require('../matchers/native'); class NativeWaitFor { constructor(invocationManager) { diff --git a/detox/src/android/core/WebElement.js b/detox/src/android/core/WebElement.js index 63df8662a8..a7eae50cde 100644 --- a/detox/src/android/core/WebElement.js +++ b/detox/src/android/core/WebElement.js @@ -1,9 +1,10 @@ const DetoxRuntimeError = require('../../errors/DetoxRuntimeError'); const invoke = require('../../invoke'); +const actions = require('../actions/web'); const EspressoWebDetoxApi = require('../espressoapi/web/EspressoWebDetox'); const WebViewElementApi = require('../espressoapi/web/WebViewElement'); -const actions = require('../actions/web'); const { ActionInteraction } = require('../interactions/web'); + const { WebMatcher } = require('./WebMatcher'); const _device = Symbol('device'); diff --git a/detox/src/android/core/WebExpect.js b/detox/src/android/core/WebExpect.js index 89d5deeb88..570c76f3c1 100644 --- a/detox/src/android/core/WebExpect.js +++ b/detox/src/android/core/WebExpect.js @@ -1,11 +1,11 @@ const invoke = require('../../invoke'); -const EspressoWebDetoxApi = require('../espressoapi/web/EspressoWebDetox'); const { WebExistsAssertion, WebHasTextAssertion } = require('../actions/web'); +const EspressoWebDetoxApi = require('../espressoapi/web/EspressoWebDetox'); const { WebAssertionInteraction } = require('../interactions/web'); class WebExpect { constructor(invocationManager) { - this._invocationManager = invocationManager + this._invocationManager = invocationManager; this._notCondition = false; } @@ -17,7 +17,7 @@ class WebExpect { class WebExpectElement extends WebExpect { constructor(invocationManager, webElement) { - super(invocationManager) + super(invocationManager); this._call = invoke.callDirectly(EspressoWebDetoxApi.expect(webElement._call.value)); } diff --git a/detox/src/android/interactions/native.js b/detox/src/android/interactions/native.js index facbed13b8..69eda00ac6 100644 --- a/detox/src/android/interactions/native.js +++ b/detox/src/android/interactions/native.js @@ -1,8 +1,8 @@ const DetoxRuntimeError = require('../../errors/DetoxRuntimeError'); +const { ScrollAmountStopAtEdgeAction } = require('../actions/native'); +const { NativeMatcher } = require('../core/NativeMatcher'); const DetoxAssertionApi = require('../espressoapi/DetoxAssertion'); const EspressoDetoxApi = require('../espressoapi/EspressoDetox'); -const { NativeMatcher } = require('../core/NativeMatcher'); -const { ScrollAmountStopAtEdgeAction } = require('../actions/native'); function call(maybeAFunction) { return maybeAFunction instanceof Function ? maybeAFunction() : maybeAFunction; diff --git a/detox/src/android/matchers/native.js b/detox/src/android/matchers/native.js index 6db3eef09b..f26633389a 100644 --- a/detox/src/android/matchers/native.js +++ b/detox/src/android/matchers/native.js @@ -1,7 +1,7 @@ const DetoxRuntimeError = require('../../errors/DetoxRuntimeError'); const invoke = require('../../invoke'); -const DetoxMatcherApi = require('../espressoapi/DetoxMatcher'); const { NativeMatcher } = require('../core/NativeMatcher'); +const DetoxMatcherApi = require('../espressoapi/DetoxMatcher'); class LabelMatcher extends NativeMatcher { constructor(value) { @@ -64,7 +64,7 @@ class ToggleMatcher extends NativeMatcher { class TraitsMatcher extends NativeMatcher { constructor(value) { super(); - if ((typeof value !== 'object') || (!value instanceof Array)) throw new DetoxRuntimeError(`TraitsMatcher ctor argument must be an array, got ${typeof value}`); + if (!Array.isArray(value)) throw new DetoxRuntimeError(`TraitsMatcher ctor argument must be an array, got ${typeof value}`); this._call = invoke.callDirectly(DetoxMatcherApi.matcherForAnything()); } diff --git a/detox/src/android/matchers/web.js b/detox/src/android/matchers/web.js index b22f794e34..23a1afd189 100644 --- a/detox/src/android/matchers/web.js +++ b/detox/src/android/matchers/web.js @@ -1,6 +1,6 @@ const invoke = require('../../invoke'); -const DetoxWebMatcherApi = require('../espressoapi/web/DetoxWebAtomMatcher'); const { WebMatcher } = require('../core/WebMatcher'); +const DetoxWebMatcherApi = require('../espressoapi/web/DetoxWebAtomMatcher'); class IdMatcher extends WebMatcher { constructor(id) { diff --git a/detox/src/artifacts/ArtifactsManager.js b/detox/src/artifacts/ArtifactsManager.js index b35f9c296c..04403923ba 100644 --- a/detox/src/artifacts/ArtifactsManager.js +++ b/detox/src/artifacts/ArtifactsManager.js @@ -1,11 +1,14 @@ -const _ = require('lodash'); -const fs = require('fs-extra'); const path = require('path'); const util = require('util'); -const FileArtifact = require('./templates/artifact/FileArtifact'); + +const fs = require('fs-extra'); +const _ = require('lodash'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); const log = require('../utils/logger').child({ __filename }); +const FileArtifact = require('./templates/artifact/FileArtifact'); + class ArtifactsManager { constructor({ pathBuilder, plugins }) { this._pluginConfigs = plugins; @@ -238,7 +241,7 @@ class ArtifactsManager { plugin: caller, methodName: 'onIdleCallback', args: [] - }) + }); } } diff --git a/detox/src/artifacts/ArtifactsManager.test.js b/detox/src/artifacts/ArtifactsManager.test.js index 7c7ff4ecd1..914ac93586 100644 --- a/detox/src/artifacts/ArtifactsManager.test.js +++ b/detox/src/artifacts/ArtifactsManager.test.js @@ -1,5 +1,7 @@ const path = require('path'); + const sleep = require('../utils/sleep'); + const testSummaries = require('./__mocks__/testSummaries.mock'); const testSuite = require('./templates/plugin/__mocks__/testSuite.mock'); const testHookError = () => ({ hook: 'beforeEach', error: new Error() }); diff --git a/detox/src/artifacts/instruments/android/AndroidInstrumentsPlugin.js b/detox/src/artifacts/instruments/android/AndroidInstrumentsPlugin.js index 50470d5156..f259d0d6eb 100644 --- a/detox/src/artifacts/instruments/android/AndroidInstrumentsPlugin.js +++ b/detox/src/artifacts/instruments/android/AndroidInstrumentsPlugin.js @@ -1,4 +1,5 @@ const InstrumentsArtifactPlugin = require('../InstrumentsArtifactPlugin'); + const AndroidInstrumentsRecording = require('./AndroidInstrumentsRecording'); class AndroidInstrumentsPlugin extends InstrumentsArtifactPlugin { diff --git a/detox/src/artifacts/instruments/ios/SimulatorInstrumentsPlugin.js b/detox/src/artifacts/instruments/ios/SimulatorInstrumentsPlugin.js index 64f0bd9d5f..d1d5ffb8da 100644 --- a/detox/src/artifacts/instruments/ios/SimulatorInstrumentsPlugin.js +++ b/detox/src/artifacts/instruments/ios/SimulatorInstrumentsPlugin.js @@ -1,10 +1,11 @@ +const temporaryPath = require('../../utils/temporaryPath'); const InstrumentsArtifactPlugin = require('../InstrumentsArtifactPlugin'); + const SimulatorInstrumentsRecording = require('./SimulatorInstrumentsRecording'); -const temporaryPath = require('../../utils/temporaryPath'); class SimulatorInstrumentsPlugin extends InstrumentsArtifactPlugin { - constructor({api, client}) { - super({api}); + constructor({ api, client }) { + super({ api }); this.client = client; } diff --git a/detox/src/artifacts/instruments/ios/SimulatorInstrumentsPlugin.test.js b/detox/src/artifacts/instruments/ios/SimulatorInstrumentsPlugin.test.js index 0cae390f94..7734e0d283 100644 --- a/detox/src/artifacts/instruments/ios/SimulatorInstrumentsPlugin.test.js +++ b/detox/src/artifacts/instruments/ios/SimulatorInstrumentsPlugin.test.js @@ -1,6 +1,7 @@ -const SimulatorInstrumentsPlugin = require('./SimulatorInstrumentsPlugin'); const temporaryPath = require('../../utils/temporaryPath'); +const SimulatorInstrumentsPlugin = require('./SimulatorInstrumentsPlugin'); + jest.mock('../../utils/temporaryPath'); describe('SimulatorInstrumentsPlugin', () => { @@ -36,7 +37,7 @@ describe('SimulatorInstrumentsPlugin', () => { launchArgs: {} }; await plugin.onBeforeLaunchApp(event); - expect(event.launchArgs.recordingPath).toBeUndefined() + expect(event.launchArgs.recordingPath).toBeUndefined(); }); it('should build launchArgs with empty config', async () => { diff --git a/detox/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js b/detox/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js index 68d1ec06b9..2def94bdb6 100644 --- a/detox/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js +++ b/detox/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js @@ -1,8 +1,9 @@ -const _ = require('lodash'); const fs = require('fs-extra'); +const _ = require('lodash'); + const log = require('../../../utils/logger').child({ __filename }); -const InstrumentsArtifactRecording = require('../InstrumentsArtifactRecording'); const FileArtifact = require('../../templates/artifact/FileArtifact'); +const InstrumentsArtifactRecording = require('../InstrumentsArtifactRecording'); class SimulatorInstrumentsRecording extends InstrumentsArtifactRecording { constructor({ pluginContext, client, userConfig, temporaryRecordingPath }) { diff --git a/detox/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.test.js b/detox/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.test.js index 0013f6fe9a..a85e9d088f 100644 --- a/detox/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.test.js +++ b/detox/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.test.js @@ -1,8 +1,9 @@ const fs = require('fs-extra'); -const SimulatorInstrumentsRecording = require('./SimulatorInstrumentsRecording'); -const FileArtifact = require('../../templates/artifact/FileArtifact'); const log = require('../../../utils/logger'); +const FileArtifact = require('../../templates/artifact/FileArtifact'); + +const SimulatorInstrumentsRecording = require('./SimulatorInstrumentsRecording'); jest.mock('fs-extra'); jest.mock('../../templates/artifact/FileArtifact'); diff --git a/detox/src/artifacts/log/android/ADBLogcatPlugin.js b/detox/src/artifacts/log/android/ADBLogcatPlugin.js index 8ed385ec9a..00a69356f6 100644 --- a/detox/src/artifacts/log/android/ADBLogcatPlugin.js +++ b/detox/src/artifacts/log/android/ADBLogcatPlugin.js @@ -1,4 +1,5 @@ const LogArtifactPlugin = require('../LogArtifactPlugin'); + const ADBLogcatRecording = require('./ADBLogcatRecording'); class ADBLogcatPlugin extends LogArtifactPlugin { diff --git a/detox/src/artifacts/log/android/ADBLogcatRecording.js b/detox/src/artifacts/log/android/ADBLogcatRecording.js index af23a0458d..dd9669dc22 100644 --- a/detox/src/artifacts/log/android/ADBLogcatRecording.js +++ b/detox/src/artifacts/log/android/ADBLogcatRecording.js @@ -1,9 +1,9 @@ -const Artifact = require('../../templates/artifact/Artifact'); const DetoxRuntimeError = require('../../../errors/DetoxRuntimeError'); const { interruptProcess } = require('../../../utils/exec'); const log = require('../../../utils/logger').child({ __filename }); const retry = require('../../../utils/retry'); const sleep = require('../../../utils/sleep'); +const Artifact = require('../../templates/artifact/Artifact'); class ADBLogcatRecording extends Artifact { constructor({ diff --git a/detox/src/artifacts/log/ios/SimulatorLogPlugin.js b/detox/src/artifacts/log/ios/SimulatorLogPlugin.js index eb48170f9f..55c12d0e2f 100644 --- a/detox/src/artifacts/log/ios/SimulatorLogPlugin.js +++ b/detox/src/artifacts/log/ios/SimulatorLogPlugin.js @@ -1,6 +1,8 @@ const _ = require('lodash'); + const temporaryPath = require('../../utils/temporaryPath'); const LogArtifactPlugin = require('../LogArtifactPlugin'); + const SimulatorLogRecording = require('./SimulatorLogRecording'); class SimulatorLogPlugin extends LogArtifactPlugin { diff --git a/detox/src/artifacts/log/ios/SimulatorLogPlugin.test.js b/detox/src/artifacts/log/ios/SimulatorLogPlugin.test.js index 58d11021b9..a2d3c912b3 100644 --- a/detox/src/artifacts/log/ios/SimulatorLogPlugin.test.js +++ b/detox/src/artifacts/log/ios/SimulatorLogPlugin.test.js @@ -1,10 +1,12 @@ jest.mock('../../../utils/logger'); +const path = require('path'); + +const fs = require('fs-extra'); const _ = require('lodash'); const tempfile = require('tempfile'); -const fs = require('fs-extra'); + const exec = require('../../../utils/exec'); -const path = require('path'); describe('SimulatorLogPlugin', () => { async function majorWorkflow() { @@ -69,7 +71,7 @@ describe('SimulatorLogPlugin', () => { api, appleSimUtils: fakeAppleSimUtils, }), - }) + }); } async function logToDeviceLogs(line) { @@ -86,7 +88,7 @@ describe('SimulatorLogPlugin', () => { await artifactsManager.onLaunchApp({ device: 'booted', bundleId: 'com.test', pid: 8000 }); await logToDeviceLogs('omit - after launch inside detox.init()'); - await artifactsManager.onTestStart({ title: 'test', fullName: 'some test', status: 'running'}); + await artifactsManager.onTestStart({ title: 'test', fullName: 'some test', status: 'running' }); await logToDeviceLogs('take - before relaunch inside test'); await artifactsManager.onBeforeLaunchApp({ device: 'booted', bundleId: 'com.test' }); @@ -94,7 +96,7 @@ describe('SimulatorLogPlugin', () => { await artifactsManager.onLaunchApp({ device: 'booted', bundleId: 'com.test', pid: 8001 }); await logToDeviceLogs('take - after relaunch inside test'); - await artifactsManager.onTestDone({ title: 'test', fullName: 'some test', status: 'passed'}); + await artifactsManager.onTestDone({ title: 'test', fullName: 'some test', status: 'passed' }); await logToDeviceLogs('omit - before cleanup'); await artifactsManager.onBeforeCleanup(); diff --git a/detox/src/artifacts/log/ios/SimulatorLogRecording.js b/detox/src/artifacts/log/ios/SimulatorLogRecording.js index 2a35a28c5c..985a4695cb 100644 --- a/detox/src/artifacts/log/ios/SimulatorLogRecording.js +++ b/detox/src/artifacts/log/ios/SimulatorLogRecording.js @@ -1,7 +1,8 @@ const fs = require('fs-extra'); + +const exec = require('../../../utils/exec'); const log = require('../../../utils/logger').child({ __filename }); const sleep = require('../../../utils/sleep'); -const exec = require('../../../utils/exec'); const Artifact = require('../../templates/artifact/Artifact'); const FileArtifact = require('../../templates/artifact/FileArtifact'); diff --git a/detox/src/artifacts/screenshot/ADBScreencapPlugin.js b/detox/src/artifacts/screenshot/ADBScreencapPlugin.js index 7d4ce9f780..19b59d787f 100644 --- a/detox/src/artifacts/screenshot/ADBScreencapPlugin.js +++ b/detox/src/artifacts/screenshot/ADBScreencapPlugin.js @@ -1,6 +1,7 @@ -const ScreenshotArtifactPlugin = require('./ScreenshotArtifactPlugin'); const Artifact = require('../templates/artifact/Artifact'); +const ScreenshotArtifactPlugin = require('./ScreenshotArtifactPlugin'); + class ADBScreencapPlugin extends ScreenshotArtifactPlugin { constructor(config) { super(config); diff --git a/detox/src/artifacts/screenshot/ScreenshotArtifactPlugin.js b/detox/src/artifacts/screenshot/ScreenshotArtifactPlugin.js index 8726809340..041820c11e 100644 --- a/detox/src/artifacts/screenshot/ScreenshotArtifactPlugin.js +++ b/detox/src/artifacts/screenshot/ScreenshotArtifactPlugin.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const TwoSnapshotsPerTestPlugin = require('../templates/plugin/TwoSnapshotsPerTestPlugin'); /*** @@ -10,7 +11,7 @@ class ScreenshotArtifactPlugin extends TwoSnapshotsPerTestPlugin { _.defaults(this.takeAutomaticSnapshots, { appNotReady: true, - }) + }); } async preparePathForSnapshot(testSummary, name) { diff --git a/detox/src/artifacts/screenshot/SimulatorScreenshotPlugin.js b/detox/src/artifacts/screenshot/SimulatorScreenshotPlugin.js index 27e76a98cc..9b4c576d6f 100644 --- a/detox/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +++ b/detox/src/artifacts/screenshot/SimulatorScreenshotPlugin.js @@ -1,8 +1,10 @@ -const _ = require('lodash'); const fs = require('fs-extra'); +const _ = require('lodash'); + const log = require('../../utils/logger').child({ __filename }); -const temporaryPath = require('../utils/temporaryPath'); const FileArtifact = require('../templates/artifact/FileArtifact'); +const temporaryPath = require('../utils/temporaryPath'); + const ScreenshotArtifactPlugin = require('./ScreenshotArtifactPlugin'); class SimulatorScreenshotPlugin extends ScreenshotArtifactPlugin { diff --git a/detox/src/artifacts/templates/artifact/Artifact.test.js b/detox/src/artifacts/templates/artifact/Artifact.test.js index 9a33c17b7b..15bdc597e2 100644 --- a/detox/src/artifacts/templates/artifact/Artifact.test.js +++ b/detox/src/artifacts/templates/artifact/Artifact.test.js @@ -1,7 +1,9 @@ jest.mock('../../../utils/logger'); -const _ = require('lodash'); const util = require('util'); + +const _ = require('lodash'); + const Artifact = require('./Artifact'); describe('Artifact', () => { diff --git a/detox/src/artifacts/templates/artifact/FileArtifact.js b/detox/src/artifacts/templates/artifact/FileArtifact.js index 3a7b41b963..a73a20f56f 100644 --- a/detox/src/artifacts/templates/artifact/FileArtifact.js +++ b/detox/src/artifacts/templates/artifact/FileArtifact.js @@ -1,7 +1,9 @@ const fs = require('fs-extra'); -const Artifact = require('./Artifact'); + const appendFile = require('../../../utils/appendFile'); +const Artifact = require('./Artifact'); + class FileArtifact extends Artifact { constructor(template) { super(template); @@ -26,26 +28,26 @@ class FileArtifact extends Artifact { static async writeFile(logger, data, destination, canAppend = false) { if (!data) { - logger.warn({event: 'FILE_WRITE_EMPTY_DATA'}, `there is no data to write to "${destination}"`); + logger.warn({ event: 'FILE_WRITE_EMPTY_DATA' }, `there is no data to write to "${destination}"`); return false; } if (!await fs.exists(destination)) { - logger.debug({event: 'FILE_WRITE_CREATE'}, `creating file "${destination}"`) + logger.debug({ event: 'FILE_WRITE_CREATE' }, `creating file "${destination}"`); } else if (!canAppend) { - logger.warn({event: 'FILE_WRITE_EXISTS'}, `cannot overwrite "${destination}"`); + logger.warn({ event: 'FILE_WRITE_EXISTS' }, `cannot overwrite "${destination}"`); return false; } if (canAppend) { - logger.debug({event: 'FILE_WRITE'}, `writing to "${destination}" via appending`); + logger.debug({ event: 'FILE_WRITE' }, `writing to "${destination}" via appending`); await fs.appendFile(destination, data); return true; } else { - logger.debug({event: 'FILE_WRITE'}, `writing to "${destination}"`); + logger.debug({ event: 'FILE_WRITE' }, `writing to "${destination}"`); await fs.writeFile(destination, data); return true; @@ -54,28 +56,27 @@ class FileArtifact extends Artifact { static async moveTemporaryFile(logger, source, destination, canAppend = false) { if (!await fs.exists(source)) { - logger.warn({event: 'MOVE_FILE_MISSING'}, `did not find temporary file: ${source}`); + logger.warn({ event: 'MOVE_FILE_MISSING' }, `did not find temporary file: ${source}`); return false; } if (!await fs.exists(destination)) { - logger.debug({event: 'MOVE_FILE'}, `moving "${source}" to ${destination}`); + logger.debug({ event: 'MOVE_FILE' }, `moving "${source}" to ${destination}`); await fs.move(source, destination); return true; } if (canAppend) { - logger.debug({event: 'MOVE_FILE'}, `moving "${source}" to ${destination} via appending`); + logger.debug({ event: 'MOVE_FILE' }, `moving "${source}" to ${destination} via appending`); await appendFile(source, destination); await fs.remove(source); return true; } - logger.warn({event: 'MOVE_FILE_EXISTS'}, `cannot overwrite: "${source}" => "${destination}"`); + logger.warn({ event: 'MOVE_FILE_EXISTS' }, `cannot overwrite: "${source}" => "${destination}"`); await fs.remove(source); return false; } } - module.exports = FileArtifact; diff --git a/detox/src/artifacts/templates/artifact/FileArtifact.test.js b/detox/src/artifacts/templates/artifact/FileArtifact.test.js index dfa80e7edf..42e0bd7c54 100644 --- a/detox/src/artifacts/templates/artifact/FileArtifact.test.js +++ b/detox/src/artifacts/templates/artifact/FileArtifact.test.js @@ -1,5 +1,5 @@ -const _ = require('lodash'); const fs = require('fs-extra'); +const _ = require('lodash'); const tempfile = require('tempfile'); describe('FileArtifact', () => { @@ -48,7 +48,7 @@ describe('FileArtifact', () => { describe('when called with { append: true }', () => { beforeEach(async () => { - await fileArtifact.save(destinationPath, {append: true}); + await fileArtifact.save(destinationPath, { append: true }); }); it('should call FileArtifact.moveTemporaryFile with extra param', async () => { @@ -111,7 +111,7 @@ describe('FileArtifact', () => { describe('when called with { append: true }', () => { beforeEach(async () => { - await fileArtifact.save(destinationPath, {append: true}); + await fileArtifact.save(destinationPath, { append: true }); }); it('should call FileArtifact.moveTemporaryFile with extra param', async () => { @@ -226,7 +226,7 @@ describe('FileArtifact', () => { expect(result).toBe(false); expect(await fs.readFile(destinationPath, 'utf8')).toBe('Hello'); - expect(logger.warn).toHaveBeenCalledWith({event: 'FILE_WRITE_EMPTY_DATA'}, expect.any(String)); + expect(logger.warn).toHaveBeenCalledWith({ event: 'FILE_WRITE_EMPTY_DATA' }, expect.any(String)); }); }); @@ -240,7 +240,7 @@ describe('FileArtifact', () => { const result = await FileArtifact.writeFile(logger, temporaryData, destinationPath); expect(result).toBe(true); - expect(logger.debug).toHaveBeenCalledWith({event: 'FILE_WRITE_CREATE'}, expect.any(String)); + expect(logger.debug).toHaveBeenCalledWith({ event: 'FILE_WRITE_CREATE' }, expect.any(String)); }); it('should create the file', async () => { @@ -263,7 +263,7 @@ describe('FileArtifact', () => { const result = await FileArtifact.writeFile(logger, temporaryData, destinationPath); expect(result).toBe(false); - expect(logger.warn).toHaveBeenCalledWith({event: 'FILE_WRITE_EXISTS'}, expect.any(String)); + expect(logger.warn).toHaveBeenCalledWith({ event: 'FILE_WRITE_EXISTS' }, expect.any(String)); }); }); @@ -273,7 +273,7 @@ describe('FileArtifact', () => { expect(result).toBe(true); expect(await fs.readFile(destinationPath, 'utf8')).toBe(fileContent + temporaryData); - expect(logger.debug).toHaveBeenCalledWith({event: 'FILE_WRITE'}, expect.any(String)); + expect(logger.debug).toHaveBeenCalledWith({ event: 'FILE_WRITE' }, expect.any(String)); }); }); }); diff --git a/detox/src/artifacts/templates/plugin/ArtifactPlugin.js b/detox/src/artifacts/templates/plugin/ArtifactPlugin.js index 5a7eaae17a..f42c6c4a4f 100644 --- a/detox/src/artifacts/templates/plugin/ArtifactPlugin.js +++ b/detox/src/artifacts/templates/plugin/ArtifactPlugin.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const log = require('../../../utils/logger').child({ __filename }); /*** @@ -11,7 +12,7 @@ const log = require('../../../utils/logger').child({ __filename }); class ArtifactPlugin { constructor({ api }) { this.api = api; - this.context = { testSummary: null , suite: null}; + this.context = { testSummary: null , suite: null }; this.enabled = api.userConfig.enabled; this.keepOnlyFailedTestsArtifacts = api.userConfig.keepOnlyFailedTestsArtifacts; this.priority = 16; diff --git a/detox/src/artifacts/templates/plugin/ArtifactPlugin.test.js b/detox/src/artifacts/templates/plugin/ArtifactPlugin.test.js index 9fba1b49f4..d0a9bc4828 100644 --- a/detox/src/artifacts/templates/plugin/ArtifactPlugin.test.js +++ b/detox/src/artifacts/templates/plugin/ArtifactPlugin.test.js @@ -1,8 +1,9 @@ jest.mock('../../../utils/logger'); const logger = require('../../../utils/logger'); -const ArtifactPlugin = require('./ArtifactPlugin'); -const FileArtifact = require('../artifact/FileArtifact'); const testSummaries = require('../../__mocks__/testSummaries.mock'); +const FileArtifact = require('../artifact/FileArtifact'); + +const ArtifactPlugin = require('./ArtifactPlugin'); const testSuite = require('./__mocks__/testSuite.mock'); class TestArtifactPlugin extends ArtifactPlugin {} @@ -269,7 +270,7 @@ describe('ArtifactPlugin', () => { it('should disable plugin with a reason', async () => { plugin.disable = jest.fn(); await expect(plugin.onTerminate()).resolves.toBe(void 0); - expect(plugin.disable.mock.calls).toEqual([["it was terminated by SIGINT or SIGTERM"]]); + expect(plugin.disable.mock.calls).toEqual([['it was terminated by SIGINT or SIGTERM']]); }); it('should replace the other lifecycle hooks with the same noop function', async () => { diff --git a/detox/src/artifacts/templates/plugin/StartupAndTestRecorderPlugin.test.js b/detox/src/artifacts/templates/plugin/StartupAndTestRecorderPlugin.test.js index a1669394ed..f598596e87 100644 --- a/detox/src/artifacts/templates/plugin/StartupAndTestRecorderPlugin.test.js +++ b/detox/src/artifacts/templates/plugin/StartupAndTestRecorderPlugin.test.js @@ -1,9 +1,10 @@ jest.mock('../../../utils/logger.js'); -const StartupAndTestRecorderPlugin = require('./StartupAndTestRecorderPlugin'); -const ArtifactsApi = require('./__mocks__/ArtifactsApi.mock'); const testSummaries = require('../../__mocks__/testSummaries.mock'); const ArtifactMock = require('../artifact/__mocks__/ArtifactMock'); +const StartupAndTestRecorderPlugin = require('./StartupAndTestRecorderPlugin'); +const ArtifactsApi = require('./__mocks__/ArtifactsApi.mock'); + describe('StartupAndTestRecorderPlugin', () => { let api; let plugin; @@ -269,7 +270,7 @@ describe('StartupAndTestRecorderPlugin', () => { }); itShouldScheduleDiscardingAndUntrackingOfStartupArtifact(); - }) + }); }); }); diff --git a/detox/src/artifacts/templates/plugin/TwoSnapshotsPerTestPlugin.js b/detox/src/artifacts/templates/plugin/TwoSnapshotsPerTestPlugin.js index 4d75112de0..b3e07a352f 100644 --- a/detox/src/artifacts/templates/plugin/TwoSnapshotsPerTestPlugin.js +++ b/detox/src/artifacts/templates/plugin/TwoSnapshotsPerTestPlugin.js @@ -1,4 +1,5 @@ const DetoxRuntimeError = require('../../../errors/DetoxRuntimeError'); + const ArtifactPlugin = require('./ArtifactPlugin'); /*** @@ -85,7 +86,6 @@ class TwoSnapshotsPerTestPlugin extends ArtifactPlugin { */ async preparePathForSnapshot(testSummary, snapshotName) {} - /*** * Creates a handle for a test artifact (video recording, log, etc.) * @@ -121,7 +121,7 @@ class TwoSnapshotsPerTestPlugin extends ArtifactPlugin { } _startSavingSnapshots(where) { - const {testSummary} = this.context; + const { testSummary } = this.context; const snapshots = this.snapshots[where]; for (const [name, snapshot] of Object.entries(snapshots)) { diff --git a/detox/src/artifacts/templates/plugin/TwoSnapshotsPerTestPlugin.test.js b/detox/src/artifacts/templates/plugin/TwoSnapshotsPerTestPlugin.test.js index c203279a33..2f7ba6c91c 100644 --- a/detox/src/artifacts/templates/plugin/TwoSnapshotsPerTestPlugin.test.js +++ b/detox/src/artifacts/templates/plugin/TwoSnapshotsPerTestPlugin.test.js @@ -1,8 +1,9 @@ jest.mock('../../../utils/logger.js'); -const TwoSnapshotsPerTestPlugin = require('./TwoSnapshotsPerTestPlugin'); +const testSummaries = require('../../__mocks__/testSummaries.mock'); const ArtifactMock = require('../artifact/__mocks__/ArtifactMock'); + +const TwoSnapshotsPerTestPlugin = require('./TwoSnapshotsPerTestPlugin'); const ArtifactsApi = require('./__mocks__/ArtifactsApi.mock'); -const testSummaries = require('../../__mocks__/testSummaries.mock'); describe('TwoSnapshotsPerTestPlugin', () => { let api; @@ -253,7 +254,7 @@ describe('TwoSnapshotsPerTestPlugin', () => { describe('onCreateExternalArtifact', () => { it('should throw error if { artifact } is not defined', async () => { - await expect(plugin.onCreateExternalArtifact({ name: 'Hello'})).rejects.toThrowError(); + await expect(plugin.onCreateExternalArtifact({ name: 'Hello' })).rejects.toThrowError(); }); it('should set snapshot in key-value map and track it', async () => { diff --git a/detox/src/artifacts/templates/plugin/WholeTestRecorderPlugin.js b/detox/src/artifacts/templates/plugin/WholeTestRecorderPlugin.js index de6d2e332a..0554638684 100644 --- a/detox/src/artifacts/templates/plugin/WholeTestRecorderPlugin.js +++ b/detox/src/artifacts/templates/plugin/WholeTestRecorderPlugin.js @@ -27,7 +27,7 @@ class WholeTestRecorderPlugin extends ArtifactPlugin { await testRecording.stop(); if (this.shouldKeepArtifactOfTest(testSummary)) { - this._startSavingTestRecording(testRecording, testSummary) + this._startSavingTestRecording(testRecording, testSummary); } else { this._startDiscardingTestRecording(testRecording); } diff --git a/detox/src/artifacts/templates/plugin/WholeTestRecorderPlugin.test.js b/detox/src/artifacts/templates/plugin/WholeTestRecorderPlugin.test.js index 687e2f0cea..8568543d99 100644 --- a/detox/src/artifacts/templates/plugin/WholeTestRecorderPlugin.test.js +++ b/detox/src/artifacts/templates/plugin/WholeTestRecorderPlugin.test.js @@ -1,7 +1,8 @@ jest.mock('../../../utils/logger.js'); +const testSummaries = require('../../__mocks__/testSummaries.mock'); + const WholeTestRecorderPlugin = require('./WholeTestRecorderPlugin'); const ArtifactsApi = require('./__mocks__/ArtifactsApi.mock'); -const testSummaries = require('../../__mocks__/testSummaries.mock'); describe('WholeTestRecorderPlugin', () => { let api; @@ -86,7 +87,7 @@ describe('WholeTestRecorderPlugin', () => { expect(plugin.createdArtifacts[0].save).toBeCalledWith('/tmp/test/fakeArtifact'); expect(api.untrackArtifact).toBeCalledWith(plugin.createdArtifacts[0]); - }) + }); }); }); @@ -118,7 +119,7 @@ describe('WholeTestRecorderPlugin', () => { expect(plugin.createdArtifacts[0].discard).toBeCalled(); expect(api.untrackArtifact).toBeCalledWith(plugin.createdArtifacts[0]); - }) + }); }); }); }); diff --git a/detox/src/artifacts/templates/plugin/__mocks__/testSuite.mock.js b/detox/src/artifacts/templates/plugin/__mocks__/testSuite.mock.js index 3878cdfaed..652a8f1158 100644 --- a/detox/src/artifacts/templates/plugin/__mocks__/testSuite.mock.js +++ b/detox/src/artifacts/templates/plugin/__mocks__/testSuite.mock.js @@ -1,3 +1,3 @@ -const mock = () => ({name: 'testSuiteName'}); +const mock = () => ({ name: 'testSuiteName' }); -module.exports = {mock}; +module.exports = { mock }; diff --git a/detox/src/artifacts/timeline/TimelineArtifactPlugin.js b/detox/src/artifacts/timeline/TimelineArtifactPlugin.js index 3e57bcefe5..f5a5d1286d 100644 --- a/detox/src/artifacts/timeline/TimelineArtifactPlugin.js +++ b/detox/src/artifacts/timeline/TimelineArtifactPlugin.js @@ -1,10 +1,11 @@ -const _noop = require('lodash/noop'); const fs = require('fs-extra'); -const ArtifactPlugin = require('../templates/plugin/ArtifactPlugin'); -const FileArtifact = require('../templates/artifact/FileArtifact'); -const { trace } = require('../../utils/trace'); +const _noop = require('lodash/noop'); + const ChromeTracingExporter = require('../../utils/ChromeTracingExporter'); const fakeTimestampsProvider = require('../../utils/fakeTimestampsProvider'); +const { trace } = require('../../utils/trace'); +const FileArtifact = require('../templates/artifact/FileArtifact'); +const ArtifactPlugin = require('../templates/plugin/ArtifactPlugin'); const traceNoop = { startSection: _noop, @@ -47,7 +48,7 @@ class TimelineArtifactPlugin extends ArtifactPlugin { } async onTestDone(testSummary) { - this._trace.endSection(testSummary.title, {status: testSummary.status}); + this._trace.endSection(testSummary.title, { status: testSummary.status }); await super.onTestDone(testSummary); } diff --git a/detox/src/artifacts/timeline/TimelineArtifactPlugin.test.js b/detox/src/artifacts/timeline/TimelineArtifactPlugin.test.js index d75e1cb49a..7e50441e30 100644 --- a/detox/src/artifacts/timeline/TimelineArtifactPlugin.test.js +++ b/detox/src/artifacts/timeline/TimelineArtifactPlugin.test.js @@ -2,7 +2,7 @@ const _ = require('lodash'); const latestInstanceOf = (clazz) => _.last(clazz.mock.instances); describe('TimelineArtifactPlugin', () => { - const configMock = ({enabled = true} = {}) => ({ + const configMock = ({ enabled = true } = {}) => ({ api: { userConfig: { enabled, @@ -243,8 +243,8 @@ describe('TimelineArtifactPlugin', () => { it('should use trace events as inpute to data exporter', async () => { trace.events = [ - { name: 'mock-event', type: 'start', ts: 1234}, - { name: 'mock-event', type: 'end', ts: 1235}, + { name: 'mock-event', type: 'start', ts: 1234 }, + { name: 'mock-event', type: 'end', ts: 1235 }, ]; const uut = uutEnabled(); @@ -279,14 +279,14 @@ describe('TimelineArtifactPlugin', () => { it('should rewrite the timeline events with fake (deterministic) timestamps', async () => { const events = [ - { type: 'init', ts: 1233}, - { name: 'mock-event', type: 'start', ts: 1234}, - { name: 'mock-event', type: 'end', ts: 1235}, + { type: 'init', ts: 1233 }, + { name: 'mock-event', type: 'start', ts: 1234 }, + { name: 'mock-event', type: 'end', ts: 1235 }, ]; const expectedEvents = [ - { type: 'init', ts: 1000}, - { name: 'mock-event', type: 'start', ts: 1100}, - { name: 'mock-event', type: 'end', ts: 1200}, + { type: 'init', ts: 1000 }, + { name: 'mock-event', type: 'start', ts: 1100 }, + { name: 'mock-event', type: 'end', ts: 1200 }, ]; trace.events = events; diff --git a/detox/src/artifacts/uiHierarchy/IosUIHierarchyPlugin.js b/detox/src/artifacts/uiHierarchy/IosUIHierarchyPlugin.js index 9b3a706481..f364c5816e 100644 --- a/detox/src/artifacts/uiHierarchy/IosUIHierarchyPlugin.js +++ b/detox/src/artifacts/uiHierarchy/IosUIHierarchyPlugin.js @@ -1,9 +1,10 @@ const _ = require('lodash'); + const Client = require('../../client/Client'); -const ArtifactPlugin = require('../templates/plugin/ArtifactPlugin'); -const FileArtifact = require('../templates/artifact/FileArtifact'); const DetoxRuntimeError = require('../../errors/DetoxRuntimeError'); const setUniqueProperty = require('../../utils/setUniqueProperty'); +const FileArtifact = require('../templates/artifact/FileArtifact'); +const ArtifactPlugin = require('../templates/plugin/ArtifactPlugin'); class IosUIHierarchyPlugin extends ArtifactPlugin { /** @@ -89,7 +90,7 @@ class IosUIHierarchyPlugin extends ArtifactPlugin { const pendingDeletions = this._pendingDeletions.splice(0); this._artifacts[scope] = _.mapValues(artifacts, _.constant(null)); - await Promise.all([...pendingSaves, ...pendingDeletions ]); + await Promise.all([...pendingSaves, ...pendingDeletions]); } /** @param {string} config */ diff --git a/detox/src/artifacts/utils/ArtifactPathBuilder.js b/detox/src/artifacts/utils/ArtifactPathBuilder.js index dae4562047..842cd293e1 100644 --- a/detox/src/artifacts/utils/ArtifactPathBuilder.js +++ b/detox/src/artifacts/utils/ArtifactPathBuilder.js @@ -1,4 +1,5 @@ const path = require('path'); + const constructSafeFilename = require('../../utils/constructSafeFilename'); class ArtifactPathBuilder { diff --git a/detox/src/artifacts/utils/ArtifactPathBuilder.test.js b/detox/src/artifacts/utils/ArtifactPathBuilder.test.js index 90660dfd81..70a938cc6f 100644 --- a/detox/src/artifacts/utils/ArtifactPathBuilder.test.js +++ b/detox/src/artifacts/utils/ArtifactPathBuilder.test.js @@ -1,5 +1,7 @@ -const _ = require('lodash'); const path = require('path'); + +const _ = require('lodash'); + const ArtifactPathBuilder = require('./ArtifactPathBuilder'); describe(ArtifactPathBuilder, () => { @@ -13,7 +15,7 @@ describe(ArtifactPathBuilder, () => { }); it('should give paths inside a timestamp-based subdirectory inside artifacts root', () => { - expect(pathBuilder.rootDir).toBe('/tmp') + expect(pathBuilder.rootDir).toBe('/tmp'); }); it('should provide path for unique (per test runner run) artifacts', () => { @@ -24,7 +26,7 @@ describe(ArtifactPathBuilder, () => { }); it('should provide nested path for test artifact', () => { - const test1 = {title: 'test 1', fullName: 'some test 1', status: 'running' }; + const test1 = { title: 'test 1', fullName: 'some test 1', status: 'running' }; const artifactPath1 = pathBuilder.buildPathForTestArtifact('1.log', test1); const expectedPath1 = path.join(pathBuilder.rootDir, test1.fullName, '1.log'); @@ -61,28 +63,28 @@ describe(ArtifactPathBuilder, () => { }); it('should prepend checkmark to an artifact of a passed test', () => { - const testSummary = {title: '', fullName: 'test', status: 'passed' }; + const testSummary = { title: '', fullName: 'test', status: 'passed' }; const artifactPath = pathBuilder.buildPathForTestArtifact('1.log', testSummary); expect(asPosixPath(artifactPath)).toBe('/tmp/subdir/✓ test/1.log'); }); it('should prepend x sign to an artifact of a failed test', () => { - const testSummary = {title: '', fullName: 'test', status: 'failed' }; + const testSummary = { title: '', fullName: 'test', status: 'failed' }; const artifactPath = pathBuilder.buildPathForTestArtifact('1.log', testSummary); expect(asPosixPath(artifactPath)).toBe('/tmp/subdir/✗ test/1.log'); }); it('should append (2) invocations count for a test that fails for the second time', () => { - const testSummary = {title: '', fullName: 'test', status: 'failed', invocations: 2 }; + const testSummary = { title: '', fullName: 'test', status: 'failed', invocations: 2 }; const artifactPath = pathBuilder.buildPathForTestArtifact('1.log', testSummary); expect(asPosixPath(artifactPath)).toBe('/tmp/subdir/✗ test (2)/1.log'); }); it('should append (3) invocations count for a test that passes for the third time', () => { - const testSummary = {title: '', fullName: 'test', status: 'passed', invocations: 3 }; + const testSummary = { title: '', fullName: 'test', status: 'passed', invocations: 3 }; const artifactPath = pathBuilder.buildPathForTestArtifact('1.log', testSummary); expect(asPosixPath(artifactPath)).toBe('/tmp/subdir/✓ test (3)/1.log'); diff --git a/detox/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js b/detox/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js index 72b68f8d87..0a46eb98df 100644 --- a/detox/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js +++ b/detox/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js @@ -1,4 +1,5 @@ const path = require('path'); + const getTimeStampString = require('./getTimeStampString'); function buildDefaultRootForArtifactsRootDirpath(configuration, rootDir) { diff --git a/detox/src/artifacts/utils/buildDefaultArtifactsRootDirpath.test.js b/detox/src/artifacts/utils/buildDefaultArtifactsRootDirpath.test.js index 5fb825f08e..e88214d024 100644 --- a/detox/src/artifacts/utils/buildDefaultArtifactsRootDirpath.test.js +++ b/detox/src/artifacts/utils/buildDefaultArtifactsRootDirpath.test.js @@ -1,4 +1,5 @@ const path = require('path'); + const buildDefaultArtifactsRootDirpath = require('./buildDefaultArtifactsRootDirpath'); describe('buildDefaultArtifactsRootDirpath', () => { @@ -16,7 +17,7 @@ describe('buildDefaultArtifactsRootDirpath', () => { it('should fall back to Date.now if environment variable DETOX_START_TIMESTAMP is unset', () => { delete process.env.DETOX_START_TIMESTAMP; - expect(buildDefaultArtifactsRootDirpath('iphone8', 'artifacts')).toMatch(/^artifacts[\\\/]iphone8\.\d{4}-\d{2}-\d{2} \d{2}-\d{2}-\d{2}Z$/); + expect(buildDefaultArtifactsRootDirpath('iphone8', 'artifacts')).toMatch(/^artifacts[\\/]iphone8\.\d{4}-\d{2}-\d{2} \d{2}-\d{2}-\d{2}Z$/); expect(buildDefaultArtifactsRootDirpath('iphone8', 'artifacts')).not.toBe(path.join('artifacts', 'iphone8.2019-11-05 11-00-41Z')); }); diff --git a/detox/src/artifacts/utils/temporaryPath.js b/detox/src/artifacts/utils/temporaryPath.js index 7991d20d2b..030dba067e 100644 --- a/detox/src/artifacts/utils/temporaryPath.js +++ b/detox/src/artifacts/utils/temporaryPath.js @@ -1,4 +1,5 @@ const path = require('path'); + const tempfile = require('tempfile'); module.exports = { diff --git a/detox/src/artifacts/utils/temporaryPath.test.js b/detox/src/artifacts/utils/temporaryPath.test.js index 2675896ca3..69db36100d 100644 --- a/detox/src/artifacts/utils/temporaryPath.test.js +++ b/detox/src/artifacts/utils/temporaryPath.test.js @@ -1,5 +1,7 @@ const path = require('path'); + const tempfile = require('tempfile'); + const temporaryPath = require('./temporaryPath'); describe('temporaryPath', () => { diff --git a/detox/src/artifacts/video/ADBScreenrecorderPlugin.js b/detox/src/artifacts/video/ADBScreenrecorderPlugin.js index cb71ab50d2..14f3bc7759 100644 --- a/detox/src/artifacts/video/ADBScreenrecorderPlugin.js +++ b/detox/src/artifacts/video/ADBScreenrecorderPlugin.js @@ -1,5 +1,5 @@ -const VideoArtifactPlugin = require('./VideoArtifactPlugin'); const ADBScreenrecorderArtifact = require('./ADBScreenrecorderArtifact'); +const VideoArtifactPlugin = require('./VideoArtifactPlugin'); class ADBScreenrecorderPlugin extends VideoArtifactPlugin { constructor(config) { diff --git a/detox/src/artifacts/video/SimulatorRecordVideoPlugin.js b/detox/src/artifacts/video/SimulatorRecordVideoPlugin.js index d706ff8561..cc3b8f6efe 100644 --- a/detox/src/artifacts/video/SimulatorRecordVideoPlugin.js +++ b/detox/src/artifacts/video/SimulatorRecordVideoPlugin.js @@ -1,10 +1,12 @@ const fs = require('fs-extra'); + +const { interruptProcess } = require('../../utils/exec'); const log = require('../../utils/logger').child({ __filename }); -const temporaryPath = require('../utils/temporaryPath'); -const VideoArtifactPlugin = require('./VideoArtifactPlugin'); const Artifact = require('../templates/artifact/Artifact'); const FileArtifact = require('../templates/artifact/FileArtifact'); -const { interruptProcess } = require('../../utils/exec'); +const temporaryPath = require('../utils/temporaryPath'); + +const VideoArtifactPlugin = require('./VideoArtifactPlugin'); class SimulatorRecordVideoPlugin extends VideoArtifactPlugin { constructor(config) { diff --git a/detox/src/client/AsyncWebSocket.js b/detox/src/client/AsyncWebSocket.js index e6608fed70..a96b1b4c45 100644 --- a/detox/src/client/AsyncWebSocket.js +++ b/detox/src/client/AsyncWebSocket.js @@ -1,9 +1,11 @@ const _ = require('lodash'); const WebSocket = require('ws'); -const log = require('../utils/logger').child({ __filename }); -const Deferred = require('../utils/Deferred'); + const DetoxInternalError = require('../errors/DetoxInternalError'); const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); +const Deferred = require('../utils/Deferred'); +const log = require('../utils/logger').child({ __filename }); + const InflightRequest = require('./InflightRequest'); const EVENTS = { @@ -233,7 +235,7 @@ class AsyncWebSocket { if (this._abortedMessageIds.has(json.messageId)) { log.debug(EVENTS.LATE_RESPONSE, `Received late response for messageId=${json.messageId}`); } else { - throw new DetoxRuntimeError('Unexpected message received over the web socket: ' + json.type) + throw new DetoxRuntimeError('Unexpected message received over the web socket: ' + json.type); } } } catch (error) { diff --git a/detox/src/client/AsyncWebSocket.test.js b/detox/src/client/AsyncWebSocket.test.js index 3f445704f8..6200f2edbc 100644 --- a/detox/src/client/AsyncWebSocket.test.js +++ b/detox/src/client/AsyncWebSocket.test.js @@ -1,7 +1,8 @@ jest.useFakeTimers('modern'); -const _ = require('lodash'); const permaproxy = require('funpermaproxy'); +const _ = require('lodash'); + const config = require('../configuration/configurations.mock').validSession; describe('AsyncWebSocket', () => { @@ -36,7 +37,7 @@ describe('AsyncWebSocket', () => { this.onclose && this.onclose(null); }; WebSocket.prototype.mockCloseError = function (error) { - this.close.mockImplementation(() => { throw error }); + this.close.mockImplementation(() => { throw error; }); }; AsyncWebSocket = require('./AsyncWebSocket'); @@ -131,7 +132,7 @@ describe('AsyncWebSocket', () => { it(`should reject all messages in the flight if there's an error`, async () => { const sendPromise1 = aws.send(generateRequest()); const sendPromise2 = aws.send(generateRequest()); - socket.mockError(anError()) + socket.mockError(anError()); await expect(sendPromise1).rejects.toThrowErrorMatchingSnapshot(); await expect(sendPromise2).rejects.toThrowErrorMatchingSnapshot(); @@ -285,7 +286,7 @@ describe('AsyncWebSocket', () => { await connect(); const someMessage = { type: 'foo' }; - socket.mockMessage(someMessage) + socket.mockMessage(someMessage); expect(f1).toHaveBeenCalledWith(someMessage); expect(f2).toHaveBeenCalledWith(someMessage); @@ -352,12 +353,12 @@ describe('AsyncWebSocket', () => { function connect() { return Promise.race([ aws.open(), - new Promise(() => { socket.mockOpen() }), + new Promise(() => { socket.mockOpen(); }), ]); } function generateRequest(messageId) { - return {type: 'invoke', message: 'a message', messageId}; + return { type: 'invoke', message: 'a message', messageId }; } function generateResponse(message, messageId) { diff --git a/detox/src/client/Client.js b/detox/src/client/Client.js index b8ff2e2ce5..b91c6a762f 100644 --- a/detox/src/client/Client.js +++ b/detox/src/client/Client.js @@ -1,14 +1,17 @@ -const _ = require('lodash'); const util = require('util'); + +const _ = require('lodash'); const { deserializeError } = require('serialize-error'); -const AsyncWebSocket = require('./AsyncWebSocket'); -const actions = require('./actions/actions'); -const Deferred = require('../utils/Deferred'); + const DetoxInternalError = require('../errors/DetoxInternalError'); const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); const failedToReachTheApp = require('../errors/longreads/failedToReachTheApp'); -const log = require('../utils/logger').child({ __filename }); +const Deferred = require('../utils/Deferred'); const { asError, createErrorWithUserStack, replaceErrorStack } = require('../utils/errorUtils'); +const log = require('../utils/logger').child({ __filename }); + +const AsyncWebSocket = require('./AsyncWebSocket'); +const actions = require('./actions/actions'); class Client { /** @@ -76,7 +79,7 @@ class Client { if (this.isConnected) { await this.sendAction(new actions.Cleanup(this._successfulTestRun)).catch(this._logError); - this._whenAppIsConnected = this._invalidState('while cleaning up') + this._whenAppIsConnected = this._invalidState('while cleaning up'); this._whenAppIsReady = this._whenAppIsConnected; } } finally { @@ -90,7 +93,7 @@ class Client { this._asyncWebSocket.setEventCallback(event, callback); } - dumpPendingRequests({testName} = {}) { + dumpPendingRequests({ testName } = {}) { if (this._whenAppIsConnected.isPending()) { const unreachableError = failedToReachTheApp.evenThoughAppWasLaunched(); log.error({ event: 'APP_UNREACHABLE' }, DetoxRuntimeError.format(unreachableError) + '\n\n'); @@ -108,7 +111,7 @@ class Client { : `Unresponded network requests might result in timeout errors in Detox tests.`; dump += `\n\n${notice}\n`; - log.warn({ event: 'PENDING_REQUESTS'}, dump); + log.warn({ event: 'PENDING_REQUESTS' }, dump); } this._asyncWebSocket.resetInFlightPromises(); @@ -132,7 +135,7 @@ class Client { return await (queryStatus ? this._sendMonitoredAction(action, options) - : this._doSendAction(action, options)) + : this._doSendAction(action, options)); } _inferSendOptions(action) { @@ -330,7 +333,7 @@ class Client { _onAppDisconnected() { this._unscheduleSlowInvocationQuery(); this._unscheduleAppTermination(); - this._whenAppIsConnected = this._invalidState('after the app has disconnected') + this._whenAppIsConnected = this._invalidState('after the app has disconnected'); this._whenAppIsReady = this._whenAppIsConnected; if (this._pendingAppCrash) { diff --git a/detox/src/client/Client.test.js b/detox/src/client/Client.test.js index c78df42345..de9c23497f 100644 --- a/detox/src/client/Client.test.js +++ b/detox/src/client/Client.test.js @@ -1,10 +1,12 @@ jest.useFakeTimers('modern'); -const tempfile = require('tempfile'); -const actions = require('./actions/actions'); -const Deferred = require('../utils/Deferred'); const { serializeError } = require('serialize-error'); +const tempfile = require('tempfile'); + const { validSession } = require('../configuration/configurations.mock'); +const Deferred = require('../utils/Deferred'); + +const actions = require('./actions/actions'); describe('Client', () => { let log; @@ -61,7 +63,7 @@ describe('Client', () => { mockAws.mockSyncError = (message) => { mockAws.send.mockImplementation(() => { throw new Error(message); - }) + }); }; const mockEvents = {}; @@ -247,7 +249,7 @@ describe('Client', () => { jest.advanceTimersByTime(validSession.debugSynchronization); await fastForwardAllPromises(); - expect(log.debug).toHaveBeenCalledWith({ event: "APP_STATUS" }, 'Failed to execute the current status query.'); + expect(log.debug).toHaveBeenCalledWith({ event: 'APP_STATUS' }, 'Failed to execute the current status query.'); expect(jest.getTimerCount()).toBe(0); }); @@ -327,14 +329,14 @@ describe('Client', () => { }); it(`should throw an error if the response has "captureViewHierarchyError" in params`, async () => { - mockAws.mockResponse("captureViewHierarchyDone", { + mockAws.mockResponse('captureViewHierarchyDone', { captureViewHierarchyError: 'Test error to check', }); const viewHierarchyURL = tempfile('.viewhierarchy'); await expect(client.captureViewHierarchy({ viewHierarchyURL })).rejects.toThrowError(/Test error to check/m); }); - }) + }); describe('.cleanup()', () => { it('should cancel "currentStatus" query', async () => { @@ -355,7 +357,7 @@ describe('Client', () => { mockAws.send.mockReset(); mockAws.mockEventCallback('AppWillTerminateWithError', { params: { errorDetails: new Error() } - }) + }); await client.cleanup(); expect(mockAws.send).not.toHaveBeenCalled(); @@ -425,14 +427,14 @@ describe('Client', () => { }); test(`"invokeResult" on an invocation object should return invokeResult`, async () => { - mockAws.mockResponse("invokeResult", { result: 'some_result' }); + mockAws.mockResponse('invokeResult', { result: 'some_result' }); const invokeObject = anInvocation(); const invokeResult = await client.execute(invokeObject); expect(invokeResult).toEqual({ result: 'some_result' }); }); test(`"invokeResult" on an invocation function should resolve`, async () => { - mockAws.mockResponse("invokeResult", { result: 'some_result' }); + mockAws.mockResponse('invokeResult', { result: 'some_result' }); const invokeResult = await client.execute(anInvocation); expect(invokeResult).toEqual({ result: 'some_result' }); }); @@ -442,7 +444,7 @@ describe('Client', () => { ['trace'], ])(`should throw "testFailed" error with view hierarchy (on --loglevel %s)`, async (loglevel) => { log.level.mockReturnValue(loglevel); - mockAws.mockResponse("testFailed", {details: "this is an error", viewHierarchy: 'mock-hierarchy'}); + mockAws.mockResponse('testFailed', { details: 'this is an error', viewHierarchy: 'mock-hierarchy' }); await expect(client.execute(anInvocation)).rejects.toThrowErrorMatchingSnapshot(); }); @@ -452,29 +454,29 @@ describe('Client', () => { ['info'], ])(`should throw "testFailed" error without view hierarchy but with a hint (on --loglevel %s)`, async (loglevel) => { log.level.mockReturnValue(loglevel); - mockAws.mockResponse("testFailed", {details: "this is an error", viewHierarchy: 'mock-hierarchy'}); + mockAws.mockResponse('testFailed', { details: 'this is an error', viewHierarchy: 'mock-hierarchy' }); await expect(client.execute(anInvocation)).rejects.toThrowErrorMatchingSnapshot(); }); it(`should throw "testFailed" error even if it has no a view hierarchy`, async () => { - mockAws.mockResponse("testFailed", {details: "this is an error", viewHierarchy: undefined }); + mockAws.mockResponse('testFailed', { details: 'this is an error', viewHierarchy: undefined }); const executionPromise = client.execute(anInvocation); await expect(executionPromise).rejects.toThrowErrorMatchingSnapshot(); }); it(`should rethrow an "error" result`, async () => { - mockAws.mockResponse("error", {error: "this is an error"}); + mockAws.mockResponse('error', { error: 'this is an error' }); await expect(client.execute(anInvocation)).rejects.toThrowErrorMatchingSnapshot(); }); it(`should throw even if a non-error object is thrown`, async () => { - mockAws.send.mockRejectedValueOnce("non-error"); + mockAws.send.mockRejectedValueOnce('non-error'); await expect(client.execute(anInvocation)).rejects.toThrowErrorMatchingSnapshot(); }); it(`should throw on an unsupported result`, async () => { - mockAws.mockResponse("unsupportedResult", { foo: 'bar' }); + mockAws.mockResponse('unsupportedResult', { foo: 'bar' }); await expect(client.execute(anInvocation)).rejects.toThrowErrorMatchingSnapshot(); }); }); @@ -492,7 +494,7 @@ describe('Client', () => { it(`should log an error about the app being unreachable over web sockets`, async () => { await client.dumpPendingRequests(); - expect(log.error.mock.calls[0][0]).toEqual({ event: "APP_UNREACHABLE" }); + expect(log.error.mock.calls[0][0]).toEqual({ event: 'APP_UNREACHABLE' }); expect(log.error.mock.calls[0][1]).toMatch(/Failed to reach the app over the web socket connection./); }); }); @@ -524,13 +526,13 @@ describe('Client', () => { it(`should dump generic message if not testName is specified`, async () => { client.dumpPendingRequests(); - expect(log.warn.mock.calls[0][0]).toEqual({ event: "PENDING_REQUESTS" }); + expect(log.warn.mock.calls[0][0]).toEqual({ event: 'PENDING_REQUESTS' }); expect(log.warn.mock.calls[0][1]).toMatch(/Unresponded network requests/); }); it(`should dump specific message if testName is specified`, async () => { - client.dumpPendingRequests({testName: "Login screen should log in"}); - expect(log.warn.mock.calls[0][0]).toEqual({ event: "PENDING_REQUESTS" }); + client.dumpPendingRequests({ testName: 'Login screen should log in' }); + expect(log.warn.mock.calls[0][0]).toEqual({ event: 'PENDING_REQUESTS' }); expect(log.warn.mock.calls[0][1]).toMatch(/Login screen should log in/); }); @@ -551,12 +553,12 @@ describe('Client', () => { expect(log.warn).toHaveBeenCalledWith({ event: 'APP_NONRESPONSIVE' }, expect.stringContaining('THREAD_DUMP')); expect(log.warn.mock.calls[0][1]).toMatchSnapshot(); }); - }) + }); describe('.waitUntilReady()', () => { it('should wait until connected, then send Ready action', async () => { let isReady = false; - client.waitUntilReady().then(() => { isReady = true; }) + client.waitUntilReady().then(() => { isReady = true; }); await fastForwardAllPromises(); expect(isReady).toBe(false); @@ -573,7 +575,7 @@ describe('Client', () => { it('should wait until connected and ready, if the app sends ready status beforehand', async () => { let isReady = false; - client.waitUntilReady().then(() => { isReady = true; }) + client.waitUntilReady().then(() => { isReady = true; }); mockAws.mockEventCallback('ready'); await fastForwardAllPromises(); @@ -584,7 +586,7 @@ describe('Client', () => { expect(isReady).toBe(true); expect(mockAws.send).not.toHaveBeenCalledWith(new actions.Ready(), expect.anything()); }); - }) + }); describe('on AppWillTerminateWithError', () => { it('should schedule the app termination in 5 seconds, and reject pending', async () => { @@ -650,7 +652,7 @@ describe('Client', () => { describe('on appDisconnected', () => { it('should reject pending actions', async () => { await client.connect(); - await simulateInFlightAction(new actions.Invoke(anInvocation())) + await simulateInFlightAction(new actions.Invoke(anInvocation())); mockAws.mockEventCallback('appDisconnected'); await fastForwardAllPromises(); expect(mockAws.rejectAll).toHaveBeenCalled(); diff --git a/detox/src/client/__mocks__/Client.js b/detox/src/client/__mocks__/Client.js index 5d248746d4..20013c741f 100644 --- a/detox/src/client/__mocks__/Client.js +++ b/detox/src/client/__mocks__/Client.js @@ -5,7 +5,7 @@ FakeClient.setInfiniteConnect = () => { FakeClient.mockImplementationOnce(() => { const client = new FakeClient(); client.deferred = new Deferred(); - client.connect.mockReturnValue(client.deferred.promise) + client.connect.mockReturnValue(client.deferred.promise); client.cleanup.mockImplementation(() => { client.deferred.reject('Fake error: aborted connection'); }); diff --git a/detox/src/client/actions/actions.js b/detox/src/client/actions/actions.js index 0d2df757aa..43e1f5a9bb 100644 --- a/detox/src/client/actions/actions.js +++ b/detox/src/client/actions/actions.js @@ -1,7 +1,8 @@ const _ = require('lodash'); -const { getDetoxLevel } = require('../../utils/logger'); -const DetoxRuntimeError = require('../../errors/DetoxRuntimeError'); + const DetoxInternalError = require('../../errors/DetoxInternalError'); +const DetoxRuntimeError = require('../../errors/DetoxRuntimeError'); +const { getDetoxLevel } = require('../../utils/logger'); class Action { constructor(type, params = {}) { @@ -181,7 +182,7 @@ class CaptureViewHierarchy extends Action { async handle(response) { this.expectResponseOfType(response, 'captureViewHierarchyDone'); - const {captureViewHierarchyError} = response.params; + const { captureViewHierarchyError } = response.params; if (captureViewHierarchyError) { throw new DetoxRuntimeError({ message: 'Failed to capture view hierarchy. Reason:\n', diff --git a/detox/src/configuration/__mocks__/configuration/extends/middle.js b/detox/src/configuration/__mocks__/configuration/extends/middle.js index 20f56a8a47..b64713bfb2 100644 --- a/detox/src/configuration/__mocks__/configuration/extends/middle.js +++ b/detox/src/configuration/__mocks__/configuration/extends/middle.js @@ -6,4 +6,4 @@ module.exports = { screenshot: 'all', }, }, -} +}; diff --git a/detox/src/configuration/collectCliConfig.js b/detox/src/configuration/collectCliConfig.js index 784dc45b3a..41e273e473 100644 --- a/detox/src/configuration/collectCliConfig.js +++ b/detox/src/configuration/collectCliConfig.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const argparse = require('../utils/argparse'); function collectCliConfig({ argv }) { diff --git a/detox/src/configuration/composeAppsConfig.js b/detox/src/configuration/composeAppsConfig.js index e6a71f4c18..a071101865 100644 --- a/detox/src/configuration/composeAppsConfig.js +++ b/detox/src/configuration/composeAppsConfig.js @@ -1,5 +1,6 @@ const _ = require('lodash'); const parse = require('yargs/yargs').Parser; + const deviceAppTypes = require('./utils/deviceAppTypes'); const CLI_PARSER_OPTIONS = { diff --git a/detox/src/configuration/composeAppsConfig.test.js b/detox/src/configuration/composeAppsConfig.test.js index 416d6c5452..45a8361de4 100644 --- a/detox/src/configuration/composeAppsConfig.test.js +++ b/detox/src/configuration/composeAppsConfig.test.js @@ -1,5 +1,7 @@ const _ = require('lodash'); + const DetoxConfigErrorComposer = require('../errors/DetoxConfigErrorComposer'); + const { appWithAbsoluteBinaryPath, appWithRelativeBinaryPath, @@ -31,7 +33,7 @@ describe('composeAppsConfig', () => { configurations: { [configurationName]: localConfig, }, - } + }; errorComposer = new DetoxConfigErrorComposer() .setDetoxConfig(globalConfig) @@ -213,7 +215,7 @@ describe('composeAppsConfig', () => { it('should parse it and merge the values inside', () => { const { app1, app2 } = compose(); - expect(app1.launchArgs).toEqual({ arg3: 'override'}); + expect(app1.launchArgs).toEqual({ arg3: 'override' }); expect(app2.launchArgs).toEqual({ arg1: 'value1', arg3: 'override' }); }); }); diff --git a/detox/src/configuration/composeArtifactsConfig.js b/detox/src/configuration/composeArtifactsConfig.js index 99c63fd279..2f7aa1921c 100644 --- a/detox/src/configuration/composeArtifactsConfig.js +++ b/detox/src/configuration/composeArtifactsConfig.js @@ -1,14 +1,14 @@ const _ = require('lodash'); -const resolveModuleFromPath = require('../utils/resolveModuleFromPath'); -const buildDefaultArtifactsRootDirpath = require('../artifacts/utils/buildDefaultArtifactsRootDirpath'); -const TimelineArtifactPlugin = require('../artifacts/timeline/TimelineArtifactPlugin'); const InstrumentsArtifactPlugin = require('../artifacts/instruments/InstrumentsArtifactPlugin'); const LogArtifactPlugin = require('../artifacts/log/LogArtifactPlugin'); const ScreenshotArtifactPlugin = require('../artifacts/screenshot/ScreenshotArtifactPlugin'); -const VideoArtifactPlugin = require('../artifacts/video/VideoArtifactPlugin'); +const TimelineArtifactPlugin = require('../artifacts/timeline/TimelineArtifactPlugin'); const IosUIHierarchyPlugin = require('../artifacts/uiHierarchy/IosUIHierarchyPlugin'); const ArtifactPathBuilder = require('../artifacts/utils/ArtifactPathBuilder'); +const buildDefaultArtifactsRootDirpath = require('../artifacts/utils/buildDefaultArtifactsRootDirpath'); +const VideoArtifactPlugin = require('../artifacts/video/VideoArtifactPlugin'); +const resolveModuleFromPath = require('../utils/resolveModuleFromPath'); /** * @param {*} cliConfig diff --git a/detox/src/configuration/composeArtifactsConfig.test.js b/detox/src/configuration/composeArtifactsConfig.test.js index b696221aff..fd1b2b7479 100644 --- a/detox/src/configuration/composeArtifactsConfig.test.js +++ b/detox/src/configuration/composeArtifactsConfig.test.js @@ -1,5 +1,7 @@ -const _ = require('lodash'); const path = require('path'); + +const _ = require('lodash'); + const schemes = require('./configurations.mock'); describe('composeArtifactsConfig', () => { @@ -17,7 +19,7 @@ describe('composeArtifactsConfig', () => { cliConfig: {}, })).toMatchObject({ pathBuilder: expect.objectContaining({ - rootDir: expect.stringMatching(/^artifacts[\\\/]abracadabra\.\d{4}/), + rootDir: expect.stringMatching(/^artifacts[\\/]abracadabra\.\d{4}/), }), plugins: schemes.pluginsDefaultsResolved, }); @@ -37,7 +39,7 @@ describe('composeArtifactsConfig', () => { cliConfig: {}, })).toMatchObject({ pathBuilder: expect.objectContaining({ - rootDir: expect.stringMatching(/^otherPlace[\\\/]abracadabra\.\d{4}/), + rootDir: expect.stringMatching(/^otherPlace[\\/]abracadabra\.\d{4}/), }), plugins: schemes.pluginsAllResolved, }); @@ -57,7 +59,7 @@ describe('composeArtifactsConfig', () => { cliConfig: {}, })).toMatchObject({ pathBuilder: expect.objectContaining({ - rootDir: expect.stringMatching(/^otherPlace[\\\/]abracadabra\.\d{4}/), + rootDir: expect.stringMatching(/^otherPlace[\\/]abracadabra\.\d{4}/), }), plugins: schemes.pluginsAllResolved, }); @@ -79,7 +81,7 @@ describe('composeArtifactsConfig', () => { cliConfig: {}, })).toMatchObject({ pathBuilder: expect.objectContaining({ - rootDir: expect.stringMatching(/^artifacts[\\\/]abracadabra\.\d{4}/), + rootDir: expect.stringMatching(/^artifacts[\\/]abracadabra\.\d{4}/), }), plugins: schemes.pluginsDefaultsResolved, }); @@ -101,7 +103,7 @@ describe('composeArtifactsConfig', () => { }, })).toMatchObject({ pathBuilder: expect.objectContaining({ - rootDir: expect.stringMatching(/^otherPlace[\\\/]abracadabra\.\d{4}/), + rootDir: expect.stringMatching(/^otherPlace[\\/]abracadabra\.\d{4}/), }), plugins: schemes.pluginsAllResolved, }); @@ -133,7 +135,7 @@ describe('composeArtifactsConfig', () => { }, })).toMatchObject({ pathBuilder: expect.objectContaining({ - rootDir: expect.stringMatching(/^cli[\\\/]priority\.\d{4}/), + rootDir: expect.stringMatching(/^cli[\\/]priority\.\d{4}/), }), plugins: { log: schemes.pluginsFailingResolved.log, @@ -171,8 +173,8 @@ describe('composeArtifactsConfig', () => { globalConfig: {}, })).toMatchObject({ pathBuilder: expect.objectContaining({ - "name": expect.any(String), - "version": expect.any(String), + 'name': expect.any(String), + 'version': expect.any(String), }), }); }); @@ -210,7 +212,7 @@ describe('composeArtifactsConfig', () => { }, video: { android: { bitRate: 4000000 }, - simulator: { codec: "hevc" }, + simulator: { codec: 'hevc' }, } }, }, @@ -227,7 +229,7 @@ describe('composeArtifactsConfig', () => { video: { ...schemes.pluginsDefaultsResolved.video, android: { bitRate: 4000000 }, - simulator: { codec: "hevc" }, + simulator: { codec: 'hevc' }, }, }), }); diff --git a/detox/src/configuration/composeBehaviorConfig.test.js b/detox/src/configuration/composeBehaviorConfig.test.js index 4d0f6a55c5..025d37dd4b 100644 --- a/detox/src/configuration/composeBehaviorConfig.test.js +++ b/detox/src/configuration/composeBehaviorConfig.test.js @@ -30,7 +30,7 @@ describe('composeBehaviorConfig', () => { cleanup: { shutdownDevice: false, }, - }) + }); }); describe('if a custom config has only .launchApp = "manual" override', () => { diff --git a/detox/src/configuration/composeDeviceConfig.js b/detox/src/configuration/composeDeviceConfig.js index 782d9b8802..14a046633e 100644 --- a/detox/src/configuration/composeDeviceConfig.js +++ b/detox/src/configuration/composeDeviceConfig.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const driverRegistry = require('../devices/DriverRegistry').default; /** diff --git a/detox/src/configuration/composeDeviceConfig.test.js b/detox/src/configuration/composeDeviceConfig.test.js index 41873fa404..a32705cd47 100644 --- a/detox/src/configuration/composeDeviceConfig.test.js +++ b/detox/src/configuration/composeDeviceConfig.test.js @@ -1,5 +1,7 @@ const _ = require('lodash'); + const DetoxConfigErrorComposer = require('../errors/DetoxConfigErrorComposer'); + const { appWithRelativeBinaryPath, iosSimulatorWithShorthandQuery } = require('./configurations.mock'); describe('composeDeviceConfig', () => { @@ -28,7 +30,7 @@ describe('composeDeviceConfig', () => { configurations: { someConfig: localConfig, }, - } + }; errorComposer = new DetoxConfigErrorComposer() .setDetoxConfig(globalConfig) @@ -192,7 +194,7 @@ describe('composeDeviceConfig', () => { device: { avdName: 'Pixel' }, utilBinaryPaths: 'valid/path/not/in/array', }, - } + }; expect(compose).toThrowError( errorComposer.malformedUtilBinaryPaths(localConfig.device) @@ -241,7 +243,7 @@ describe('composeDeviceConfig', () => { it('should throw if the device config has invalid type', () => { const someError = new Error('Some error'); - driverRegistry.resolve = () => { throw someError }; + driverRegistry.resolve = () => { throw someError; }; localConfig.device = { type: 'android.apk' }; expect(compose).toThrow(errorComposer.invalidDeviceType( diff --git a/detox/src/configuration/composeSessionConfig.js b/detox/src/configuration/composeSessionConfig.js index 794b5be6ba..c9b30a6fab 100644 --- a/detox/src/configuration/composeSessionConfig.js +++ b/detox/src/configuration/composeSessionConfig.js @@ -1,6 +1,7 @@ const getPort = require('get-port'); -const uuid = require('../utils/uuid'); + const isValidWebsocketURL = require('../utils/isValidWebsocketURL'); +const uuid = require('../utils/uuid'); /** * @param {require('../errors/DetoxConfigErrorComposer')} errorComposer diff --git a/detox/src/configuration/configurations.mock.js b/detox/src/configuration/configurations.mock.js index d85f4809c9..90dff3175b 100644 --- a/detox/src/configuration/configurations.mock.js +++ b/detox/src/configuration/configurations.mock.js @@ -1,9 +1,9 @@ const InstrumentsArtifactPlugin = require('../artifacts/instruments/InstrumentsArtifactPlugin'); const LogArtifactPlugin = require('../artifacts/log/LogArtifactPlugin'); const ScreenshotArtifactPlugin = require('../artifacts/screenshot/ScreenshotArtifactPlugin'); -const VideoArtifactPlugin = require('../artifacts/video/VideoArtifactPlugin'); const TimelineArtifactPlugin = require('../artifacts/timeline/TimelineArtifactPlugin'); const IosUIHierarchyPlugin = require('../artifacts/uiHierarchy/IosUIHierarchyPlugin'); +const VideoArtifactPlugin = require('../artifacts/video/VideoArtifactPlugin'); const defaultArtifactsConfiguration = { rootDir: 'artifacts', @@ -56,47 +56,47 @@ const pluginsAllResolved = { }; const appWithNoBinary = { - type: "ios.app", - bundleId: "com.detox.example", + type: 'ios.app', + bundleId: 'com.detox.example', }; const appWithRelativeBinaryPath = { - type: "ios.app", - binaryPath: "ios/build/Build/Products/Release-iphonesimulator/example.app", + type: 'ios.app', + binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/example.app', }; const appWithAbsoluteBinaryPath = { - type: "ios.app", - binaryPath: process.platform === "win32" ? "C:\\Temp\\abcdef\\123" : "/tmp/abcdef/123", + type: 'ios.app', + binaryPath: process.platform === 'win32' ? 'C:\\Temp\\abcdef\\123' : '/tmp/abcdef/123', }; const appWithBinaryAndBundleId = { - type: "ios.app", - binaryPath: "ios/build/Build/Products/Release-iphonesimulator/example.app", - bundleId: "com.detox.example", + type: 'ios.app', + binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/example.app', + bundleId: 'com.detox.example', }; const apkWithBinary = { - type: "android.apk", - binaryPath: "android/app/build/outputs/apk/release/app-release.apk", - testBinaryPath: "android/app/build/outputs/apk/release/app-release-androidTest.apk", + type: 'android.apk', + binaryPath: 'android/app/build/outputs/apk/release/app-release.apk', + testBinaryPath: 'android/app/build/outputs/apk/release/app-release-androidTest.apk', }; const iosSimulatorWithShorthandQuery = { - type: "ios.simulator", - device: "iPhone 7 Plus, iOS 10.2" + type: 'ios.simulator', + device: 'iPhone 7 Plus, iOS 10.2' }; const validSession = { - server: "ws://localhost:8099", - sessionId: "test", + server: 'ws://localhost:8099', + sessionId: 'test', debugSynchronization: 10000, }; const androidEmulator = { - "type": "android.emulator", - "device": { - "avdName": "Pixel_API_28", + 'type': 'android.emulator', + 'device': { + 'avdName': 'Pixel_API_28', }, }; diff --git a/detox/src/configuration/index.js b/detox/src/configuration/index.js index 8505d3ab1b..5a22a0c166 100644 --- a/detox/src/configuration/index.js +++ b/detox/src/configuration/index.js @@ -1,13 +1,15 @@ const _ = require('lodash'); + const DetoxConfigErrorComposer = require('../errors/DetoxConfigErrorComposer'); + const collectCliConfig = require('./collectCliConfig'); -const loadExternalConfig = require('./loadExternalConfig'); -const composeArtifactsConfig = require('./composeArtifactsConfig'); const composeAppsConfig = require('./composeAppsConfig'); +const composeArtifactsConfig = require('./composeArtifactsConfig'); const composeBehaviorConfig = require('./composeBehaviorConfig'); const composeDeviceConfig = require('./composeDeviceConfig'); const composeRunnerConfig = require('./composeRunnerConfig'); const composeSessionConfig = require('./composeSessionConfig'); +const loadExternalConfig = require('./loadExternalConfig'); const selectConfiguration = require('./selectConfiguration'); async function composeDetoxConfig({ diff --git a/detox/src/configuration/index.test.js b/detox/src/configuration/index.test.js index 6b6f563230..e71ffb06cf 100644 --- a/detox/src/configuration/index.test.js +++ b/detox/src/configuration/index.test.js @@ -1,8 +1,10 @@ jest.mock('../utils/argparse'); -const _ = require('lodash'); const os = require('os'); const path = require('path'); + +const _ = require('lodash'); + const DetoxConfigErrorComposer = require('../errors/DetoxConfigErrorComposer'); describe('composeDetoxConfig', () => { diff --git a/detox/src/configuration/loadExternalConfig.js b/detox/src/configuration/loadExternalConfig.js index 148442815a..96a55e6017 100644 --- a/detox/src/configuration/loadExternalConfig.js +++ b/detox/src/configuration/loadExternalConfig.js @@ -1,8 +1,10 @@ -const _ = require('lodash'); -const fs = require('fs-extra'); const path = require('path'); + const findUp = require('find-up'); +const fs = require('fs-extra'); +const _ = require('lodash'); const resolveFrom = require('resolve-from'); + const log = require('../utils/logger').child({ __filename }); async function locateExternalConfig(cwd) { diff --git a/detox/src/configuration/loadExternalConfig.test.js b/detox/src/configuration/loadExternalConfig.test.js index ac932bcea9..90baee5676 100644 --- a/detox/src/configuration/loadExternalConfig.test.js +++ b/detox/src/configuration/loadExternalConfig.test.js @@ -1,5 +1,5 @@ -const path = require('path'); const os = require('os'); +const path = require('path'); describe('loadExternalConfig', () => { const DIR_PACKAGEJSON = path.join(__dirname, '__mocks__/configuration/packagejson'); @@ -30,7 +30,7 @@ describe('loadExternalConfig', () => { it('should implicitly use .detoxrc.js, even if there is package.json', async () => { const { filepath, config } = await loadExternalConfig({ cwd: DIR_PRIORITY }); - expect(filepath).toBe(path.join(DIR_PRIORITY, '.detoxrc.js')) + expect(filepath).toBe(path.join(DIR_PRIORITY, '.detoxrc.js')); expect(config).toMatchObject({ configurations: expect.anything() }); expect(logger.warn).not.toHaveBeenCalled(); }); @@ -38,7 +38,7 @@ describe('loadExternalConfig', () => { it('should implicitly use package.json, even if there is no .detoxrc', async () => { const { filepath, config } = await loadExternalConfig({ cwd: DIR_PACKAGEJSON }); - expect(filepath).toBe(path.join(DIR_PACKAGEJSON, 'package.json')) + expect(filepath).toBe(path.join(DIR_PACKAGEJSON, 'package.json')); expect(config).toMatchObject({ configurations: expect.anything() }); expect(logger.warn).not.toHaveBeenCalled(); }); @@ -52,7 +52,7 @@ describe('loadExternalConfig', () => { const configPath = path.join(DIR_PRIORITY, 'detox-config.json'); const { filepath, config } = await loadExternalConfig({ configPath }); - expect(filepath).toBe(configPath) + expect(filepath).toBe(configPath); expect(config).toMatchObject({ configurations: expect.anything() }); expect(logger.warn).not.toHaveBeenCalled(); }); @@ -60,15 +60,15 @@ describe('loadExternalConfig', () => { it('should merge in the base config from "extends" property', async () => { const { filepath, config } = await loadExternalConfig({ cwd: DIR_EXTENDS }); - expect(filepath).toBe(path.join(DIR_EXTENDS, '.detoxrc.js')) + expect(filepath).toBe(path.join(DIR_EXTENDS, '.detoxrc.js')); expect(config).toEqual({ extends: path.join(DIR_EXTENDS, 'middle.js'), artifacts: { rootDir: 'someRootDir', plugins: { - log: "all", - screenshot: "all", - video: "all", + log: 'all', + screenshot: 'all', + video: 'all', }, }, }); diff --git a/detox/src/configuration/selectConfiguration.test.js b/detox/src/configuration/selectConfiguration.test.js index 8c64dc7577..a5880609ae 100644 --- a/detox/src/configuration/selectConfiguration.test.js +++ b/detox/src/configuration/selectConfiguration.test.js @@ -1,5 +1,6 @@ const DetoxConfigErrorComposer = require('../errors/DetoxConfigErrorComposer'); -const { apkWithBinary, androidEmulator } = require('./configurations.mock'); + +const { androidEmulator, apkWithBinary } = require('./configurations.mock'); describe('selectConfiguration', () => { let selectConfiguration; diff --git a/detox/src/devices/Device.js b/detox/src/devices/Device.js index bf25b2ef29..a6ab90ab05 100644 --- a/detox/src/devices/Device.js +++ b/detox/src/devices/Device.js @@ -1,9 +1,11 @@ const _ = require('lodash'); -const LaunchArgsEditor = require('./LaunchArgsEditor'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); const debug = require('../utils/debug'); // debug utils, leave here even if unused const { traceCall } = require('../utils/trace'); +const LaunchArgsEditor = require('./LaunchArgsEditor'); + class Device { constructor({ appsConfig, @@ -325,7 +327,7 @@ class Device { } if (this._isAppRunning(bundleId) && hasPayload) { - await this.deviceDriver.deliverPayload({...params, delayPayload: true}); + await this.deviceDriver.deliverPayload({ ...params, delayPayload: true }); } if (this._behaviorConfig.launchApp === 'manual') { diff --git a/detox/src/devices/Device.test.js b/detox/src/devices/Device.test.js index 0744bdc874..764aa8b15b 100644 --- a/detox/src/devices/Device.test.js +++ b/detox/src/devices/Device.test.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const configurationsMock = require('../configuration/configurations.mock'); describe('Device', () => { @@ -204,7 +205,7 @@ describe('Device', () => { it(`should throw on attempt to select a non-existent app`, async () => { await expect(device.selectApp('nonExistent')).rejects.toThrowError(); }); - }) + }); describe('when there are multiple apps', () => { beforeEach(async () => { @@ -232,7 +233,7 @@ describe('Device', () => { it(`upon select, it should infer bundleId if it is missing`, async () => { await device.selectApp('withBinaryPath'); - expect(driverMock.driver.getBundleIdFromBinary).toHaveBeenCalledWith('path/to/app') + expect(driverMock.driver.getBundleIdFromBinary).toHaveBeenCalledWith('path/to/app'); }); it(`upon select, it should terminate the previous app`, async () => { @@ -256,13 +257,13 @@ describe('Device', () => { await device.selectApp('withBinaryPath'); expect(driverMock.driver.getBundleIdFromBinary).toHaveBeenCalledTimes(1); }); - }) + }); }); describe('re/launchApp()', () => { const expectedDriverArgs = { - "detoxServer": "ws://localhost:8099", - "detoxSessionId": "test", + 'detoxServer': 'ws://localhost:8099', + 'detoxSessionId': 'test', }; it(`with no args should launch app with defaults`, async () => { @@ -294,7 +295,7 @@ describe('Device', () => { deviceId: device.id, bundleId: device._bundleId, pid: 42, - }) + }); }); it(`(relaunch) with no args should use defaults`, async () => { @@ -317,7 +318,7 @@ describe('Device', () => { it(`(relaunch) with newInstance=false should not terminate the app before launch`, async () => { const device = await aValidDevice(); - await device.relaunchApp({newInstance: false}); + await device.relaunchApp({ newInstance: false }); driverMock.expectTerminateNotCalled(); }); @@ -325,7 +326,7 @@ describe('Device', () => { it(`(relaunch) with newInstance=true should terminate the app before launch`, async () => { const device = await aValidDevice(); - await device.relaunchApp({newInstance: true}); + await device.relaunchApp({ newInstance: true }); driverMock.expectTerminateCalled(); }); @@ -334,7 +335,7 @@ describe('Device', () => { const expectedArgs = expectedDriverArgs; const device = await aValidDevice(); - await device.relaunchApp({delete: true}); + await device.relaunchApp({ delete: true }); driverMock.expectReinstallCalled(); driverMock.expectLaunchCalledWithArgs(device, expectedArgs); @@ -352,10 +353,10 @@ describe('Device', () => { }); it(`(relaunch) with url should send the url as a param in launchParams`, async () => { - const expectedArgs = {...expectedDriverArgs, "detoxURLOverride": "scheme://some.url"}; + const expectedArgs = { ...expectedDriverArgs, 'detoxURLOverride': 'scheme://some.url' }; const device = await aValidDevice(); - await device.relaunchApp({url: `scheme://some.url`}); + await device.relaunchApp({ url: `scheme://some.url` }); driverMock.expectLaunchCalledWithArgs(device, expectedArgs); }); @@ -363,11 +364,11 @@ describe('Device', () => { it(`(relaunch) with url should send the url as a param in launchParams`, async () => { const expectedArgs = { ...expectedDriverArgs, - "detoxURLOverride": "scheme://some.url", - "detoxSourceAppOverride": "sourceAppBundleId", + 'detoxURLOverride': 'scheme://some.url', + 'detoxSourceAppOverride': 'sourceAppBundleId', }; const device = await aValidDevice(); - await device.relaunchApp({url: `scheme://some.url`, sourceApp: 'sourceAppBundleId'}); + await device.relaunchApp({ url: `scheme://some.url`, sourceApp: 'sourceAppBundleId' }); driverMock.expectLaunchCalledWithArgs(device, expectedArgs); }); @@ -375,13 +376,13 @@ describe('Device', () => { it(`(relaunch) with userNofitication should send the userNotification as a param in launchParams`, async () => { const expectedArgs = { ...expectedDriverArgs, - "detoxUserNotificationDataURL": "url", + 'detoxUserNotificationDataURL': 'url', }; const device = await aValidDevice(); device.deviceDriver.createPayloadFile = jest.fn(() => 'url'); - await device.relaunchApp({userNotification: 'json'}); + await device.relaunchApp({ userNotification: 'json' }); driverMock.expectLaunchCalledWithArgs(device, expectedArgs); }); @@ -389,7 +390,7 @@ describe('Device', () => { it(`(relaunch) with url and userNofitication should throw`, async () => { const device = await aValidDevice(); try { - await device.relaunchApp({url: "scheme://some.url", userNotification: 'notif'}); + await device.relaunchApp({ url: 'scheme://some.url', userNotification: 'notif' }); fail('should fail'); } catch (ex) { expect(ex).toBeDefined(); @@ -398,9 +399,9 @@ describe('Device', () => { it(`(relaunch) with permissions should send trigger setpermissions before app starts`, async () => { const device = await aValidDevice(); - await device.relaunchApp({permissions: {calendar: "YES"}}); + await device.relaunchApp({ permissions: { calendar: 'YES' } }); - expect(driverMock.driver.setPermissions).toHaveBeenCalledWith(device.id, device._bundleId, {calendar: "YES"}); + expect(driverMock.driver.setPermissions).toHaveBeenCalledWith(device.id, device._bundleId, { calendar: 'YES' }); }); it('with languageAndLocale should launch app with a specific language/locale', async () => { @@ -412,16 +413,16 @@ describe('Device', () => { locale: 'es-MX' }; - await device.launchApp({languageAndLocale}); + await device.launchApp({ languageAndLocale }); driverMock.expectLaunchCalledWithArgs(device, expectedArgs, languageAndLocale); }); it(`with disableTouchIndicators should send a boolean switch as a param in launchParams`, async () => { - const expectedArgs = {...expectedDriverArgs, "detoxDisableTouchIndicators": true}; + const expectedArgs = { ...expectedDriverArgs, 'detoxDisableTouchIndicators': true }; const device = await aValidDevice(); - await device.launchApp({disableTouchIndicators: true}); + await device.launchApp({ disableTouchIndicators: true }); driverMock.expectLaunchCalledWithArgs(device, expectedArgs); }); @@ -433,8 +434,8 @@ describe('Device', () => { device.deviceDriver.launchApp.mockReturnValue(processId); await device.prepare(); - await device.launchApp({newInstance: true}); - await device.launchApp({newInstance: false}); + await device.launchApp({ newInstance: true }); + await device.launchApp({ newInstance: false }); expect(driverMock.driver.deliverPayload).not.toHaveBeenCalled(); }); @@ -445,14 +446,14 @@ describe('Device', () => { device.deviceDriver.launchApp.mockReturnValue(processId); await device.prepare(); - await device.launchApp({newInstance: true}); - await device.launchApp({url: 'url://me'}); + await device.launchApp({ newInstance: true }); + await device.launchApp({ url: 'url://me' }); expect(driverMock.driver.deliverPayload).toHaveBeenCalledTimes(1); }); it(`with a url should check if process is in background and if not use launch args`, async () => { - const launchParams = {url: 'url://me'}; + const launchParams = { url: 'url://me' }; const processId = 1; const newProcessId = 2; @@ -466,21 +467,21 @@ describe('Device', () => { }); it(`with a url should check if process is in background and use openURL() instead of launch args`, async () => { - const launchParams = {url: 'url://me'}; + const launchParams = { url: 'url://me' }; const processId = 1; const device = await aValidDevice(); device.deviceDriver.launchApp.mockReturnValue(processId); await device.prepare(); - await device.launchApp({newInstance: true}); + await device.launchApp({ newInstance: true }); await device.launchApp(launchParams); - expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({delayPayload: true, url: 'url://me'}); + expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({ delayPayload: true, url: 'url://me' }); }); it('with userActivity should check if process is in background and if it is use deliverPayload', async () => { - const launchParams = {userActivity: 'userActivity'}; + const launchParams = { userActivity: 'userActivity' }; const processId = 1; const device = await aValidDevice(); @@ -488,15 +489,14 @@ describe('Device', () => { device.deviceDriver.createPayloadFile = () => 'url'; await device.prepare(); - await device.launchApp({newInstance: true}); + await device.launchApp({ newInstance: true }); await device.launchApp(launchParams); - expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({delayPayload: true, detoxUserActivityDataURL: 'url'}); + expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({ delayPayload: true, detoxUserActivityDataURL: 'url' }); }); - it('with userNotification should check if process is in background and if it is use deliverPayload', async () => { - const launchParams = {userNotification: 'notification'}; + const launchParams = { userNotification: 'notification' }; const processId = 1; const device = await aValidDevice(); @@ -504,14 +504,14 @@ describe('Device', () => { device.deviceDriver.createPayloadFile = () => 'url'; await device.prepare(); - await device.launchApp({newInstance: true}); + await device.launchApp({ newInstance: true }); await device.launchApp(launchParams); expect(driverMock.driver.deliverPayload).toHaveBeenCalledTimes(1); }); it(`with userNotification should check if process is in background and if not use launch args`, async () => { - const launchParams = {userNotification: 'notification'}; + const launchParams = { userNotification: 'notification' }; const processId = 1; const newProcessId = 2; @@ -525,7 +525,7 @@ describe('Device', () => { }); it(`with userNotification and url should fail`, async () => { - const launchParams = {userNotification: 'notification', url: 'url://me'}; + const launchParams = { userNotification: 'notification', url: 'url://me' }; const processId = 1; driverMock.driver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(processId); @@ -584,7 +584,7 @@ describe('Device', () => { }; const device = await aValidDevice(); - await device.launchApp({launchArgs}); + await device.launchApp({ launchArgs }); driverMock.expectLaunchCalledWithArgs(device, expectedArgs); }); @@ -802,9 +802,9 @@ describe('Device', () => { it(`openURL({url:url}) should pass to device driver`, async () => { const device = await aValidDevice(); - await device.openURL({url: 'url'}); + await device.openURL({ url: 'url' }); - expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({url: 'url'}, device.id); + expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({ url: 'url' }, device.id); }); it(`openURL(notAnObject) should pass to device driver`, async () => { @@ -956,7 +956,7 @@ describe('Device', () => { const result = await device.getUiDevice(); expect(result).toEqual(uiDevice); - }) + }); }); it('takeScreenshot(name) should throw an exception if given name is empty', async () => { diff --git a/detox/src/devices/DeviceRegistry.js b/detox/src/devices/DeviceRegistry.js index cd5a253b83..555ccfc65e 100644 --- a/detox/src/devices/DeviceRegistry.js +++ b/detox/src/devices/DeviceRegistry.js @@ -1,7 +1,8 @@ -const _ = require('lodash'); -const environment = require('../utils/environment'); const fs = require('fs-extra'); +const _ = require('lodash'); + const ExclusiveLockfile = require('../utils/ExclusiveLockfile'); +const environment = require('../utils/environment'); const safeAsync = require('../utils/safeAsync'); const readOptions = { @@ -111,7 +112,7 @@ class DeviceRegistry { let result = null; await this._lockfile.exclusively(() => { result = this.getRegisteredDevices(); - }) + }); return result; } diff --git a/detox/src/devices/DeviceRegistry.test.js b/detox/src/devices/DeviceRegistry.test.js index f65e210493..a5e70e0740 100644 --- a/detox/src/devices/DeviceRegistry.test.js +++ b/detox/src/devices/DeviceRegistry.test.js @@ -1,5 +1,6 @@ const fs = require('fs-extra'); const tempfile = require('tempfile'); + const environment = require('../utils/environment'); const deviceId = 'emulator-5554'; @@ -42,7 +43,7 @@ describe('DeviceRegistry', () => { return registry.allocateDevice(async () => { expect(registry.includes(deviceId)).toBe(false); throw new Error('ignored'); // So it wouldn't really allocate anything - }).catch((e) => { if (e.message !== 'ignored') throw e }); + }).catch((e) => { if (e.message !== 'ignored') throw e; }); } function expectIncludedInDevicesList(deviceId) { @@ -51,7 +52,7 @@ describe('DeviceRegistry', () => { expect(registeredDevices.includes(deviceId)).toEqual(true); throw new Error('ignored'); // So it wouldn't really allocate anything - }).catch((e) => { if (e.message !== 'ignored') throw e }); + }).catch((e) => { if (e.message !== 'ignored') throw e; }); } function expectDevicesListEquals(rawDevices) { @@ -60,7 +61,7 @@ describe('DeviceRegistry', () => { expect(registeredDevices.rawDevices).toStrictEqual(rawDevices); throw new Error('ignored'); // So it wouldn't really allocate anything - }).catch((e) => { if (e.message !== 'ignored') throw e }); + }).catch((e) => { if (e.message !== 'ignored') throw e; }); } async function expectIncludedInReadDevicesList(deviceId) { @@ -186,7 +187,7 @@ describe('DeviceRegistry', () => { await registry.reset(); expect(await fs.readFile(lockfilePath, 'utf8')).toBe('[]'); }); - }) + }); }); describe('instantiation methods', () => { diff --git a/detox/src/devices/LaunchArgsEditor.js b/detox/src/devices/LaunchArgsEditor.js index 6eac22905d..27e41121de 100644 --- a/detox/src/devices/LaunchArgsEditor.js +++ b/detox/src/devices/LaunchArgsEditor.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); class LaunchArgsEditor { diff --git a/detox/src/devices/LaunchArgsEditor.test.js b/detox/src/devices/LaunchArgsEditor.test.js index 593b7067c4..0005350a3d 100644 --- a/detox/src/devices/LaunchArgsEditor.test.js +++ b/detox/src/devices/LaunchArgsEditor.test.js @@ -62,7 +62,7 @@ describe('Device launch-args editor', () => { }; const expectedArgs = { argZ: 'valZ', - } + }; const launchArgsEditor = new LaunchArgsEditor(launchArgs); launchArgsEditor.modify(argsModifier); diff --git a/detox/src/devices/drivers/DeviceDriverBase.js b/detox/src/devices/drivers/DeviceDriverBase.js index c7504ce44c..10bfef2139 100644 --- a/detox/src/devices/drivers/DeviceDriverBase.js +++ b/detox/src/devices/drivers/DeviceDriverBase.js @@ -1,7 +1,9 @@ -const _ = require('lodash'); -const fs = require('fs-extra'); const os = require('os'); const path = require('path'); + +const fs = require('fs-extra'); +const _ = require('lodash'); + const log = require('../../utils/logger').child({ __filename }); class DeviceDriverBase { @@ -95,7 +97,7 @@ class DeviceDriverBase { } async clearKeychain(_udid) { - return await Promise.resolve('') + return await Promise.resolve(''); } async waitUntilReady() { diff --git a/detox/src/devices/drivers/android/AndroidDriver.js b/detox/src/devices/drivers/android/AndroidDriver.js index b8645d0afc..b66ddaac75 100644 --- a/detox/src/devices/drivers/android/AndroidDriver.js +++ b/detox/src/devices/drivers/android/AndroidDriver.js @@ -1,32 +1,36 @@ -const _ = require('lodash'); const path = require('path'); -const fs = require('fs-extra'); const URL = require('url').URL; -const DeviceDriverBase = require('../DeviceDriverBase'); -const logger = require('../../../utils/logger'); -const log = logger.child({ __filename }); -const ADB = require('./exec/ADB'); -const AAPT = require('./exec/AAPT'); -const APKPath = require('./tools/APKPath'); -const TempFileXfer = require('./tools/TempFileXfer'); -const AppInstallHelper = require('./tools/AppInstallHelper'); -const AppUninstallHelper = require('./tools/AppUninstallHelper'); -const MonitoredInstrumentation = require('./tools/MonitoredInstrumentation'); + +const fs = require('fs-extra'); +const _ = require('lodash'); + const DetoxApi = require('../../../android/espressoapi/Detox'); const EspressoDetoxApi = require('../../../android/espressoapi/EspressoDetox'); const UiDeviceProxy = require('../../../android/espressoapi/UiDeviceProxy'); const AndroidInstrumentsPlugin = require('../../../artifacts/instruments/android/AndroidInstrumentsPlugin'); const ADBLogcatPlugin = require('../../../artifacts/log/android/ADBLogcatPlugin'); const ADBScreencapPlugin = require('../../../artifacts/screenshot/ADBScreencapPlugin'); -const ADBScreenrecorderPlugin = require('../../../artifacts/video/ADBScreenrecorderPlugin'); -const AndroidDevicePathBuilder = require('../../../artifacts/utils/AndroidDevicePathBuilder'); const TimelineArtifactPlugin = require('../../../artifacts/timeline/TimelineArtifactPlugin'); +const AndroidDevicePathBuilder = require('../../../artifacts/utils/AndroidDevicePathBuilder'); const temporaryPath = require('../../../artifacts/utils/temporaryPath'); +const ADBScreenrecorderPlugin = require('../../../artifacts/video/ADBScreenrecorderPlugin'); const DetoxRuntimeError = require('../../../errors/DetoxRuntimeError'); -const sleep = require('../../../utils/sleep'); -const retry = require('../../../utils/retry'); -const pressAnyKey = require('../../../utils/pressAnyKey'); const getAbsoluteBinaryPath = require('../../../utils/getAbsoluteBinaryPath'); +const logger = require('../../../utils/logger'); +const pressAnyKey = require('../../../utils/pressAnyKey'); +const retry = require('../../../utils/retry'); +const sleep = require('../../../utils/sleep'); +const DeviceDriverBase = require('../DeviceDriverBase'); + +const AAPT = require('./exec/AAPT'); +const ADB = require('./exec/ADB'); +const APKPath = require('./tools/APKPath'); +const AppInstallHelper = require('./tools/AppInstallHelper'); +const AppUninstallHelper = require('./tools/AppUninstallHelper'); +const MonitoredInstrumentation = require('./tools/MonitoredInstrumentation'); +const TempFileXfer = require('./tools/TempFileXfer'); + +const log = logger.child({ __filename }); class AndroidDriver extends DeviceDriverBase { constructor(config) { @@ -263,7 +267,7 @@ class AndroidDriver extends DeviceDriverBase { _launchArgs = { ...launchArgs, detoxUserNotificationDataURL: notificationPayloadTargetPath, - } + }; } return _launchArgs; } @@ -360,8 +364,8 @@ class AndroidDriver extends DeviceDriverBase { return `${paddedKey} | ${paddedValue}`; }); - const keyHeader = 'Key'.padEnd(keyMaxLength, ' ') - const valueHeader = 'Value'.padEnd(valueMaxLength, ' ') + const keyHeader = 'Key'.padEnd(keyMaxLength, ' '); + const valueHeader = 'Value'.padEnd(valueMaxLength, ' '); const header = `${keyHeader} | ${valueHeader}`; const separator = '-'.repeat(header.length); diff --git a/detox/src/devices/drivers/android/AndroidDriver.test.js b/detox/src/devices/drivers/android/AndroidDriver.test.js index a46c3ca34a..9050b840f2 100644 --- a/detox/src/devices/drivers/android/AndroidDriver.test.js +++ b/detox/src/devices/drivers/android/AndroidDriver.test.js @@ -104,7 +104,7 @@ describe('Android driver', () => { const invokeTerminationCallbackFn = async () => { const fn = extractTerminationCallbackFn(); await fn(); - } + }; }); describe('App termination', () => { @@ -146,7 +146,7 @@ describe('Android driver', () => { const assertActivityStartInvoked = () => { expect(invocationManager.execute).toHaveBeenCalledWith(detoxApiInvocation); expect(detoxApi.startActivityFromUrl).toHaveBeenCalledWith(detoxURLOverride); - } + }; const assertActivityStartNotInvoked = () => expect(detoxApi.startActivityFromUrl).not.toHaveBeenCalled(); const assertInstrumentationLaunchedWith = (args) => expect(instrumentationObj().launch).toHaveBeenCalledWith(deviceId, bundleId, args); @@ -183,12 +183,12 @@ describe('Android driver', () => { const argsDelayed = { ...args, delayPayload: true, - } + }; it('should start the app via invocation-manager', async () => { mockStartActivityInvokeApi(); - await uut.launchApp(deviceId, bundleId, {}, '') + await uut.launchApp(deviceId, bundleId, {}, ''); await uut.deliverPayload(args, deviceId); assertActivityStartInvoked(); @@ -197,7 +197,7 @@ describe('Android driver', () => { it('should not start the app via invocation-manager', async () => { mockStartActivityInvokeApi(); - await uut.launchApp(deviceId, bundleId, {}, '') + await uut.launchApp(deviceId, bundleId, {}, ''); await uut.deliverPayload(argsDelayed, deviceId); assertActivityStartNotInvoked(); @@ -218,10 +218,10 @@ describe('Android driver', () => { const assertActivityStartInvoked = () => { expect(invocationManager.execute).toHaveBeenCalledWith(detoxApiInvocation); expect(detoxApi.startActivityFromNotification).toHaveBeenCalledWith(mockNotificationDataTargetPath); - } + }; const assertActivityStartNotInvoked = () => { expect(detoxApi.startActivityFromNotification).not.toHaveBeenCalled(); - } + }; const assertInstrumentationLaunchedWith = (args) => expect(instrumentationObj().launch).toHaveBeenCalledWith(deviceId, bundleId, args); const assertInstrumentationNotSpawned = () => expect(instrumentationObj().launch).not.toHaveBeenCalled(); @@ -238,7 +238,7 @@ describe('Android driver', () => { }); it('should not send the data if device prep fails', async () => { - fileXferObj().prepareDestinationDir.mockRejectedValue(new Error()) + fileXferObj().prepareDestinationDir.mockRejectedValue(new Error()); await expect(uut.launchApp(deviceId, bundleId, notificationArgs, '')).rejects.toThrowError(); }); @@ -287,17 +287,17 @@ describe('Android driver', () => { const notificationArgsDelayed = { ...notificationArgs, delayPayload: true, - } + }; it('should not send notification data is payload send-out is set as delayed', async () => { - await uut.launchApp(deviceId, bundleId, {}, '') + await uut.launchApp(deviceId, bundleId, {}, ''); await uut.deliverPayload(notificationArgsDelayed, deviceId); expect(fileXferObj().send).not.toHaveBeenCalled(); }); it('should not start the app using invocation-manager', async () => { - await uut.launchApp(deviceId, bundleId, {}, '') + await uut.launchApp(deviceId, bundleId, {}, ''); await uut.deliverPayload(notificationArgsDelayed, deviceId); assertActivityStartNotInvoked(); @@ -439,7 +439,7 @@ describe('Android driver', () => { aaptObj().getPackageName.mockResolvedValue(packageId); await uut.installUtilBinaries(deviceId, [binaryPath]); - expect(adbObj().isPackageInstalled).toHaveBeenCalledWith(deviceId, packageId) + expect(adbObj().isPackageInstalled).toHaveBeenCalledWith(deviceId, packageId); expect(aaptObj().getPackageName).toHaveBeenCalledWith(mockGetAbsoluteBinaryPathImpl(binaryPath)); }); }); @@ -535,7 +535,7 @@ describe('Android driver', () => { InstrumentationClass = require('./tools/MonitoredInstrumentation'); InstrumentationClass.mockImplementation(() => { mockInstrumentationDead(); - }) + }); jest.mock('./exec/ADB'); ADBClass = require('./exec/ADB'); @@ -560,7 +560,7 @@ describe('Android driver', () => { FileXferClass = require('./tools/TempFileXfer'); FileXferClass.mockImplementation(() => { const _this = latestInstanceOf(FileXferClass); - _this.send.mockResolvedValue(mockNotificationDataTargetPath) + _this.send.mockResolvedValue(mockNotificationDataTargetPath); }); jest.mock('./tools/AppInstallHelper'); diff --git a/detox/src/devices/drivers/android/attached/AttachedAndroidDriver.js b/detox/src/devices/drivers/android/attached/AttachedAndroidDriver.js index 44a2c0f71b..929cf5bdff 100644 --- a/detox/src/devices/drivers/android/attached/AttachedAndroidDriver.js +++ b/detox/src/devices/drivers/android/attached/AttachedAndroidDriver.js @@ -1,7 +1,8 @@ const _ = require('lodash'); + +const DeviceRegistry = require('../../../DeviceRegistry'); const AndroidDriver = require('../AndroidDriver'); const FreeDeviceFinder = require('../tools/FreeDeviceFinder'); -const DeviceRegistry = require('../../../DeviceRegistry'); class AttachedAndroidDriver extends AndroidDriver { constructor(config) { diff --git a/detox/src/devices/drivers/android/emulator/AVDValidator.js b/detox/src/devices/drivers/android/emulator/AVDValidator.js index 260f20bdac..2dde5aecf4 100644 --- a/detox/src/devices/drivers/android/emulator/AVDValidator.js +++ b/detox/src/devices/drivers/android/emulator/AVDValidator.js @@ -1,6 +1,7 @@ const _ = require('lodash'); -const environment = require('../../../../utils/environment'); + const DetoxRuntimeError = require('../../../../errors/DetoxRuntimeError'); +const environment = require('../../../../utils/environment'); const logger = require('../../../../utils/logger').child({ __filename }); const REQUIRED_EMULATOR_MAJOR = 29; diff --git a/detox/src/devices/drivers/android/emulator/AVDValidator.test.js b/detox/src/devices/drivers/android/emulator/AVDValidator.test.js index 2f60f6d01c..f67ac1956d 100644 --- a/detox/src/devices/drivers/android/emulator/AVDValidator.test.js +++ b/detox/src/devices/drivers/android/emulator/AVDValidator.test.js @@ -37,7 +37,7 @@ describe('AVD validator', () => { minor: 0, patch: 0, toString: () => '29.x.y', - }) + }); const givenUnknownEmulatorVersion = () => versionResolver.resolve.mockResolvedValue(null); const givenMockedAvdManagerPath = () => environment.getAvdManagerPath.mockReturnValue('mock/path/avdmng'); diff --git a/detox/src/devices/drivers/android/emulator/EmulatorDriver.js b/detox/src/devices/drivers/android/emulator/EmulatorDriver.js index cf3c56031a..9865d4ca5b 100644 --- a/detox/src/devices/drivers/android/emulator/EmulatorDriver.js +++ b/detox/src/devices/drivers/android/emulator/EmulatorDriver.js @@ -1,20 +1,23 @@ -const _ = require('lodash'); const fs = require('fs'); const path = require('path'); + const ini = require('ini'); +const _ = require('lodash'); + +const DetoxRuntimeError = require('../../../../errors/DetoxRuntimeError'); +const argparse = require('../../../../utils/argparse'); +const environment = require('../../../../utils/environment'); +const log = require('../../../../utils/logger').child({ __filename }); +const DeviceRegistry = require('../../../DeviceRegistry'); const AndroidDriver = require('../AndroidDriver'); -const EmulatorDeviceAllocation = require('./helpers/EmulatorDeviceAllocation'); +const { EmulatorExec } = require('../exec/EmulatorExec'); + const AVDValidator = require('./AVDValidator'); const AVDsResolver = require('./AVDsResolver'); -const EmulatorLauncher = require('./helpers/EmulatorLauncher'); const EmulatorVersionResolver = require('./EmulatorVersionResolver'); const FreeEmulatorFinder = require('./FreeEmulatorFinder'); -const { EmulatorExec } = require('../exec/EmulatorExec'); -const DeviceRegistry = require('../../../DeviceRegistry'); -const DetoxRuntimeError = require('../../../../errors/DetoxRuntimeError'); -const environment = require('../../../../utils/environment'); -const log = require('../../../../utils/logger').child({ __filename }); -const argparse = require('../../../../utils/argparse'); +const EmulatorDeviceAllocation = require('./helpers/EmulatorDeviceAllocation'); +const EmulatorLauncher = require('./helpers/EmulatorLauncher'); const EMU_BIN_STABLE_SKIN_VER = 28; @@ -31,7 +34,7 @@ class EmulatorDriver extends AndroidDriver { const avdsResolver = new AVDsResolver(emulatorExec); this._avdValidator = new AVDValidator(avdsResolver, this._emuVersionResolver); - const freeEmulatorFinder = new FreeEmulatorFinder(this.adb, this._deviceRegistry) + const freeEmulatorFinder = new FreeEmulatorFinder(this.adb, this._deviceRegistry); this._deviceAllocation = new EmulatorDeviceAllocation(this._deviceRegistry, freeEmulatorFinder, this._emulatorLauncher, this.adb, this.emitter); } @@ -74,7 +77,7 @@ class EmulatorDriver extends AndroidDriver { try { await super.cleanup(deviceId, bundleId); } finally { - await this._deviceAllocation.deallocateDevice(deviceId) + await this._deviceAllocation.deallocateDevice(deviceId); } } diff --git a/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.js b/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.js index bd376c13d4..2532b7d725 100644 --- a/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.js +++ b/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.js @@ -1,5 +1,5 @@ -const {QueryVersionCommand} = require('../exec/EmulatorExec'); const log = require('../../../../utils/logger').child({ __filename }); +const { QueryVersionCommand } = require('../exec/EmulatorExec'); const EMU_BIN_VERSION_DETECT_EV = 'EMU_BIN_VERSION_DETECT'; @@ -37,7 +37,7 @@ class EmulatorVersionResolver { } _parseVersionString(versionRaw) { - const [major, minor, patch] = versionRaw.split('\.'); + const [major, minor, patch] = versionRaw.split('.'); return { major: Number(major), minor: Number(minor), diff --git a/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.test.js b/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.test.js index 102e12856c..cc865f8791 100644 --- a/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.test.js +++ b/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.test.js @@ -1,15 +1,15 @@ describe('Emulator binary version', () => { const versionResult = [ 'Android emulator version 30.1.2.3 (build_id 6306047) (CL:N/A)', - "Copyright (C) 2006-2017 The Android Open Source Project and many others.", - "This program is a derivative of the QEMU CPU emulator (www.qemu.org).", - " This software is licensed under the terms of the GNU General Public", - " License version 2, as published by the Free Software Foundation, and", - " may be copied, distributed, and modified under those terms.", - " This program is distributed in the hope that it will be useful,", - " but WITHOUT ANY WARRANTY; without even the implied warranty of", - " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", - " GNU General Public License for more details.", + 'Copyright (C) 2006-2017 The Android Open Source Project and many others.', + 'This program is a derivative of the QEMU CPU emulator (www.qemu.org).', + ' This software is licensed under the terms of the GNU General Public', + ' License version 2, as published by the Free Software Foundation, and', + ' may be copied, distributed, and modified under those terms.', + ' This program is distributed in the hope that it will be useful,', + ' but WITHOUT ANY WARRANTY; without even the implied warranty of', + ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the', + ' GNU General Public License for more details.', ].join('\n'); const expectedVersion = { major: 30, @@ -63,7 +63,7 @@ describe('Emulator binary version', () => { }); it('should return null for a query result that has an invalid syntax', async () => { - emulatorExec.exec.mockResolvedValue('Android emulator version \ (build_id 6306047) (CL:N/A)'); + emulatorExec.exec.mockResolvedValue('Android emulator version (build_id 6306047) (CL:N/A)'); const version = await uut.resolve(); expect(version).toEqual(null); }); @@ -71,7 +71,7 @@ describe('Emulator binary version', () => { it('should log in case of a parsing error', async () => { emulatorExec.exec.mockResolvedValue('non-parsable result'); await uut.resolve(); - expect(log.warn).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: false}, expect.any(String), 'non-parsable result'); + expect(log.warn).toHaveBeenCalledWith({ event: 'EMU_BIN_VERSION_DETECT', success: false }, expect.any(String), 'non-parsable result'); }); it('should return null in case of a version-query failure', async () => { @@ -84,7 +84,7 @@ describe('Emulator binary version', () => { const error = new Error('some error'); emulatorExec.exec.mockRejectedValue(error); await uut.resolve(); - expect(log.error).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: false, error}, expect.any(String), error); + expect(log.error).toHaveBeenCalledWith({ event: 'EMU_BIN_VERSION_DETECT', success: false, error }, expect.any(String), error); }); it('should cache the version', async () => { @@ -97,6 +97,6 @@ describe('Emulator binary version', () => { it('should log the version', async () => { await uut.resolve(); - expect(log.debug).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: true}, expect.any(String), expect.objectContaining(expectedVersion)); + expect(log.debug).toHaveBeenCalledWith({ event: 'EMU_BIN_VERSION_DETECT', success: true }, expect.any(String), expect.objectContaining(expectedVersion)); }); }); diff --git a/detox/src/devices/drivers/android/emulator/FreeEmulatorFinder.test.js b/detox/src/devices/drivers/android/emulator/FreeEmulatorFinder.test.js index d799ffb943..afeb7f8552 100644 --- a/detox/src/devices/drivers/android/emulator/FreeEmulatorFinder.test.js +++ b/detox/src/devices/drivers/android/emulator/FreeEmulatorFinder.test.js @@ -1,4 +1,4 @@ -const { mockAvdName, emulator5556, localhost5555 } = require('../tools/__mocks__/handles'); +const { emulator5556, localhost5555, mockAvdName } = require('../tools/__mocks__/handles'); describe('FreeEmulatorFinder', () => { const mockAdb = { devices: jest.fn() }; diff --git a/detox/src/devices/drivers/android/emulator/helpers/EmulatorDeviceAllocation.js b/detox/src/devices/drivers/android/emulator/helpers/EmulatorDeviceAllocation.js index bc8375e58c..37f6e96555 100644 --- a/detox/src/devices/drivers/android/emulator/helpers/EmulatorDeviceAllocation.js +++ b/detox/src/devices/drivers/android/emulator/helpers/EmulatorDeviceAllocation.js @@ -1,8 +1,8 @@ -const AndroidDeviceAllocation = require('../../AndroidDeviceAllocation'); const DetoxRuntimeError = require('../../../../../errors/DetoxRuntimeError'); const logger = require('../../../../../utils/logger').child({ __filename }); const retry = require('../../../../../utils/retry'); const { traceCall } = require('../../../../../utils/trace'); +const AndroidDeviceAllocation = require('../../AndroidDeviceAllocation'); const DetoxEmulatorsPortRange = { min: 10000, diff --git a/detox/src/devices/drivers/android/emulator/helpers/EmulatorLauncher.js b/detox/src/devices/drivers/android/emulator/helpers/EmulatorLauncher.js index 51cd7476fc..7ce0434f5e 100644 --- a/detox/src/devices/drivers/android/emulator/helpers/EmulatorLauncher.js +++ b/detox/src/devices/drivers/android/emulator/helpers/EmulatorLauncher.js @@ -1,11 +1,13 @@ -const _ = require('lodash'); const fs = require('fs'); + +const _ = require('lodash'); const Tail = require('tail').Tail; -const AndroidDeviceLauncher = require('../../AndroidDeviceLauncher'); -const EmulatorTelnet = require('../../tools/EmulatorTelnet'); -const { LaunchCommand } = require('../../exec/EmulatorExec'); + const unitLogger = require('../../../../../utils/logger').child({ __filename }); const retry = require('../../../../../utils/retry'); +const AndroidDeviceLauncher = require('../../AndroidDeviceLauncher'); +const { LaunchCommand } = require('../../exec/EmulatorExec'); +const EmulatorTelnet = require('../../tools/EmulatorTelnet'); const isUnknownEmulatorError = (err) => (err.message || '').includes('failed with code null'); @@ -16,7 +18,7 @@ class EmulatorLauncher extends AndroidDeviceLauncher { this._telnetGeneratorFn = telnetGeneratorFn; } - async launch(emulatorName, options = {port: undefined}) { + async launch(emulatorName, options = { port: undefined }) { const launchCommand = new LaunchCommand(emulatorName, options); return await retry({ @@ -48,7 +50,7 @@ class EmulatorLauncher extends AndroidDeviceLauncher { }, }; const tail = new Tail(tempLog, tailOptions) - .on("line", (line) => { + .on('line', (line) => { if (line.includes('Adb connected, start proxing data')) { childProcessPromise._cpResolve(); } diff --git a/detox/src/devices/drivers/android/exec/AAPT.js b/detox/src/devices/drivers/android/exec/AAPT.js index fb5928fa7f..b3b5b9e3a2 100644 --- a/detox/src/devices/drivers/android/exec/AAPT.js +++ b/detox/src/devices/drivers/android/exec/AAPT.js @@ -1,4 +1,4 @@ -const {getAaptPath} = require('../../../../utils/environment'); +const { getAaptPath } = require('../../../../utils/environment'); const exec = require('../../../../utils/exec').execWithRetriesAndLogs; const escape = require('../../../../utils/pipeCommands').escape.inQuotedString; const egrep = require('../../../../utils/pipeCommands').search.fragment; @@ -15,7 +15,7 @@ class AAPT { async getPackageName(apkPath) { await this._prepare(); const process = await exec( - `${this.aaptBin} dump badging "${escape(apkPath)}" | ${egrep("package: name=")}`, + `${this.aaptBin} dump badging "${escape(apkPath)}" | ${egrep('package: name=')}`, { retries: 1 } ); diff --git a/detox/src/devices/drivers/android/exec/AAPT.test.js b/detox/src/devices/drivers/android/exec/AAPT.test.js index 245c08e179..31efd8580c 100644 --- a/detox/src/devices/drivers/android/exec/AAPT.test.js +++ b/detox/src/devices/drivers/android/exec/AAPT.test.js @@ -14,13 +14,13 @@ xdescribe('AAPT', () => { }); it(`Parse 'aapt dump badging' output`, async () => { - exec.mockReturnValueOnce(Promise.resolve({stdout: AAPTOutputMock})); + exec.mockReturnValueOnce(Promise.resolve({ stdout: AAPTOutputMock })); const pacakageName = await aapt.getPackageName('path/to/file.apk'); expect(pacakageName).toEqual('com.wix.detox.test'); }); it(`Configure aaptBin only once`, async () => { - exec.mockReturnValue(Promise.resolve({stdout: AAPTOutputMock})); + exec.mockReturnValue(Promise.resolve({ stdout: AAPTOutputMock })); await aapt.getPackageName('path/to/file.apk'); await aapt.getPackageName('path/to/file.apk'); }); diff --git a/detox/src/devices/drivers/android/exec/ADB.js b/detox/src/devices/drivers/android/exec/ADB.js index 4cfd1dc176..b198bba4cc 100644 --- a/detox/src/devices/drivers/android/exec/ADB.js +++ b/detox/src/devices/drivers/android/exec/ADB.js @@ -1,8 +1,9 @@ const _ = require('lodash'); -const {execWithRetriesAndLogs, spawnAndLog} = require('../../../../utils/exec'); -const {escape} = require('../../../../utils/pipeCommands'); + const DetoxRuntimeError = require('../../../../errors/DetoxRuntimeError'); -const {getAdbPath} = require('../../../../utils/environment'); +const { getAdbPath } = require('../../../../utils/environment'); +const { execWithRetriesAndLogs, spawnAndLog } = require('../../../../utils/exec'); +const { escape } = require('../../../../utils/pipeCommands'); const DeviceHandle = require('../tools/DeviceHandle'); const EmulatorHandle = require('../tools/EmulatorHandle'); @@ -13,7 +14,7 @@ class ADB { } async devices() { - const {stdout} = await this.adbCmd('', 'devices', { verbosity: 'high' }); + const { stdout } = await this.adbCmd('', 'devices', { verbosity: 'high' }); const devices = _.chain(stdout) .trim() .split('\n') @@ -117,7 +118,7 @@ class ADB { async pidof(deviceId, bundleId) { const bundleIdRegex = escape.inQuotedRegexp(bundleId) + '$'; - const processes = await this.shell(deviceId, `ps | grep "${bundleIdRegex}"`, {silent: true}).catch(() => ''); + const processes = await this.shell(deviceId, `ps | grep "${bundleIdRegex}"`, { silent: true }).catch(() => ''); if (!processes) { return NaN; } @@ -169,7 +170,7 @@ class ADB { * @returns ChildProcessPromise */ screenrecord(deviceId, { path, size, bitRate, timeLimit, verbose }) { - const [ width = 0, height = 0 ] = size || []; + const [width = 0, height = 0] = size || []; const _size = (width > 0) && (height > 0) ? ['--size', `${width}x${height}`] @@ -259,7 +260,7 @@ class ADB { } _instrumentationRunnerForBundleId(instrumentationRunners, bundleId) { - const runnerForBundleRegEx = new RegExp(`^instrumentation:(.*) \\(target=${bundleId.replace(new RegExp('\\.', 'g'), "\\.")}\\)$`, 'gm'); + const runnerForBundleRegEx = new RegExp(`^instrumentation:(.*) \\(target=${bundleId.replace(new RegExp('\\.', 'g'), '\\.')}\\)$`, 'gm'); return _.get(runnerForBundleRegEx.exec(instrumentationRunners), [1], 'undefined'); } @@ -282,7 +283,7 @@ class ADB { const _options = { retries: 1, ...options, - } + }; return execWithRetriesAndLogs(cmd, _options); } diff --git a/detox/src/devices/drivers/android/exec/ADB.test.js b/detox/src/devices/drivers/android/exec/ADB.test.js index 98fa32e893..97a7219ae5 100644 --- a/detox/src/devices/drivers/android/exec/ADB.test.js +++ b/detox/src/devices/drivers/android/exec/ADB.test.js @@ -74,7 +74,7 @@ describe('ADB', () => { stdout: 'List of devices attached\n' }); - const {devices} = await adb.devices(); + const { devices } = await adb.devices(); expect(devices.length).toEqual(0); }); }); @@ -245,13 +245,13 @@ describe('ADB', () => { }); it(`getInstrumentationRunner parses the correct runner for the package`, async () => { - const expectedRunner = "com.example.android.apis/.app.LocalSampleInstrumentation"; - const expectedPackage = "com.example.android.apis"; + const expectedRunner = 'com.example.android.apis/.app.LocalSampleInstrumentation'; + const expectedPackage = 'com.example.android.apis'; const instrumentationRunnersShellOutput = - "instrumentation:com.android.emulator.smoketests/android.support.test.runner.AndroidJUnitRunner (target=com.android.emulator.smoketests)\n" + - "instrumentation:com.android.smoketest.tests/com.android.smoketest.SmokeTestRunner (target=com.android.smoketest)\n" + + 'instrumentation:com.android.emulator.smoketests/android.support.test.runner.AndroidJUnitRunner (target=com.android.emulator.smoketests)\n' + + 'instrumentation:com.android.smoketest.tests/com.android.smoketest.SmokeTestRunner (target=com.android.smoketest)\n' + `instrumentation:${expectedRunner} (target=${expectedPackage})\n` + - "instrumentation:org.chromium.webview_shell/.WebViewLayoutTestRunner (target=org.chromium.webview_shell)\n"; + 'instrumentation:org.chromium.webview_shell/.WebViewLayoutTestRunner (target=org.chromium.webview_shell)\n'; jest.spyOn(adb, 'shell').mockImplementation(async () => instrumentationRunnersShellOutput); diff --git a/detox/src/devices/drivers/android/exec/BinaryExec.js b/detox/src/devices/drivers/android/exec/BinaryExec.js index 668ede02cb..dbb24fa40f 100644 --- a/detox/src/devices/drivers/android/exec/BinaryExec.js +++ b/detox/src/devices/drivers/android/exec/BinaryExec.js @@ -1,4 +1,5 @@ const spawn = require('child-process-promise').spawn; + const exec = require('../../../../utils/exec').execWithRetriesAndLogs; class ExecCommand { diff --git a/detox/src/devices/drivers/android/exec/BinaryExec.test.js b/detox/src/devices/drivers/android/exec/BinaryExec.test.js index e1e16fcaec..d3ce14b0d1 100644 --- a/detox/src/devices/drivers/android/exec/BinaryExec.test.js +++ b/detox/src/devices/drivers/android/exec/BinaryExec.test.js @@ -1,5 +1,5 @@ describe('BinaryExec', () => { - const binaryPath = "/binary/mock"; + const binaryPath = '/binary/mock'; let exec; let spawn; @@ -17,7 +17,7 @@ describe('BinaryExec', () => { })); spawn = require('child-process-promise').spawn; - const {BinaryExec} = require('./BinaryExec'); + const { BinaryExec } = require('./BinaryExec'); binaryExec = new BinaryExec(binaryPath); }); @@ -27,7 +27,7 @@ describe('BinaryExec', () => { describe('exec-command', () => { it('exec-command should return args as toString()', () => { - const {ExecCommand} = require('./BinaryExec'); + const { ExecCommand } = require('./BinaryExec'); class MockExecCommand extends ExecCommand { _getArgsString() { return 'test args'; @@ -61,7 +61,7 @@ describe('BinaryExec', () => { }; exec.mockResolvedValue(execResult); - const {ExecCommand} = require('./BinaryExec'); + const { ExecCommand } = require('./BinaryExec'); const command = new ExecCommand(); const result = await binaryExec.exec(command); @@ -100,19 +100,19 @@ describe('BinaryExec', () => { }); const anEmptyCommand = () => { - const {ExecCommand} = require('./BinaryExec'); + const { ExecCommand } = require('./BinaryExec'); return new ExecCommand(); }; const aCommandMockWithArgsString = (argsString) => { - const {ExecCommand} = jest.genMockFromModule('./BinaryExec'); + const { ExecCommand } = jest.genMockFromModule('./BinaryExec'); const command = new ExecCommand(); command._getArgsString.mockReturnValue(argsString); return command; }; const aCommandMockWithArgs = (commandArgs) => { - const {ExecCommand} = jest.genMockFromModule('./BinaryExec'); + const { ExecCommand } = jest.genMockFromModule('./BinaryExec'); const command = new ExecCommand(); command._getArgs.mockReturnValue(commandArgs); return command; diff --git a/detox/src/devices/drivers/android/exec/EmulatorExec.js b/detox/src/devices/drivers/android/exec/EmulatorExec.js index 6db90f7cf4..f5252303bd 100644 --- a/detox/src/devices/drivers/android/exec/EmulatorExec.js +++ b/detox/src/devices/drivers/android/exec/EmulatorExec.js @@ -1,10 +1,13 @@ -const _ = require('lodash'); const os = require('os'); + +const _ = require('lodash'); + const argparse = require('../../../../utils/argparse'); const { getAndroidEmulatorPath } = require('../../../../utils/environment'); + const { - ExecCommand, BinaryExec, + ExecCommand, } = require('./BinaryExec'); class EmulatorExec extends BinaryExec { diff --git a/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.js b/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.js index e9298add36..8cba8e8dfc 100644 --- a/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.js +++ b/detox/src/devices/drivers/android/genycloud/GenyCloudDriver.js @@ -1,19 +1,21 @@ const semver = require('semver'); const onSignalExit = require('signal-exit'); + +const DetoxRuntimeError = require('../../../../errors/DetoxRuntimeError'); +const environment = require('../../../../utils/environment'); +const logger = require('../../../../utils/logger').child({ __filename }); const AndroidDriver = require('../AndroidDriver'); -const InstanceLauncher = require('./helpers/GenyCloudInstanceLauncher'); -const GenyCloudInstanceAllocation = require('./helpers/GenyCloudInstanceAllocation'); + const GenyDeviceRegistryFactory = require('./GenyDeviceRegistryFactory'); const GenyCloudExec = require('./exec/GenyCloudExec'); -const RecipesService = require('./services/GenyRecipesService'); -const InstanceLookupService = require('./services/GenyInstanceLookupService'); +const GenyCloudInstanceAllocation = require('./helpers/GenyCloudInstanceAllocation'); +const InstanceLauncher = require('./helpers/GenyCloudInstanceLauncher'); +const RecipeQuerying = require('./helpers/GenyRecipeQuerying'); +const AuthService = require('./services/GenyAuthService'); const InstanceLifecycleService = require('./services/GenyInstanceLifecycleService'); +const InstanceLookupService = require('./services/GenyInstanceLookupService'); const InstanceNaming = require('./services/GenyInstanceNaming'); -const AuthService = require('./services/GenyAuthService'); -const RecipeQuerying = require('./helpers/GenyRecipeQuerying'); -const DetoxRuntimeError = require('../../../../errors/DetoxRuntimeError'); -const logger = require('../../../../utils/logger').child({ __filename }); -const environment = require('../../../../utils/environment'); +const RecipesService = require('./services/GenyRecipesService'); const MIN_GMSAAS_VERSION = '1.6.0'; const cleanupLogData = { diff --git a/detox/src/devices/drivers/android/genycloud/GenyDeviceRegistryFactory.js b/detox/src/devices/drivers/android/genycloud/GenyDeviceRegistryFactory.js index ef1ca2b565..891c6fb3b2 100644 --- a/detox/src/devices/drivers/android/genycloud/GenyDeviceRegistryFactory.js +++ b/detox/src/devices/drivers/android/genycloud/GenyDeviceRegistryFactory.js @@ -1,5 +1,5 @@ -const DeviceRegistry = require('../../../DeviceRegistry'); const environment = require('../../../../utils/environment'); +const DeviceRegistry = require('../../../DeviceRegistry'); class GenyDeviceRegistryFactory { forRuntime() { diff --git a/detox/src/devices/drivers/android/genycloud/GenyDeviceRegistryFactory.test.js b/detox/src/devices/drivers/android/genycloud/GenyDeviceRegistryFactory.test.js index 3c5d108500..92a424cc20 100644 --- a/detox/src/devices/drivers/android/genycloud/GenyDeviceRegistryFactory.test.js +++ b/detox/src/devices/drivers/android/genycloud/GenyDeviceRegistryFactory.test.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const environment = require('../../../../utils/environment'); const latestInstanceOf = (clazz) => _.last(clazz.mock.instances); diff --git a/detox/src/devices/drivers/android/genycloud/exec/GenyCloudExec.test.js b/detox/src/devices/drivers/android/genycloud/exec/GenyCloudExec.test.js index e589f5a302..3731c640b5 100644 --- a/detox/src/devices/drivers/android/genycloud/exec/GenyCloudExec.test.js +++ b/detox/src/devices/drivers/android/genycloud/exec/GenyCloudExec.test.js @@ -72,7 +72,7 @@ describe('Genymotion-cloud executable', () => { commandName: 'Start Instance', commandExecFn: () => uut.startInstance(recipeUUID, instanceName), expectedExec: `"mock/path/to/gmsaas" --format compactjson instances start --stop-when-inactive --no-wait ${recipeUUID} "${instanceName}"`, - expectedExecOptions: { retries: 0}, + expectedExecOptions: { retries: 0 }, }, { commandName: 'ADB Connect', @@ -95,7 +95,7 @@ describe('Genymotion-cloud executable', () => { statusLogs: { retrying: true, } - } + }; await testCase.commandExecFn(); expect(exec).toHaveBeenCalledWith( diff --git a/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceAllocation.js b/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceAllocation.js index 49e25ee514..ff87688a30 100644 --- a/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceAllocation.js +++ b/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceAllocation.js @@ -1,7 +1,7 @@ -const AndroidDeviceAllocation = require('../../AndroidDeviceAllocation'); const DetoxRuntimeError = require('../../../../../errors/DetoxRuntimeError'); -const retry = require('../../../../../utils/retry'); const logger = require('../../../../../utils/logger').child({ __filename }); +const retry = require('../../../../../utils/retry'); +const AndroidDeviceAllocation = require('../../AndroidDeviceAllocation'); const { ALLOCATE_DEVICE_LOG_EVT } = AndroidDeviceAllocation; @@ -50,7 +50,7 @@ class GenyCloudInstanceAllocation extends AndroidDeviceAllocation { return { instance, isNew, - } + }; } async _waitForInstanceBoot(instance) { diff --git a/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceAllocation.test.js b/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceAllocation.test.js index 9351b21697..b21ca45714 100644 --- a/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceAllocation.test.js +++ b/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceAllocation.test.js @@ -77,7 +77,7 @@ describe('Genymotion-Cloud instance allocation', () => { return instance; }; - const givenFreeInstance = (instance) => instanceLookupService.findFreeInstance.mockResolvedValueOnce(instance) + const givenFreeInstance = (instance) => instanceLookupService.findFreeInstance.mockResolvedValueOnce(instance); const givenNoFreeInstances = () => instanceLookupService.findFreeInstance.mockResolvedValue(undefined); const givenCreatedInstance = (instance) => instanceLifecycleService.createInstance.mockResolvedValueOnce(instance); const givenConnectionInstance = (instance) => instanceLifecycleService.adbConnectInstance.mockResolvedValue(instance); @@ -295,7 +295,7 @@ describe('Genymotion-Cloud instance allocation', () => { describe('Deallocation', () => { it('should dispose the instance from the standard device registry', async () => { const instance = anOnlineInstance(); - await uut.deallocateDevice(instance.uuid) + await uut.deallocateDevice(instance.uuid); expect(deviceRegistry.disposeDevice).toHaveBeenCalledWith(instance.uuid); }); diff --git a/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.test.js b/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.test.js index 0886691a3f..234c74f677 100644 --- a/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.test.js +++ b/detox/src/devices/drivers/android/genycloud/helpers/GenyCloudInstanceLauncher.test.js @@ -4,7 +4,7 @@ describe('Genymotion-Cloud instance launcher', () => { instance.uuid = 'mock-instance-uuid'; instance.name = 'mock-instance-name'; return instance; - } + }; const givenAnInstanceDeletionError = () => instanceLifecycleService.deleteInstance.mockRejectedValue(new Error()); diff --git a/detox/src/devices/drivers/android/genycloud/services/GenyInstanceNaming.test.js b/detox/src/devices/drivers/android/genycloud/services/GenyInstanceNaming.test.js index a81ca38fba..1fe2de8fb6 100644 --- a/detox/src/devices/drivers/android/genycloud/services/GenyInstanceNaming.test.js +++ b/detox/src/devices/drivers/android/genycloud/services/GenyInstanceNaming.test.js @@ -16,7 +16,7 @@ describe('Genymotion-Cloud instance unique-name strategy', () => { afterAll(() => { delete process.env.DETOX_START_TIMESTAMP; process.env.JEST_WORKER_ID = JEST_WORKER_ID; - }) + }); it('should generate a session-scope unique name', () => { expect(uut.generateName().startsWith('Detox-123456.')).toEqual(true); diff --git a/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.js b/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.js index 553d95ab6e..238c162f09 100644 --- a/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.js +++ b/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.js @@ -15,7 +15,7 @@ class GenyRecipesService { if (recipes.length > 1) { const recipesInfoList = recipes.map((recipe) => ` ${recipe.name} (${recipe.uuid})`).join('\n'); this.logger.warn( - { event: 'GENYCLOUD_RECIPE_LOOKUP'}, + { event: 'GENYCLOUD_RECIPE_LOOKUP' }, `More than one Genymotion-Cloud recipe found for recipe name ${recipeName}:\n${recipesInfoList}\nFalling back to ${recipes[0].name}` ); } diff --git a/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.test.js b/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.test.js index c4c90f1144..43c42f9cca 100644 --- a/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.test.js +++ b/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.test.js @@ -7,9 +7,9 @@ describe('Genymotion-Cloud recipes service', () => { const givenRecipes = (...recipes) => { exec.getRecipe.mockResolvedValue({ - recipes: [ ...recipes ], + recipes: [...recipes], }); - } + }; const aRecipe = () => ({ uuid: 'mock-recipe-uuid', diff --git a/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.js b/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.js index 44435a47e0..896fc316da 100644 --- a/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.js +++ b/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.js @@ -30,7 +30,7 @@ class GenyInstance { this.adb = { name: rawInstance.adb_serial, port: rawInstance.adb_serial_port, - } + }; this.recipe = new Recipe(rawInstance.recipe); } diff --git a/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.test.js b/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.test.js index b05fb138d5..556d46f80a 100644 --- a/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.test.js +++ b/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.test.js @@ -7,7 +7,7 @@ describe('Genymotion-Cloud Instance DTO', () => { uuid: 'mock-recipe-uuid', name: 'mock-recipe-name', }, - } + }; const disconnectedRawInstance = { ...rawInstance, diff --git a/detox/src/devices/drivers/android/tools/APKPath.js b/detox/src/devices/drivers/android/tools/APKPath.js index 41c4bebaea..19ae537f86 100644 --- a/detox/src/devices/drivers/android/tools/APKPath.js +++ b/detox/src/devices/drivers/android/tools/APKPath.js @@ -1,5 +1,7 @@ const path = require('path'); + const _ = require('lodash'); + const string = require('../../../../utils/string'); class APKPath { diff --git a/detox/src/devices/drivers/android/tools/EmulatorTelnet.js b/detox/src/devices/drivers/android/tools/EmulatorTelnet.js index d1207c9f48..d258ec9569 100644 --- a/detox/src/devices/drivers/android/tools/EmulatorTelnet.js +++ b/detox/src/devices/drivers/android/tools/EmulatorTelnet.js @@ -1,7 +1,9 @@ -const Telnet = require('telnet-client'); -const path = require('path'); const os = require('os'); +const path = require('path'); + const fs = require('fs-extra'); +const Telnet = require('telnet-client'); + const log = require('../../../../utils/logger').child({ __filename }); class EmulatorTelnet { diff --git a/detox/src/devices/drivers/android/tools/FreeDeviceFinder.test.js b/detox/src/devices/drivers/android/tools/FreeDeviceFinder.test.js index 2c38983dd9..6e8b6ea55b 100644 --- a/detox/src/devices/drivers/android/tools/FreeDeviceFinder.test.js +++ b/detox/src/devices/drivers/android/tools/FreeDeviceFinder.test.js @@ -1,5 +1,5 @@ const FreeDeviceFinder = require('./FreeDeviceFinder'); -const { deviceOffline, emulator5556, localhost5555, ip5557 } = require('./__mocks__/handles'); +const { deviceOffline, emulator5556, ip5557, localhost5555 } = require('./__mocks__/handles'); describe('FreeDeviceFinder', () => { const mockAdb = { devices: jest.fn() }; diff --git a/detox/src/devices/drivers/android/tools/Instrumentation.js b/detox/src/devices/drivers/android/tools/Instrumentation.js index b7f9f36aac..3ecf48fb03 100644 --- a/detox/src/devices/drivers/android/tools/Instrumentation.js +++ b/detox/src/devices/drivers/android/tools/Instrumentation.js @@ -1,5 +1,7 @@ const _ = require('lodash'); + const { interruptProcess } = require('../../../../utils/exec'); + const { prepareInstrumentationArgs } = require('./instrumentationArgs'); class Instrumentation { diff --git a/detox/src/devices/drivers/android/tools/Instrumentation.test.js b/detox/src/devices/drivers/android/tools/Instrumentation.test.js index 31089ed683..ab6d71d583 100644 --- a/detox/src/devices/drivers/android/tools/Instrumentation.test.js +++ b/detox/src/devices/drivers/android/tools/Instrumentation.test.js @@ -15,11 +15,11 @@ describe('Instrumentation', () => { jest.mock('./instrumentationArgs'); instrumentationArgs = require('./instrumentationArgs'); - instrumentationArgs.prepareInstrumentationArgs.mockReturnValue({args: [], usedReservedArgs: []}); + instrumentationArgs.prepareInstrumentationArgs.mockReturnValue({ args: [], usedReservedArgs: [] }); logger = { warn: jest.fn(), - } + }; }); let childProcess; @@ -63,7 +63,7 @@ describe('Instrumentation', () => { describe('spawning launch-arguments processing', () => { it('should prepare user launch-arguments', async () => { - instrumentationArgs.prepareInstrumentationArgs.mockReturnValue({args: [], usedReservedArgs: []}); + instrumentationArgs.prepareInstrumentationArgs.mockReturnValue({ args: [], usedReservedArgs: [] }); const userArgs = { arg1: 'value1', }; @@ -73,7 +73,7 @@ describe('Instrumentation', () => { }); it('should prepare forced debug=false launch argument', async () => { - instrumentationArgs.prepareInstrumentationArgs.mockReturnValue({args: [], usedReservedArgs: []}); + instrumentationArgs.prepareInstrumentationArgs.mockReturnValue({ args: [], usedReservedArgs: [] }); await uut.launch(deviceId, bundleId, { }); expect(instrumentationArgs.prepareInstrumentationArgs).toHaveBeenCalledWith({ debug: false }); }); @@ -222,11 +222,11 @@ describe('Instrumentation', () => { const invokeDataCallbackWith = async (data) => { const fn = extractDataCallback(); await fn(data); - } + }; const extractTerminationCallback = () => childProcess.on.mock.calls[0][1]; const invokeTerminationCallback = async () => { const terminationFn = extractTerminationCallback(); await terminationFn(); - } + }; }); diff --git a/detox/src/devices/drivers/android/tools/MonitoredInstrumentation.js b/detox/src/devices/drivers/android/tools/MonitoredInstrumentation.js index c88d4b1fec..7e18da289a 100644 --- a/detox/src/devices/drivers/android/tools/MonitoredInstrumentation.js +++ b/detox/src/devices/drivers/android/tools/MonitoredInstrumentation.js @@ -1,8 +1,10 @@ const _ = require('lodash'); + +const DetoxRuntimeError = require('../../../../errors/DetoxRuntimeError'); +const Deferred = require('../../../../utils/Deferred'); + const Instrumentation = require('./Instrumentation'); const { InstrumentationLogsParser } = require('./InstrumentationLogsParser'); -const Deferred = require('../../../../utils/Deferred'); -const DetoxRuntimeError = require('../../../../errors/DetoxRuntimeError'); class MonitoredInstrumentation { constructor(adb, logger) { diff --git a/detox/src/devices/drivers/android/tools/MonitoredInstrumentation.test.js b/detox/src/devices/drivers/android/tools/MonitoredInstrumentation.test.js index ab05c040a5..c866e38cc6 100644 --- a/detox/src/devices/drivers/android/tools/MonitoredInstrumentation.test.js +++ b/detox/src/devices/drivers/android/tools/MonitoredInstrumentation.test.js @@ -24,7 +24,7 @@ describe('Monitored instrumentation', () => { const instances = InstrumentationLogsParserClass.mock.instances; const _this = instances[instances.length - 1]; _this.getStackTrace.mockReturnValue(INSTRUMENTATION_STACKTRACE_MOCK); - }) + }); }); const instrumentationObj = () => InstrumentationClass.mock.instances[0]; @@ -199,12 +199,12 @@ describe('Monitored instrumentation', () => { const invokeUnderlyingTerminationCallback = async () => { const fn = extractUnderlyingTerminationCallback(); await fn(); - } + }; const extractUnderlyingLogListenerCallback = () => InstrumentationClass.mock.calls[0][3]; const invokeUnderlyingLogListenerCallbackWith = async (data) => { const fn = extractUnderlyingLogListenerCallback(); await fn(data); - } + }; const mockUnderlyingInstrumentationRunning = () => instrumentationObj().isRunning.mockReturnValue(true); const mockUnderlyingInstrumentationDead = () => instrumentationObj().isRunning.mockReturnValue(false); diff --git a/detox/src/devices/drivers/android/tools/instrumentationArgs.js b/detox/src/devices/drivers/android/tools/instrumentationArgs.js index 06af4a2969..a8f4cd67a9 100644 --- a/detox/src/devices/drivers/android/tools/instrumentationArgs.js +++ b/detox/src/devices/drivers/android/tools/instrumentationArgs.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const { encodeBase64 } = require('../../../../utils/encoding'); const reservedInstrumentationArgs = ['class', 'package', 'func', 'unit', 'size', 'perf', 'debug', 'log', 'emma', 'coverageFile']; @@ -13,7 +14,7 @@ function prepareInstrumentationArgs(args) { if (isReservedInstrumentationArg(key)) { usedReservedArgs.push(key); } else if (!key.startsWith('detox')) { - valueEncoded = encodeBase64(valueAsString) + valueEncoded = encodeBase64(valueAsString); } result.push('-e', key, valueEncoded); diff --git a/detox/src/devices/drivers/ios/IosDriver.js b/detox/src/devices/drivers/ios/IosDriver.js index 7e56c20e7b..4a275534ca 100644 --- a/detox/src/devices/drivers/ios/IosDriver.js +++ b/detox/src/devices/drivers/ios/IosDriver.js @@ -1,10 +1,10 @@ -const path = require('path'); const fs = require('fs'); -const DeviceDriverBase = require('../DeviceDriverBase'); +const path = require('path'); const TimelineArtifactPlugin = require('../../../artifacts/timeline/TimelineArtifactPlugin'); const IosUIHierarchyPlugin = require('../../../artifacts/uiHierarchy/IosUIHierarchyPlugin'); const DetoxRuntimeError = require('../../../errors/DetoxRuntimeError'); +const DeviceDriverBase = require('../DeviceDriverBase'); class IosDriver extends DeviceDriverBase { declareArtifactPlugins() { @@ -23,15 +23,15 @@ class IosDriver extends DeviceDriverBase { } async setURLBlacklist(blacklistURLs) { - return await this.client.setSyncSettings({blacklistURLs: blacklistURLs}); + return await this.client.setSyncSettings({ blacklistURLs: blacklistURLs }); } async enableSynchronization() { - return await this.client.setSyncSettings({enabled: true}); + return await this.client.setSyncSettings({ enabled: true }); } async disableSynchronization() { - return await this.client.setSyncSettings({enabled: false}); + return await this.client.setSyncSettings({ enabled: false }); } async shake(deviceId) { @@ -39,8 +39,8 @@ class IosDriver extends DeviceDriverBase { } async setOrientation(deviceId, orientation) { - if (!['portrait', 'landscape'].some(option => option === orientation)) throw new DetoxRuntimeError("orientation should be either 'portrait' or 'landscape', but got " + (orientation + ")")); - return await this.client.setOrientation({orientation}); + if (!['portrait', 'landscape'].some(option => option === orientation)) throw new DetoxRuntimeError("orientation should be either 'portrait' or 'landscape', but got " + (orientation + ')')); + return await this.client.setOrientation({ orientation }); } getPlatform() { diff --git a/detox/src/devices/drivers/ios/SimulatorDriver.js b/detox/src/devices/drivers/ios/SimulatorDriver.js index 5b6f79083e..282ef9d4fb 100644 --- a/detox/src/devices/drivers/ios/SimulatorDriver.js +++ b/detox/src/devices/drivers/ios/SimulatorDriver.js @@ -1,21 +1,24 @@ -const _ = require('lodash'); const fs = require('fs'); const path = require('path'); + const exec = require('child-process-promise').exec; -const DeviceRegistry = require('../../DeviceRegistry'); -const IosDriver = require('./IosDriver'); -const AppleSimUtils = require('./tools/AppleSimUtils'); +const _ = require('lodash'); + const SimulatorInstrumentsPlugin = require('../../../artifacts/instruments/ios/SimulatorInstrumentsPlugin'); const SimulatorLogPlugin = require('../../../artifacts/log/ios/SimulatorLogPlugin'); -const SimulatorRecordVideoPlugin = require('../../../artifacts/video/SimulatorRecordVideoPlugin'); const SimulatorScreenshotPlugin = require('../../../artifacts/screenshot/SimulatorScreenshotPlugin'); const temporaryPath = require('../../../artifacts/utils/temporaryPath'); +const SimulatorRecordVideoPlugin = require('../../../artifacts/video/SimulatorRecordVideoPlugin'); const DetoxRuntimeError = require('../../../errors/DetoxRuntimeError'); -const environment = require('../../../utils/environment'); const argparse = require('../../../utils/argparse'); +const environment = require('../../../utils/environment'); const getAbsoluteBinaryPath = require('../../../utils/getAbsoluteBinaryPath'); const log = require('../../../utils/logger').child({ __filename }); const pressAnyKey = require('../../../utils/pressAnyKey'); +const DeviceRegistry = require('../../DeviceRegistry'); + +const IosDriver = require('./IosDriver'); +const AppleSimUtils = require('./tools/AppleSimUtils'); class SimulatorDriver extends IosDriver { @@ -104,15 +107,15 @@ class SimulatorDriver extends IosDriver { } async launchApp(deviceId, bundleId, launchArgs, languageAndLocale) { - await this.emitter.emit('beforeLaunchApp', {bundleId, deviceId, launchArgs}); + await this.emitter.emit('beforeLaunchApp', { bundleId, deviceId, launchArgs }); const pid = await this.applesimutils.launch(deviceId, bundleId, launchArgs, languageAndLocale); - await this.emitter.emit('launchApp', {bundleId, deviceId, launchArgs, pid}); + await this.emitter.emit('launchApp', { bundleId, deviceId, launchArgs, pid }); return pid; } async waitForAppLaunch(deviceId, bundleId, launchArgs, languageAndLocale) { - await this.emitter.emit('beforeLaunchApp', {bundleId, deviceId, launchArgs}); + await this.emitter.emit('beforeLaunchApp', { bundleId, deviceId, launchArgs }); this.applesimutils.printLaunchHint(deviceId, bundleId, launchArgs, languageAndLocale); await pressAnyKey(); @@ -128,7 +131,7 @@ class SimulatorDriver extends IosDriver { log.info({}, `Found the app (${bundleId}) with process ID = ${pid}. Proceeding...`); } - await this.emitter.emit('launchApp', {bundleId, deviceId, launchArgs, pid}); + await this.emitter.emit('launchApp', { bundleId, deviceId, launchArgs, pid }); return pid; } @@ -177,7 +180,7 @@ class SimulatorDriver extends IosDriver { } async clearKeychain(deviceId) { - await this.applesimutils.clearKeychain(deviceId) + await this.applesimutils.clearKeychain(deviceId); } async resetContentAndSettings(deviceId) { @@ -257,7 +260,7 @@ class SimulatorDriver extends IosDriver { return { taken: _.filter(taken, isMatching), free: _.filter(free, isMatching), - } + }; } async _queryDevices(deviceQuery) { diff --git a/detox/src/devices/drivers/ios/SimulatorDriver.test.js b/detox/src/devices/drivers/ios/SimulatorDriver.test.js index 04d9c7407a..7b5df6c1df 100644 --- a/detox/src/devices/drivers/ios/SimulatorDriver.test.js +++ b/detox/src/devices/drivers/ios/SimulatorDriver.test.js @@ -12,7 +12,7 @@ describe('IOS simulator driver', () => { emitter = new AsyncEmitter({ events: ['beforeLaunchApp'], - onError: (e) => { throw e }, + onError: (e) => { throw e; }, }); MockClient = jest.requireMock('../../../client/Client'); @@ -116,7 +116,7 @@ describe('IOS simulator driver', () => { it('fails to match a face by passing to AppleSimUtils', async () => { await sim.unmatchFinger(deviceId); expect(sim.applesimutils.unmatchBiometric).toHaveBeenCalledWith(deviceId, 'Finger'); - }) + }); }); describe('acquireFreeDevice', () => { @@ -125,9 +125,9 @@ describe('IOS simulator driver', () => { rawDevices: UDIDs.map((UDID) => ({ id: UDID })), // as typically returned by getRegisteredDevices() includes: UDIDs.includes.bind(UDIDs), }); - } + }; const givenNoUsedSimulators = () => givenUsedSimulators(); - const givenSystemDevices = (...deviceSpecs) => uut.applesimutils.list.mockResolvedValue([ ...deviceSpecs ]); + const givenSystemDevices = (...deviceSpecs) => uut.applesimutils.list.mockResolvedValue([...deviceSpecs]); const givenCreatedDeviceUDID = (udid) => uut.applesimutils.create.mockReturnValue(udid); const aDeviceSpec = (udid) => ({ udid, diff --git a/detox/src/devices/drivers/ios/tools/AppleSimUtils.js b/detox/src/devices/drivers/ios/tools/AppleSimUtils.js index a9649e3a26..703831e80d 100644 --- a/detox/src/devices/drivers/ios/tools/AppleSimUtils.js +++ b/detox/src/devices/drivers/ios/tools/AppleSimUtils.js @@ -1,10 +1,12 @@ -const _ = require('lodash'); const path = require('path'); + +const _ = require('lodash'); + const DetoxRuntimeError = require('../../../../errors/DetoxRuntimeError'); -const {joinArgs} = require('../../../../utils/argparse'); +const { joinArgs } = require('../../../../utils/argparse'); +const environment = require('../../../../utils/environment'); const exec = require('../../../../utils/exec'); const log = require('../../../../utils/logger').child({ __filename }); -const environment = require('../../../../utils/environment'); const { quote } = require('../../../../utils/shellQuote'); class AppleSimUtils { @@ -21,7 +23,7 @@ class AppleSimUtils { successful: 'Permissions are set' }, retries: 1, - } + }; await this._execAppleSimUtils(options); } @@ -160,7 +162,7 @@ class AppleSimUtils { trying: `Trying to unmatch ${matchType}...`, successful: `Unmatched ${matchType}!` }, - } + }; await this._execAppleSimUtils(options); } @@ -177,7 +179,7 @@ class AppleSimUtils { trying: `Turning ${toggle ? 'on' : 'off'} biometric enrollment...`, successful: toggle ? 'Activated!' : 'Deactivated!' }, - } + }; await this._execAppleSimUtils(options); } @@ -189,7 +191,7 @@ class AppleSimUtils { trying: `Clearing Keychain...`, successful: 'Cleared Keychain!' }, - } + }; await this._execAppleSimUtils(options); } @@ -284,7 +286,7 @@ class AppleSimUtils { verbosity: silent ? 'low' : 'normal', statusLogs, retries, - } + }; return await exec.execWithRetriesAndLogs(`/usr/bin/xcrun simctl ${cmd}`, options); } @@ -363,21 +365,21 @@ class AppleSimUtils { if (udid && flags) { let overrides = []; if (flags.time) - overrides.push(`--time "${flags.time}"`) + overrides.push(`--time "${flags.time}"`); if (flags.dataNetwork) - overrides.push(`--dataNetwork "${flags.dataNetwork}"`) + overrides.push(`--dataNetwork "${flags.dataNetwork}"`); if (flags.wifiMode) - overrides.push(`--wifiMode "${flags.wifiMode}"`) + overrides.push(`--wifiMode "${flags.wifiMode}"`); if (flags.wifiBars) - overrides.push(`--wifiBars "${flags.wifiBars}"`) + overrides.push(`--wifiBars "${flags.wifiBars}"`); if (flags.cellularMode) - overrides.push(`--cellularMode "${flags.cellularMode}"`) + overrides.push(`--cellularMode "${flags.cellularMode}"`); if (flags.cellularBars) - overrides.push(`--cellularBars "${flags.cellularBars}"`) + overrides.push(`--cellularBars "${flags.cellularBars}"`); if (flags.batteryState) - overrides.push(`--batteryState "${flags.batteryState}"`) + overrides.push(`--batteryState "${flags.batteryState}"`); if (flags.batteryLevel) - overrides.push(`--batteryLevel "${flags.batteryLevel}"`) + overrides.push(`--batteryLevel "${flags.batteryLevel}"`); await this._execSimctl({ cmd: `status_bar ${udid} override ${overrides.join(' ')}` }); } diff --git a/detox/src/errors/DetoxConfigErrorComposer.js b/detox/src/errors/DetoxConfigErrorComposer.js index 93600b4149..ea663bb676 100644 --- a/detox/src/errors/DetoxConfigErrorComposer.js +++ b/detox/src/errors/DetoxConfigErrorComposer.js @@ -1,6 +1,8 @@ const _ = require('lodash'); -const DetoxConfigError = require('./DetoxConfigError'); + const deviceAppTypes = require('../configuration/utils/deviceAppTypes'); + +const DetoxConfigError = require('./DetoxConfigError'); const J = s => JSON.stringify(s); class DetoxConfigErrorComposer { @@ -549,7 +551,7 @@ Check contents of your Detox config${this._atPath()}`, } function hintConfigurations(configurations) { - return _.keys(configurations).map(c => `* ${c}`).join('\n') + return _.keys(configurations).map(c => `* ${c}`).join('\n'); } module.exports = DetoxConfigErrorComposer; diff --git a/detox/src/errors/DetoxConfigErrorComposer.test.js b/detox/src/errors/DetoxConfigErrorComposer.test.js index 091eb7861c..38e82eb621 100644 --- a/detox/src/errors/DetoxConfigErrorComposer.test.js +++ b/detox/src/errors/DetoxConfigErrorComposer.test.js @@ -1,6 +1,8 @@ -const _ = require('lodash'); const fs = require('fs'); const os = require('os'); + +const _ = require('lodash'); + const DetoxConfigErrorComposer = require('./DetoxConfigErrorComposer'); describe('DetoxConfigErrorComposer', () => { @@ -84,7 +86,7 @@ describe('DetoxConfigErrorComposer', () => { builder .setExtends(true) .setDetoxConfigPath('package.json') - .noConfigurationAtGivenPath("some-detox-preset") + .noConfigurationAtGivenPath('some-detox-preset') ).toMatchSnapshot(); }); }); @@ -138,7 +140,7 @@ describe('DetoxConfigErrorComposer', () => { describe('.noConfigurationWithGivenName', () => { beforeEach(() => { build = () => builder.noConfigurationWithGivenName(); - builder.setConfigurationName('otherConf') + builder.setConfigurationName('otherConf'); }); it('should create an error with configuration suggestions', () => { @@ -149,7 +151,7 @@ describe('DetoxConfigErrorComposer', () => { describe('.configurationShouldNotBeEmpty', () => { beforeEach(() => { build = () => builder.configurationShouldNotBeEmpty(); - builder.setConfigurationName('empty') + builder.setConfigurationName('empty'); config.configurations.empty = {}; }); @@ -164,7 +166,7 @@ describe('DetoxConfigErrorComposer', () => { beforeEach(() => { build = () => builder.thereAreNoDeviceConfigs('aDevice'); config.devices = {}; - builder.setConfigurationName('aliased') + builder.setConfigurationName('aliased'); }); it('should create an error with a hint', () => { @@ -282,7 +284,7 @@ describe('DetoxConfigErrorComposer', () => { describe('.thereAreNoAppConfigs', () => { it('should create an error for aliased configuration', () => { delete config.apps.someApp; - builder.setConfigurationName('aliased') + builder.setConfigurationName('aliased'); expect(builder.thereAreNoAppConfigs('someApp')).toMatchSnapshot(); }); @@ -290,7 +292,7 @@ describe('DetoxConfigErrorComposer', () => { describe('.cantResolveAppAlias', () => { it('should create an error for aliased configuration', () => { - builder.setConfigurationName('aliased') + builder.setConfigurationName('aliased'); expect(builder.cantResolveAppAlias('anotherApp')).toMatchSnapshot(); }); }); @@ -607,7 +609,7 @@ describe('DetoxConfigErrorComposer', () => { server: 'ws://localhost:12837', }, configurations: {}, - }) + }); builder.setDetoxConfigPath('/home/detox/myproject/.detoxrc.json'); expect(build()).toMatchSnapshot(); @@ -648,7 +650,7 @@ describe('DetoxConfigErrorComposer', () => { server: 'ws://localhost:12837', }, configurations: {}, - }) + }); builder.setDetoxConfigPath('/home/detox/myproject/.detoxrc.json'); expect(build()).toMatchSnapshot(); diff --git a/detox/src/errors/DetoxError.js b/detox/src/errors/DetoxError.js index fb32dd8c0f..f4182defd3 100644 --- a/detox/src/errors/DetoxError.js +++ b/detox/src/errors/DetoxError.js @@ -1,6 +1,7 @@ -const _ = require('lodash'); const util = require('util'); +const _ = require('lodash'); + class DetoxError extends Error { constructor(message) { super(message); @@ -38,7 +39,7 @@ class DetoxError extends Error { return String(err.stack || err); } - return this.inspectObj(err, inspectOptions) + return this.inspectObj(err, inspectOptions); } } diff --git a/detox/src/errors/DetoxInternalError.test.js b/detox/src/errors/DetoxInternalError.test.js index 7889c52c70..91e7c47ac7 100644 --- a/detox/src/errors/DetoxInternalError.test.js +++ b/detox/src/errors/DetoxInternalError.test.js @@ -2,7 +2,7 @@ const DetoxInternalError = require('./DetoxInternalError'); describe('DetoxInternalError', () => { it('should append a Report-Issue hint', () => { - expect(() => { throw new DetoxInternalError('Should do better') }) + expect(() => { throw new DetoxInternalError('Should do better'); }) .toThrowErrorMatchingSnapshot(); }); diff --git a/detox/src/errors/DetoxRuntimeError.js b/detox/src/errors/DetoxRuntimeError.js index 8ca2ba102f..fe1501d2f2 100644 --- a/detox/src/errors/DetoxRuntimeError.js +++ b/detox/src/errors/DetoxRuntimeError.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const DetoxError = require('./DetoxError'); class DetoxRuntimeError extends DetoxError { diff --git a/detox/src/errors/DetoxRuntimeError.test.js b/detox/src/errors/DetoxRuntimeError.test.js index c23f599e33..192c9e2207 100644 --- a/detox/src/errors/DetoxRuntimeError.test.js +++ b/detox/src/errors/DetoxRuntimeError.test.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const DetoxRuntimeError = require('./DetoxRuntimeError'); describe('DetoxRuntimeError', () => { @@ -13,7 +14,7 @@ describe('DetoxRuntimeError', () => { }); it('should format any object to an error message', () => { - expect(DetoxRuntimeError.format({})).toBe("{}"); + expect(DetoxRuntimeError.format({})).toBe('{}'); const err = new Error('Command failed: echo Hello world'); expect(DetoxRuntimeError.format(err)).toBe(err.message); diff --git a/detox/src/errors/DetoxRuntimeErrorComposer.js b/detox/src/errors/DetoxRuntimeErrorComposer.js index 29d67d5c43..e9cba18464 100644 --- a/detox/src/errors/DetoxRuntimeErrorComposer.js +++ b/detox/src/errors/DetoxRuntimeErrorComposer.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const DetoxRuntimeError = require('./DetoxRuntimeError'); const J = s => JSON.stringify(s); @@ -69,7 +70,7 @@ class DetoxRuntimeErrorComposer { } function toStarlist(dictionary) { - return _.keys(dictionary).map(c => `* ${c}`).join('\n') + return _.keys(dictionary).map(c => `* ${c}`).join('\n'); } module.exports = DetoxRuntimeErrorComposer; diff --git a/detox/src/errors/longreads/failedToReachTheApp.test.js b/detox/src/errors/longreads/failedToReachTheApp.test.js index 8ef65157e6..a7040450a8 100644 --- a/detox/src/errors/longreads/failedToReachTheApp.test.js +++ b/detox/src/errors/longreads/failedToReachTheApp.test.js @@ -11,4 +11,4 @@ describe('failedToReachTheApp', () => { messageId: -1000 })).toMatchSnapshot(); }); -}) +}); diff --git a/detox/src/invoke.js b/detox/src/invoke.js index cee4d12632..5d0b9eab51 100644 --- a/detox/src/invoke.js +++ b/detox/src/invoke.js @@ -1,7 +1,7 @@ -const Invoke = require('./invoke/Invoke'); const EarlGrey = require('./invoke/EarlGrey'); const Espresso = require('./invoke/Espresso'); const EspressoWeb = require('./invoke/EspressoWeb'); +const Invoke = require('./invoke/Invoke'); class InvocationManager { constructor(excutionHandler) { diff --git a/detox/src/invoke.test.js b/detox/src/invoke.test.js index 3b62e90746..db4cb26805 100644 --- a/detox/src/invoke.test.js +++ b/detox/src/invoke.test.js @@ -10,23 +10,23 @@ describe('invoke', () => { }); it(`execute() should trigger executionHandler.execute()`, () => { - const invocationManager = new invoke.InvocationManager(new Client("")); + const invocationManager = new invoke.InvocationManager(new Client('')); invocationManager.execute(); expect(invocationManager.executionHandler.execute).toHaveBeenCalled(); }); it(`execute should return execution result`, async () => { - const client = new Client(""); + const client = new Client(''); const someResult = 'some_result'; client.execute.mockReturnValue(someResult); const invocationManager = new invoke.InvocationManager(client); const result = await invocationManager.execute(); - expect(result).toEqual(someResult) + expect(result).toEqual(someResult); }); it(`invoke.IOS.{anything} will create an instance of {generic} invoke object`, () => { - expect(invoke.IOS.CGPoint({x: 2, y: 1})).toEqual({type: 'CGPoint', value: {x: 2, y: 1}}); - expect(invoke.IOS.CGRect({x: 12, y: 11})).toEqual({type: 'CGRect', value: {x: 12, y: 11}}); - expect(invoke.IOS.Anything(1)).toEqual({type: 'Anything', value: 1}); + expect(invoke.IOS.CGPoint({ x: 2, y: 1 })).toEqual({ type: 'CGPoint', value: { x: 2, y: 1 } }); + expect(invoke.IOS.CGRect({ x: 12, y: 11 })).toEqual({ type: 'CGRect', value: { x: 12, y: 11 } }); + expect(invoke.IOS.Anything(1)).toEqual({ type: 'Anything', value: 1 }); }); }); diff --git a/detox/src/invoke/Invoke.test.js b/detox/src/invoke/Invoke.test.js index d4cf7bee8d..9285a90427 100644 --- a/detox/src/invoke/Invoke.test.js +++ b/detox/src/invoke/Invoke.test.js @@ -1,4 +1,4 @@ -const {call} = require('./Invoke'); +const { call } = require('./Invoke'); describe('call', () => { it('handles target as thunk', () => { diff --git a/detox/src/ios/expectTwo.js b/detox/src/ios/expectTwo.js index d2a7871139..45342d1105 100644 --- a/detox/src/ios/expectTwo.js +++ b/detox/src/ios/expectTwo.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); const { assertEnum, assertNormalized, assertNumber } = require('../utils/assertArgument'); const assertDirection = assertEnum(['left', 'right', 'up', 'down']); @@ -85,7 +86,7 @@ class Expect { type: 'expectation', predicate: this.element.matcher.predicate, ...(this.element.index !== undefined && { atIndex: this.element.index }), - ...(this.modifiers.length !== 0 && {modifiers: this.modifiers}), + ...(this.modifiers.length !== 0 && { modifiers: this.modifiers }), expectation, ...(params.length !== 0 && { params: _.without(params, undefined) }) }; @@ -239,7 +240,7 @@ class Element { } takeScreenshot() { - throw new DetoxRuntimeError({message: 'Element screenshots are not supported on iOS, at the moment!'}); + throw new DetoxRuntimeError({ message: 'Element screenshots are not supported on iOS, at the moment!' }); } createInvocation(action, targetElementMatcher, ...params) { @@ -255,7 +256,7 @@ class Element { if (targetElementMatcher && targetElementMatcher.matcher && targetElementMatcher.matcher.predicate) { invocation.targetElement = { predicate: targetElementMatcher.matcher.predicate - } + }; } return invocation; @@ -339,7 +340,7 @@ class Matcher { } traits(traits) { - if (typeof traits !== 'object' || !traits instanceof Array) throw new Error('traits must be an array, got ' + typeof traits); + if (!Array.isArray(traits)) throw new Error('traits must be an array, got ' + typeof traits); this.predicate = { type: 'traits', value: traits }; return this; } diff --git a/detox/src/ios/expectTwo.test.js b/detox/src/ios/expectTwo.test.js index 6413ce70f3..baa9b09299 100644 --- a/detox/src/ios/expectTwo.test.js +++ b/detox/src/ios/expectTwo.test.js @@ -486,9 +486,8 @@ expect.extend({ } }); - class MockExecutor { execute(invocation) { return { invocation }; - }; + } } diff --git a/detox/src/ios/expectTwoApiCoverage.test.js b/detox/src/ios/expectTwoApiCoverage.test.js index b24ecad033..4d1381f156 100644 --- a/detox/src/ios/expectTwoApiCoverage.test.js +++ b/detox/src/ios/expectTwoApiCoverage.test.js @@ -8,7 +8,6 @@ describe('expectTwo API Coverage', () => { }); }); - describe('Matchers', () => { it(`by.accessibilityLabel`, async () => { await e.expect(e.element(e.by.accessibilityLabel('test'))).toBeVisible(); @@ -64,7 +63,6 @@ describe('expectTwo API Coverage', () => { await e.expect(e.element(e.by.id('test').and(e.by.type('type')))).toBeVisible(); }); - it(`matchers with wrong parameters should throw`, async () => { await expectToThrow(() => e.element(e.by.label(5))); await expectToThrow(() => e.element(e.by.id(5))); @@ -90,7 +88,6 @@ describe('expectTwo API Coverage', () => { }); }); - describe('Actions', () => { it(`setColumnToValue()`, async () => { @@ -192,7 +189,7 @@ describe('expectTwo API Coverage', () => { await expectToThrow(() => e.element(e.by.id('elementToDrag')).longPressAndDrag(1000, 0.5, 0.5, e.by.id('matcherNotElement'))); await expectToThrow(() => e.element(e.by.id('elementToDrag')).longPressAndDrag('notANumber', 0.5, 0.5, e.element(e.by.id('targetElement')))); - await expectToThrow(() => e.element(e.by.id('elementToDrag')).longPressAndDrag(1000, 0.5, 0.5, e.element(e.by.id('targetElement')), 0.5, 0.5, "slow", 'notANumber')); + await expectToThrow(() => e.element(e.by.id('elementToDrag')).longPressAndDrag(1000, 0.5, 0.5, e.element(e.by.id('targetElement')), 0.5, 0.5, 'slow', 'notANumber')); }); }); diff --git a/detox/src/matchersRegistry.test.js b/detox/src/matchersRegistry.test.js index 41c59cdacd..3059353439 100644 --- a/detox/src/matchersRegistry.test.js +++ b/detox/src/matchersRegistry.test.js @@ -36,7 +36,7 @@ describe('Detox matchers registry', () => { const withUnknownDevice = (deviceType) => { device.getPlatform.mockReturnValue(undefined); device.type = deviceType; - } + }; it('should resolve the Android matchers', () => { withAndroidDevice(); diff --git a/detox/src/server/DetoxConnection.js b/detox/src/server/DetoxConnection.js index 9323e01e55..902f925920 100644 --- a/detox/src/server/DetoxConnection.js +++ b/detox/src/server/DetoxConnection.js @@ -1,9 +1,11 @@ const _ = require('lodash'); const { WebSocket } = require('ws'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); -const AnonymousConnectionHandler = require('./handlers/AnonymousConnectionHandler'); const logger = require('../utils/logger').child({ __filename }); +const AnonymousConnectionHandler = require('./handlers/AnonymousConnectionHandler'); + const EVENTS = { NEW: { event: 'WSS_CONNECTION' }, GET: { event: 'WSS_GET_FROM' }, diff --git a/detox/src/server/DetoxServer.js b/detox/src/server/DetoxServer.js index 0f7d3da963..104e971079 100644 --- a/detox/src/server/DetoxServer.js +++ b/detox/src/server/DetoxServer.js @@ -1,9 +1,11 @@ const _ = require('lodash'); const WebSocket = require('ws'); -const DetoxSessionManager = require('./DetoxSessionManager'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); -const log = require('../utils/logger').child({ __filename }); const Deferred = require('../utils/Deferred'); +const log = require('../utils/logger').child({ __filename }); + +const DetoxSessionManager = require('./DetoxSessionManager'); class DetoxServer { /** diff --git a/detox/src/server/DetoxServer.test.js b/detox/src/server/DetoxServer.test.js index 4bfa76ad21..91b6d078ca 100644 --- a/detox/src/server/DetoxServer.test.js +++ b/detox/src/server/DetoxServer.test.js @@ -20,7 +20,7 @@ describe('DetoxServer', () => { if (server) { await server.close(); } - }) + }); describe('.open() / .close()', () => { beforeEach(async () => { diff --git a/detox/src/server/DetoxSessionManager.js b/detox/src/server/DetoxSessionManager.js index c6ed209b2d..bf09fa1b6d 100644 --- a/detox/src/server/DetoxSessionManager.js +++ b/detox/src/server/DetoxSessionManager.js @@ -1,5 +1,6 @@ -const log = require('../utils/logger').child({ __filename }); const DetoxInternalError = require('../errors/DetoxInternalError'); +const log = require('../utils/logger').child({ __filename }); + const DetoxConnection = require('./DetoxConnection'); const DetoxSession = require('./DetoxSession'); diff --git a/detox/src/server/__mocks__/FakeWebSocket.js b/detox/src/server/__mocks__/FakeWebSocket.js index 3dc995a5ec..5a5b22a712 100644 --- a/detox/src/server/__mocks__/FakeWebSocket.js +++ b/detox/src/server/__mocks__/FakeWebSocket.js @@ -33,7 +33,7 @@ class FakeWebSocket { role, sessionId, }, - }) + }); } mockClose() { diff --git a/detox/src/server/__tests__/server-integration.test.js b/detox/src/server/__tests__/server-integration.test.js index d491f99331..33b5b850d1 100644 --- a/detox/src/server/__tests__/server-integration.test.js +++ b/detox/src/server/__tests__/server-integration.test.js @@ -134,12 +134,12 @@ describe('Detox server integration', () => { expect(testerSocket.send).toHaveBeenCalledWith(aMessage({ type: 'appConnected' })); // tester sends to app - const reloadAction = { type: 'reactNativeReload', messageId: 1000 } + const reloadAction = { type: 'reactNativeReload', messageId: 1000 }; testerSocket.mockMessage(reloadAction); expect(appSocket.send).toHaveBeenCalledWith(aMessage(reloadAction)); // app sends back to tester - const readyAction = { type: 'ready', messageId: 1000 } + const readyAction = { type: 'ready', messageId: 1000 }; appSocket.mockMessage(readyAction); expect(testerSocket.send).toHaveBeenCalledWith(aMessage(readyAction)); @@ -268,7 +268,7 @@ describe('Detox server integration', () => { webSocket.mockLogin({ role: 'app' }); const [[detoxConnection]] = sessionManager.registerSession.mock.calls; const priorDetoxSession = sessionManager.getSession(detoxConnection); - const newDetoxSession = sessionManager.registerSession(detoxConnection, { role: 'app', sessionId: '10101'}); + const newDetoxSession = sessionManager.registerSession(detoxConnection, { role: 'app', sessionId: '10101' }); expect(priorDetoxSession === newDetoxSession).toBe(true); // assert no new sessions were created expect(getLoggerMsg('error', 0)).toMatchSnapshot(); diff --git a/detox/src/server/handlers/AnonymousConnectionHandler.js b/detox/src/server/handlers/AnonymousConnectionHandler.js index 16c5644efd..1fa3f21814 100644 --- a/detox/src/server/handlers/AnonymousConnectionHandler.js +++ b/detox/src/server/handlers/AnonymousConnectionHandler.js @@ -1,5 +1,6 @@ -const DetoxRuntimeError = require('../../errors/DetoxRuntimeError'); const DetoxInternalError = require('../../errors/DetoxInternalError'); +const DetoxRuntimeError = require('../../errors/DetoxRuntimeError'); + const AppConnectionHandler = require('./AppConnectionHandler'); const TesterConnectionHandler = require('./TesterConnectionHandler'); diff --git a/detox/src/server/handlers/AppConnectionHandler.js b/detox/src/server/handlers/AppConnectionHandler.js index f8cd8ec500..3f831979bf 100644 --- a/detox/src/server/handlers/AppConnectionHandler.js +++ b/detox/src/server/handlers/AppConnectionHandler.js @@ -1,4 +1,5 @@ const DetoxRuntimeError = require('../../errors/DetoxRuntimeError'); + const RegisteredConnectionHandler = require('./RegisteredConnectionHandler'); class AppConnectionHandler extends RegisteredConnectionHandler { diff --git a/detox/src/server/handlers/RegisteredConnectionHandler.js b/detox/src/server/handlers/RegisteredConnectionHandler.js index 773e5a0aa2..7d88c10784 100644 --- a/detox/src/server/handlers/RegisteredConnectionHandler.js +++ b/detox/src/server/handlers/RegisteredConnectionHandler.js @@ -1,7 +1,8 @@ -const DetoxInternalError = require('../../errors/DetoxInternalError'); -const DetoxError = require('../../errors/DetoxError'); const { serializeError } = require('serialize-error'); +const DetoxError = require('../../errors/DetoxError'); +const DetoxInternalError = require('../../errors/DetoxInternalError'); + class RegisteredConnectionHandler { constructor({ api, role, session }) { this._api = api; @@ -39,7 +40,7 @@ class RegisteredConnectionHandler { messageId: action && action.messageId, }); } catch (err) { - this._api.log.error('Cannot forward the error details to the tester due to the error:\n' + DetoxError.format(err)) + this._api.log.error('Cannot forward the error details to the tester due to the error:\n' + DetoxError.format(err)); throw error; } } diff --git a/detox/src/server/handlers/TesterConnectionHandler.js b/detox/src/server/handlers/TesterConnectionHandler.js index eaf42d7ff5..a88c39f1b2 100644 --- a/detox/src/server/handlers/TesterConnectionHandler.js +++ b/detox/src/server/handlers/TesterConnectionHandler.js @@ -1,6 +1,7 @@ -const RegisteredConnectionHandler = require('./RegisteredConnectionHandler'); const failedToReachTheApp = require('../../errors/longreads/failedToReachTheApp'); +const RegisteredConnectionHandler = require('./RegisteredConnectionHandler'); + class TesterConnectionHandler extends RegisteredConnectionHandler { constructor({ api, session }) { super({ api, session, role: 'tester' }); diff --git a/detox/src/utils/AsyncEmitter.js b/detox/src/utils/AsyncEmitter.js index 26be1a8b10..a8626ca60a 100644 --- a/detox/src/utils/AsyncEmitter.js +++ b/detox/src/utils/AsyncEmitter.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); class AsyncEmitter { diff --git a/detox/src/utils/ChromeTracingExporter.js b/detox/src/utils/ChromeTracingExporter.js index d771e7ed57..5c48434031 100644 --- a/detox/src/utils/ChromeTracingExporter.js +++ b/detox/src/utils/ChromeTracingExporter.js @@ -1,4 +1,5 @@ const _ = require('lodash'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); class ChromeTracingExporter { @@ -44,8 +45,8 @@ class ChromeTracingExporter { tid: this._thread.id, ts, ph: phase, - args: {...args}, - } + args: { ...args }, + }; } } diff --git a/detox/src/utils/ChromeTracingExporter.test.js b/detox/src/utils/ChromeTracingExporter.test.js index 121311990c..c698679a64 100644 --- a/detox/src/utils/ChromeTracingExporter.test.js +++ b/detox/src/utils/ChromeTracingExporter.test.js @@ -39,7 +39,7 @@ describe('Chrome-Tracing exporter', () => { ph: 'B', args: startEvent.args, }; - const result = uut.export([ startEvent ]); + const result = uut.export([startEvent]); expect(result).toEqual(`[${JSON.stringify(expectedObject)}`); }); @@ -54,7 +54,7 @@ describe('Chrome-Tracing exporter', () => { ph: 'E', args: endEvent.args, }; - const result = uut.export([ endEvent ]); + const result = uut.export([endEvent]); expect(result).toEqual(`[${JSON.stringify(expectedObject)}`); }); @@ -79,7 +79,7 @@ describe('Chrome-Tracing exporter', () => { ph: 'M', args: { name: threadName } }]; - const result = uut.export([ initEvent ]); + const result = uut.export([initEvent]); expect(result).toEqual(`[${JSON.stringify(expectedObjects).slice(1, -1)}`); }); @@ -89,13 +89,13 @@ describe('Chrome-Tracing exporter', () => { ts: 666, }; - expect(() => uut.export([ bizarreEvent ])).toThrowError(/Invalid type 'bizarre'/); + expect(() => uut.export([bizarreEvent])).toThrowError(/Invalid type 'bizarre'/); }); it('should export multiple events', () => { const startEvent = anEvent({ type: 'start' }); const endEvent = anEvent({ type: 'end' }); - const result = uut.export([ startEvent, endEvent ]); + const result = uut.export([startEvent, endEvent]); expect(result).toContain(`"ph":"B"`); expect(result).toContain(`"ph":"E"`); }); diff --git a/detox/src/utils/ExclusiveLockfile.js b/detox/src/utils/ExclusiveLockfile.js index c1e209be0e..e4e48b6c19 100644 --- a/detox/src/utils/ExclusiveLockfile.js +++ b/detox/src/utils/ExclusiveLockfile.js @@ -1,11 +1,13 @@ -const _ = require('lodash'); const fs = require('fs-extra'); +const _ = require('lodash'); const plockfile = require('proper-lockfile'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); + const retry = require('./retry'); const DEFAULT_OPTIONS = { - retry: {retries: 10000, interval: 5}, + retry: { retries: 10000, interval: 5 }, read: { encoding: 'utf8' }, getInitialState: _.constant(null), }; diff --git a/detox/src/utils/ExclusiveLockfile.test.js b/detox/src/utils/ExclusiveLockfile.test.js index 569c9c6eb4..3c6e6a8d84 100644 --- a/detox/src/utils/ExclusiveLockfile.test.js +++ b/detox/src/utils/ExclusiveLockfile.test.js @@ -1,8 +1,9 @@ jest.mock('proper-lockfile'); -const plock = require('proper-lockfile'); const fs = require('fs-extra'); +const plock = require('proper-lockfile'); const tempfile = require('tempfile'); + const ExclusiveLockFile = require('./ExclusiveLockfile'); describe('ExclusiveLockFile', () => { @@ -30,7 +31,7 @@ describe('ExclusiveLockFile', () => { expect(lockfile.read()).toBe(84); expect(plock.unlockSync).not.toHaveBeenCalled(); - return "result"; + return 'result'; }); expect(plock.unlockSync).toHaveBeenCalled(); diff --git a/detox/src/utils/Timer.js b/detox/src/utils/Timer.js index d6ad65b8b6..ed6f8e0db3 100644 --- a/detox/src/utils/Timer.js +++ b/detox/src/utils/Timer.js @@ -1,4 +1,5 @@ const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); + const Deferred = require('./Deferred'); class Timer { diff --git a/detox/src/utils/__mocks__/trace.js b/detox/src/utils/__mocks__/trace.js index 014d5fd390..e69fae1cbe 100644 --- a/detox/src/utils/__mocks__/trace.js +++ b/detox/src/utils/__mocks__/trace.js @@ -11,4 +11,4 @@ const traceCall = jest.fn().mockImplementation((_, fn) => fn()); module.exports = { trace: new FakeTrace(), traceCall, -} +}; diff --git a/detox/src/utils/appdatapath.js b/detox/src/utils/appdatapath.js index 4528e0ec3c..afa26e7495 100644 --- a/detox/src/utils/appdatapath.js +++ b/detox/src/utils/appdatapath.js @@ -1,5 +1,6 @@ const os = require('os'); const path = require('path'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); function darwin() { diff --git a/detox/src/utils/appendFile.js b/detox/src/utils/appendFile.js index 1519f4e683..19b507d791 100644 --- a/detox/src/utils/appendFile.js +++ b/detox/src/utils/appendFile.js @@ -1,7 +1,7 @@ const fs = require('fs'); async function appendFile(src, dest) { - const writeStream = fs.createWriteStream(dest, {flags: 'a'}); + const writeStream = fs.createWriteStream(dest, { flags: 'a' }); const readStream = fs.createReadStream(src); const promise = new Promise((resolve, reject) => { diff --git a/detox/src/utils/appendFile.test.js b/detox/src/utils/appendFile.test.js index 0b36b5e518..735a50bd87 100644 --- a/detox/src/utils/appendFile.test.js +++ b/detox/src/utils/appendFile.test.js @@ -1,5 +1,6 @@ const fs = require('fs-extra'); const tempfile = require('tempfile'); + const appendFile = require('./appendFile'); describe('appendFile', () => { diff --git a/detox/src/utils/argparse.js b/detox/src/utils/argparse.js index af15cd6f0b..dc0a55efe9 100644 --- a/detox/src/utils/argparse.js +++ b/detox/src/utils/argparse.js @@ -1,6 +1,7 @@ const _ = require('lodash'); const argv = require('minimist')(process.argv.slice(2)); -const {escape} = require('./pipeCommands'); + +const { escape } = require('./pipeCommands'); function getArgValue(key, alias) { let value = _getArgvValue(key, alias); @@ -50,7 +51,7 @@ const DEFAULT_JOIN_ARGUMENTS_OPTIONS = { }; function joinArgs(keyValues, options = DEFAULT_JOIN_ARGUMENTS_OPTIONS) { - const {prefix, joiner} = options === DEFAULT_JOIN_ARGUMENTS_OPTIONS + const { prefix, joiner } = options === DEFAULT_JOIN_ARGUMENTS_OPTIONS ? options : { ...DEFAULT_JOIN_ARGUMENTS_OPTIONS, ...options }; @@ -73,7 +74,7 @@ function joinArgs(keyValues, options = DEFAULT_JOIN_ARGUMENTS_OPTIONS) { } } - argArray.push(arg) + argArray.push(arg); } return argArray.join(' '); diff --git a/detox/src/utils/argparse.test.js b/detox/src/utils/argparse.test.js index bac587927e..9226640273 100644 --- a/detox/src/utils/argparse.test.js +++ b/detox/src/utils/argparse.test.js @@ -51,7 +51,7 @@ describe('argparse', () => { let argparse; beforeEach(() => { - minimist.mockReturnValue({'kebab-case-key': 'a value', 'b': 'shortened'}); + minimist.mockReturnValue({ 'kebab-case-key': 'a value', 'b': 'shortened' }); argparse = require('./argparse'); }); @@ -73,7 +73,7 @@ describe('argparse', () => { let argparse; beforeEach(() => { - minimist.mockReturnValue({'flag-true': 1, 'flag-false': 0}); + minimist.mockReturnValue({ 'flag-true': 1, 'flag-false': 0 }); argparse = require('./argparse'); }); @@ -117,5 +117,5 @@ describe('argparse', () => { expect(argparse.joinArgs(argsObject, options)).toBe('-version=100 --help'); }); - }) + }); }); diff --git a/detox/src/utils/callsites.js b/detox/src/utils/callsites.js index 45b144755b..22c5638ad5 100644 --- a/detox/src/utils/callsites.js +++ b/detox/src/utils/callsites.js @@ -1,5 +1,6 @@ const path = require('path'); -const {escapeRegExp} = require('lodash'); + +const { escapeRegExp } = require('lodash'); const cwd = process.cwd() + path.sep; // Taken from https://github.com/sindresorhus/callsites diff --git a/detox/src/utils/constructSafeFilename.js b/detox/src/utils/constructSafeFilename.js index ee3cdd890c..d054bc3218 100644 --- a/detox/src/utils/constructSafeFilename.js +++ b/detox/src/utils/constructSafeFilename.js @@ -1,4 +1,5 @@ -const sanitize = require("sanitize-filename"); +const sanitize = require('sanitize-filename'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); const MAX_FILE_LENGTH = 255; diff --git a/detox/src/utils/customConsoleLogger.js b/detox/src/utils/customConsoleLogger.js index e3ab4df490..17f6f14f9f 100644 --- a/detox/src/utils/customConsoleLogger.js +++ b/detox/src/utils/customConsoleLogger.js @@ -1,4 +1,5 @@ const util = require('util'); + const callsites = require('./callsites'); const USER_STACK_FRAME_INDEX = 2; diff --git a/detox/src/utils/customConsoleLogger.test.js b/detox/src/utils/customConsoleLogger.test.js index d5fcd02159..e9d6f9f927 100644 --- a/detox/src/utils/customConsoleLogger.test.js +++ b/detox/src/utils/customConsoleLogger.test.js @@ -40,8 +40,8 @@ describe('customConsoleLogger.overrideConsoleMethods(console, bunyanLogger)', () }); describe('- proxying to bunyan -', () => { - const expectedOrigin = expect.stringMatching(/at src[\\\/]utils[\\\/]customConsoleLogger\.test\.js:\d+:\d+/); - const expectedStackDump = expect.stringMatching(/at.*src[\\\/]utils[\\\/]customConsoleLogger\.test\.js:\d+:\d+/m); + const expectedOrigin = expect.stringMatching(/at src[\\/]utils[\\/]customConsoleLogger\.test\.js:\d+:\d+/); + const expectedStackDump = expect.stringMatching(/at.*src[\\/]utils[\\/]customConsoleLogger\.test\.js:\d+:\d+/m); beforeEach(() => { overrideConsoleMethods(fakeConsole, bunyanLogger); diff --git a/detox/src/utils/environment.js b/detox/src/utils/environment.js index bd6a2b8045..ce4d31580f 100644 --- a/detox/src/utils/environment.js +++ b/detox/src/utils/environment.js @@ -1,16 +1,19 @@ -const _ = require('lodash'); const fs = require('fs'); const os = require('os'); const path = require('path'); + +const exec = require('child-process-promise').exec; const ini = require('ini'); +const _ = require('lodash'); const _which = require('which'); -const exec = require('child-process-promise').exec; + +const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); + const appdatapath = require('./appdatapath'); const fsext = require('./fsext'); -const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); function which(executable, path) { - return _which.sync(executable, {path, nothrow: true}); + return _which.sync(executable, { path, nothrow: true }); } const DETOX_LIBRARY_ROOT_PATH = path.join(appdatapath.appDataPath(), 'Detox'); @@ -40,12 +43,12 @@ function getAvdHome() { function getAvdDir(avdName) { const avdIniPath = path.join(getAvdHome(), `${avdName}.ini`); if (!fs.existsSync(avdIniPath)) { - throwMissingAvdINIError(avdName, avdIniPath) + throwMissingAvdINIError(avdName, avdIniPath); } const avdIni = ini.parse(fs.readFileSync(avdIniPath, 'utf-8')); if (!fs.existsSync(avdIni.path)) { - throwMissingAvdError(avdName, avdIni.path, avdIniPath) + throwMissingAvdError(avdName, avdIni.path, avdIniPath); } return avdIni.path; @@ -151,7 +154,7 @@ function throwSdkIntegrityError(sdkRoot, relativeExecutablePath) { } function throwMissingGmsaasError() { - throw new DetoxRuntimeError(`Failed to locate Genymotion\'s gmsaas executable. Please add it to your $PATH variable!\nPATH is currently set to: ${process.env.PATH}`) + throw new DetoxRuntimeError(`Failed to locate Genymotion's gmsaas executable. Please add it to your $PATH variable!\nPATH is currently set to: ${process.env.PATH}`); } function getDetoxVersion() { diff --git a/detox/src/utils/environment.test.js b/detox/src/utils/environment.test.js index 847789c40c..b30d03ee1b 100644 --- a/detox/src/utils/environment.test.js +++ b/detox/src/utils/environment.test.js @@ -1,8 +1,9 @@ +const os = require('os'); +const path = require('path'); + +const fs = require('fs-extra'); const _ = require('lodash'); const tempfile = require('tempfile'); -const fs = require('fs-extra'); -const path = require('path'); -const os = require('os'); describe('Environment', () => { let Environment; @@ -76,12 +77,12 @@ describe('Environment', () => { }); it('should throw error if path specified in INI file does not exist', () => { - fs.writeFileSync(path.join(avdHome, 'MyAVD.ini'), `path=randomPath${Math.random()}`) + fs.writeFileSync(path.join(avdHome, 'MyAVD.ini'), `path=randomPath${Math.random()}`); expect(() => Environment.getAvdDir('MyAVD')).toThrow(/Failed to find.*randomPath0\./); }); it('should return path specified in INI file if it exists', () => { - fs.writeFileSync(path.join(avdHome, 'MyAVD.ini'), `path=${avdHome}`) + fs.writeFileSync(path.join(avdHome, 'MyAVD.ini'), `path=${avdHome}`); expect(Environment.getAvdDir('MyAVD')).toBe(avdHome); }); }); @@ -274,7 +275,7 @@ describe('Environment', () => { it('should throw error if gmsaas is not in $PATH', async () => { const pathToNowhere = path.join('one', 'mock', 'directory'); process.env.PATH = pathToNowhere; - await expect(async () => Environment.getGmsaasPath()).rejects.toThrow(`Failed to locate Genymotion\'s gmsaas executable. Please add it to your $PATH variable!\nPATH is currently set to: ${pathToNowhere}`); + await expect(async () => Environment.getGmsaasPath()).rejects.toThrow(`Failed to locate Genymotion's gmsaas executable. Please add it to your $PATH variable!\nPATH is currently set to: ${pathToNowhere}`); }); }); }); diff --git a/detox/src/utils/errorUtils.test.js b/detox/src/utils/errorUtils.test.js index bb85c92207..f562dc5007 100644 --- a/detox/src/utils/errorUtils.test.js +++ b/detox/src/utils/errorUtils.test.js @@ -1,5 +1,6 @@ -const _ = require("lodash"); -const errorUtils = require("./errorUtils"); +const _ = require('lodash'); + +const errorUtils = require('./errorUtils'); describe('sliceErrorStack(error, fromIndex)', () => { it('should clean up error stack by N first lines containing at:', () => { @@ -21,7 +22,7 @@ describe('sliceErrorStack(error, fromIndex)', () => { const err = new Error(); delete err.stack; - errorUtils.filterErrorStack(err, () => true) + errorUtils.filterErrorStack(err, () => true); expect(err.stack).toBe(''); }); }); @@ -54,7 +55,7 @@ describe('replaceErrorStack(source, target)', () => { describe('createErrorWithUserStack()', () => { it('should not have /detox/src/ lines in stack', () => { - expect(new Error().stack).toMatch(/[\\\/]detox[\\\/]src[\\\/]/m); // sanity assertion + expect(new Error().stack).toMatch(/[\\/]detox[\\/]src[\\/]/m); // sanity assertion expect(errorUtils.createErrorWithUserStack()).not.toContain('/detox/src/'); // POSIX expect(errorUtils.createErrorWithUserStack()).not.toContain('\\detox\\src\\'); // WIN32 @@ -68,7 +69,7 @@ describe('asError(err)', () => { }); it('should wrap non-Error with Error', () => { - const err = 'non-Error' + const err = 'non-Error'; expect(errorUtils.asError(err)).toBeInstanceOf(Error); expect(errorUtils.asError(err).message).toBe(err); }); diff --git a/detox/src/utils/exec.interruptProcess.test.js b/detox/src/utils/exec.interruptProcess.test.js index 53f7acabb8..e5fc26d5e2 100644 --- a/detox/src/utils/exec.interruptProcess.test.js +++ b/detox/src/utils/exec.interruptProcess.test.js @@ -10,7 +10,7 @@ describe('interruptProcess', () => { it('should throw exception if child process exited with an error', async () => { const script = "process.on('SIGINT', () => {});" + - "setTimeout(()=>process.exit(1), 100);"; + 'setTimeout(()=>process.exit(1), 100);'; await interruptProcess(spawnAndLog('node', ['-e', script])); }, 1000); @@ -18,7 +18,7 @@ describe('interruptProcess', () => { it('should SIGTERM a stuck process after specified time', async () => { const script = "process.on('SIGINT', () => {});" + - "setTimeout(()=>process.exit(1), 10000);"; + 'setTimeout(()=>process.exit(1), 10000);'; const theProcess = spawnAndLog('node', ['-e', script]); await interruptProcess(theProcess, { diff --git a/detox/src/utils/exec.js b/detox/src/utils/exec.js index d73dc54ef9..d3a995f8e1 100644 --- a/detox/src/utils/exec.js +++ b/detox/src/utils/exec.js @@ -1,9 +1,11 @@ +const { exec, spawn } = require('child-process-promise'); const _ = require('lodash'); -const {exec, spawn} = require('child-process-promise'); + +const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); + const execLogger = require('./logger').child({ __filename }); -const retry = require('./retry'); const { escape } = require('./pipeCommands'); -const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); +const retry = require('./retry'); let _operationCounter = 0; @@ -26,7 +28,7 @@ async function execWithRetriesAndLogs(bin, options = {}) { try { log.debug({ event: 'EXEC_CMD' }, `${cmd}`); - await retry({retries, interval}, async (retryNumber, lastError) => { + await retry({ retries, interval }, async (retryNumber, lastError) => { if (statusLogs.trying) { _logTrying(log, statusLogs.trying, retryNumber, lastError); } else if (statusLogs.retrying) { @@ -126,7 +128,7 @@ function _composeCommand(bin, prefix, args) { function spawnAndLog(command, flags, options) { const cmd = _joinCommandAndFlags(command, flags); - const result = spawn(command, flags, {stdio: ['ignore', 'pipe', 'pipe'], ...options}); + const result = spawn(command, flags, { stdio: ['ignore', 'pipe', 'pipe'], ...options }); const { childProcess } = result; const { exitCode, stdout, stderr } = childProcess; diff --git a/detox/src/utils/exec.test.js b/detox/src/utils/exec.test.js index 74ee16a341..24f5cf1605 100644 --- a/detox/src/utils/exec.test.js +++ b/detox/src/utils/exec.test.js @@ -27,7 +27,7 @@ describe('exec', () => { it(`exec command with arguments successfully`, async () => { mockCppSuccessful(cpp); - const options = {args: `--argument 123`}; + const options = { args: `--argument 123` }; await exec.execWithRetriesAndLogs('bin', options); expect(cpp.exec).toHaveBeenCalledWith(`bin --argument 123`, { timeout: 0 }); @@ -56,7 +56,7 @@ describe('exec', () => { it(`exec command with prefix (no args) successfully`, async () => { mockCppSuccessful(cpp); - const options = {prefix: `export MY_PREFIX`}; + const options = { prefix: `export MY_PREFIX` }; await exec.execWithRetriesAndLogs('bin', options); expect(cpp.exec).toHaveBeenCalledWith(`export MY_PREFIX && bin`, { timeout: 0 }); @@ -77,8 +77,8 @@ describe('exec', () => { await exec.execWithRetriesAndLogs('bin', options); expect(cpp.exec).toHaveBeenCalledWith(`bin --argument 123`, { timeout: 0 }); - expect(logger.debug).toHaveBeenCalledWith({ event: 'EXEC_TRY', retryNumber: 1}, options.statusLogs.trying); - expect(logger.debug).toHaveBeenCalledWith({ event: 'EXEC_TRY', retryNumber: 2}, options.statusLogs.trying); + expect(logger.debug).toHaveBeenCalledWith({ event: 'EXEC_TRY', retryNumber: 1 }, options.statusLogs.trying); + expect(logger.debug).toHaveBeenCalledWith({ event: 'EXEC_TRY', retryNumber: 2 }, options.statusLogs.trying); expect(logger.trace).toHaveBeenCalledWith({ event: 'EXEC_TRY_FAIL' }, 'error result'); }); @@ -96,8 +96,8 @@ describe('exec', () => { await exec.execWithRetriesAndLogs('bin', options); expect(cpp.exec).toHaveBeenCalledWith(`bin --argument 123`, { timeout: 0 }); - expect(logger.debug).toHaveBeenCalledWith({ event: 'EXEC_RETRY', retryNumber: 2}, '(Retry #1)', 'bin --argument 123'); - expect(logger.debug).not.toHaveBeenCalledWith({ event: 'EXEC_RETRY', retryNumber: 1}, expect.any(String), expect.any(String)); + expect(logger.debug).toHaveBeenCalledWith({ event: 'EXEC_RETRY', retryNumber: 2 }, '(Retry #1)', 'bin --argument 123'); + expect(logger.debug).not.toHaveBeenCalledWith({ event: 'EXEC_RETRY', retryNumber: 1 }, expect.any(String), expect.any(String)); expect(logger.trace).toHaveBeenCalledWith({ event: 'EXEC_TRY_FAIL' }, 'error result'); }); @@ -129,7 +129,7 @@ describe('exec', () => { expect(logger.debug).toHaveBeenCalledWith({ event: 'EXEC_SUCCESS', stdout: true }, '"successful result"'); expect(logger.debug).toHaveBeenCalledWith({ event: 'EXEC_SUCCESS', stderr: true }, 'err'); - expect(logger.trace).not.toHaveBeenCalledWith(expect.objectContaining({event: 'EXEC_SUCCESS'}), expect.anything()); + expect(logger.trace).not.toHaveBeenCalledWith(expect.objectContaining({ event: 'EXEC_SUCCESS' }), expect.anything()); }); it(`exec command with undefined return should throw`, async () => { @@ -151,7 +151,7 @@ describe('exec', () => { } catch (object) { expect(cpp.exec).toHaveBeenCalledWith(`bin`, { timeout: 0 }); expect(logger.error.mock.calls).toHaveLength(3); - expect(logger.error).toHaveBeenCalledWith(expect.objectContaining({event: 'EXEC_FAIL'}), expect.anything()); + expect(logger.error).toHaveBeenCalledWith(expect.objectContaining({ event: 'EXEC_FAIL' }), expect.anything()); } }); @@ -326,7 +326,7 @@ function nextCycle() { } function toStream(string) { - const {Readable} = require('stream'); + const { Readable } = require('stream'); const stream = new Readable(); stream._read = () => {}; stream.push(string); @@ -336,14 +336,14 @@ function toStream(string) { const returnSuccessfulWithValue = (value) => ({ stdout: JSON.stringify(value), - stderr: "err", + stderr: 'err', childProcess: { exitCode: 0 } }); const returnErrorWithValue = (value) => ({ - stdout: "out", + stdout: 'out', stderr: value, childProcess: { exitCode: 1 diff --git a/detox/src/utils/fsext.js b/detox/src/utils/fsext.js index 1a799524b6..ae046597e5 100644 --- a/detox/src/utils/fsext.js +++ b/detox/src/utils/fsext.js @@ -1,6 +1,7 @@ -const fs = require('fs-extra'); const path = require('path'); +const fs = require('fs-extra'); + async function getDirectories (rootPath) { let files = await fs.readdir(rootPath); let dirs = []; diff --git a/detox/src/utils/getAbsoluteBinaryPath.js b/detox/src/utils/getAbsoluteBinaryPath.js index c72bde5ed7..7dd88eb910 100644 --- a/detox/src/utils/getAbsoluteBinaryPath.js +++ b/detox/src/utils/getAbsoluteBinaryPath.js @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); + const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); function getAbsoluteBinaryPath(appPath) { diff --git a/detox/src/utils/getAbsoluteBinaryPath.test.js b/detox/src/utils/getAbsoluteBinaryPath.test.js index ba6d4c82b6..d93e2d430d 100644 --- a/detox/src/utils/getAbsoluteBinaryPath.test.js +++ b/detox/src/utils/getAbsoluteBinaryPath.test.js @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); + const getAbsoluteBinaryPath = require('./getAbsoluteBinaryPath'); describe('getAbsoluteBinaryPath', () => { diff --git a/detox/src/utils/lastFailedTests.js b/detox/src/utils/lastFailedTests.js index d2ea44c63f..0970ac19b5 100644 --- a/detox/src/utils/lastFailedTests.js +++ b/detox/src/utils/lastFailedTests.js @@ -1,4 +1,5 @@ const fs = require('fs-extra'); + const environment = require('./environment'); async function resetLastFailedTests() { diff --git a/detox/src/utils/logger.js b/detox/src/utils/logger.js index 58f966cf1d..f52be081e5 100644 --- a/detox/src/utils/logger.js +++ b/detox/src/utils/logger.js @@ -1,10 +1,13 @@ -const fs = require('fs-extra'); -const onExit = require('signal-exit'); const path = require('path'); + const bunyan = require('bunyan'); const bunyanDebugStream = require('bunyan-debug-stream'); -const argparse = require('./argparse'); +const fs = require('fs-extra'); +const onExit = require('signal-exit'); + const temporaryPath = require('../artifacts/utils/temporaryPath'); + +const argparse = require('./argparse'); const customConsoleLogger = require('./customConsoleLogger'); function adaptLogLevelName(level) { diff --git a/detox/src/utils/pipeCommands.js b/detox/src/utils/pipeCommands.js index f07e836c64..759dd3de01 100644 --- a/detox/src/utils/pipeCommands.js +++ b/detox/src/utils/pipeCommands.js @@ -1,6 +1,6 @@ const { - escapeInDoubleQuotedString, escapeInDoubleQuotedRegexp, + escapeInDoubleQuotedString, isRunningInCMDEXE, } = require('./shellUtils'); diff --git a/detox/src/utils/pressAnyKey.js b/detox/src/utils/pressAnyKey.js index eb1001b353..f94f2c19e5 100644 --- a/detox/src/utils/pressAnyKey.js +++ b/detox/src/utils/pressAnyKey.js @@ -20,6 +20,6 @@ async function pressAnyKey() { } } }); -}; +} module.exports = pressAnyKey; diff --git a/detox/src/utils/resolveModuleFromPath.js b/detox/src/utils/resolveModuleFromPath.js index 7485530ecf..5d2e2d5fd9 100644 --- a/detox/src/utils/resolveModuleFromPath.js +++ b/detox/src/utils/resolveModuleFromPath.js @@ -1,5 +1,5 @@ function resolveModuleFromPath(modulePath) { - const resolvedModulePath = require.resolve(modulePath, { paths: [process.cwd()]}); + const resolvedModulePath = require.resolve(modulePath, { paths: [process.cwd()] }); return require(resolvedModulePath); } diff --git a/detox/src/utils/resolveModuleFromPath.test.js b/detox/src/utils/resolveModuleFromPath.test.js index 659025a1db..9fdd76428f 100644 --- a/detox/src/utils/resolveModuleFromPath.test.js +++ b/detox/src/utils/resolveModuleFromPath.test.js @@ -1,5 +1,7 @@ -const _ = require('lodash'); const path = require('path'); + +const _ = require('lodash'); + const resolveModuleFromPath = require('./resolveModuleFromPath'); const RELATIVE_PATH_TO_PACKAGE_JSON = '../../package.json'; diff --git a/detox/src/utils/retry.js b/detox/src/utils/retry.js index 40c876962b..88007517e7 100644 --- a/detox/src/utils/retry.js +++ b/detox/src/utils/retry.js @@ -25,6 +25,7 @@ async function retry(optionsOrFunc, func) { const backoffFn = backoffModes[backoff](); + // eslint-disable-next-line no-constant-condition for (let totalTries = 1, lastError = null; true; totalTries++) { try { return await func(totalTries, lastError); diff --git a/detox/src/utils/retry.test.js b/detox/src/utils/retry.test.js index b7591e5bcd..5873482723 100644 --- a/detox/src/utils/retry.test.js +++ b/detox/src/utils/retry.test.js @@ -22,7 +22,7 @@ describe('retry', () => { const mockFn = mockFailingOnceUserFn(); try { - await retry({retries: 999, interval: 0}, mockFn); + await retry({ retries: 999, interval: 0 }, mockFn); } catch (e) { fail('expected retry not to fail'); } @@ -32,13 +32,13 @@ describe('retry', () => { it('should retry multiple times', async () => { const mockFn = mockFailingTwiceUserFn(); - await retry({retries: 999, interval: 0}, mockFn); + await retry({ retries: 999, interval: 0 }, mockFn); expect(mockFn).toHaveBeenCalledTimes(3); }); it('should provide error info in each failure', async () => { const mockFn = mockFailingTwiceUserFn(); - await retry({retries: 999, interval: 0}, mockFn); + await retry({ retries: 999, interval: 0 }, mockFn); expect(mockFn).toHaveBeenCalledWith(1, null); expect(mockFn).toHaveBeenCalledWith(2, new Error('once')); expect(mockFn).toHaveBeenCalledWith(3, new Error('twice')); @@ -47,7 +47,7 @@ describe('retry', () => { it('should adhere to retries parameter', async () => { const mockFn = mockFailingUserFn(); try { - await retry({retries: 2, interval: 1}, mockFn); + await retry({ retries: 2, interval: 1 }, mockFn); fail('expected retry to fail and throw'); } catch (error) { expect(mockFn).toHaveBeenCalledTimes(3); @@ -60,7 +60,7 @@ describe('retry', () => { const baseInterval = 111; try { - await retry({retries: 2, interval: baseInterval}, mockFn); + await retry({ retries: 2, interval: baseInterval }, mockFn); fail('expected retry to fail and throw'); } catch (error) {} @@ -114,7 +114,7 @@ describe('retry', () => { .mockReturnValueOnce(false); try { - await retry({retries: 999, interval: 1, conditionFn}, mockFn); + await retry({ retries: 999, interval: 1, conditionFn }, mockFn); fail('expected retry to fail and throw'); } catch (error) {} diff --git a/detox/src/utils/setUniqueProperty.test.js b/detox/src/utils/setUniqueProperty.test.js index ac343e863b..9130ececad 100644 --- a/detox/src/utils/setUniqueProperty.test.js +++ b/detox/src/utils/setUniqueProperty.test.js @@ -1,15 +1,15 @@ const setUniqueProperty = require('./setUniqueProperty'); describe('setUniqueProperty(obj, key, value', () => { - it("should set obj[key] = value", () => { + it('should set obj[key] = value', () => { expect(setUniqueProperty({}, 'a', 1)).toEqual({ a: 1 }); }); - it("should set obj[key + 2] = value if obj[key] exists", () => { + it('should set obj[key + 2] = value if obj[key] exists', () => { expect(setUniqueProperty({ a: 1 }, 'a', 2)).toEqual({ a: 1, a2: 2 }); }); - it("should set obj[key + 3] = value if obj[key] and obj[key + 2] exist", () => { + it('should set obj[key + 3] = value if obj[key] and obj[key + 2] exist', () => { expect(setUniqueProperty({ a: 1, a2: 2 }, 'a', 3)).toEqual({ a: 1, a2: 2, a3: 3 }); }); }); diff --git a/detox/src/utils/sh.js b/detox/src/utils/sh.js index dc95386e79..9b27a6e55e 100644 --- a/detox/src/utils/sh.js +++ b/detox/src/utils/sh.js @@ -1,6 +1,7 @@ -const cpp = require('child-process-promise'); const fs = require('fs'); +const cpp = require('child-process-promise'); + const sh = new Proxy({}, { get: function(target, prop) { if (target[prop] === undefined) { diff --git a/detox/src/utils/sh.test.js b/detox/src/utils/sh.test.js index cb3552fd67..d48e829cfc 100644 --- a/detox/src/utils/sh.test.js +++ b/detox/src/utils/sh.test.js @@ -18,7 +18,6 @@ describe('sh', () => { expect(cpp.exec).toHaveBeenCalledWith('cp -r path/to/src pat/to/dest'); }); - it(`Require an undefined param from sh and then initiate it as function should generate a full command string`, async () => { const npm = require('./sh').npm; await npm('-v'); diff --git a/detox/src/utils/shellQuote.js b/detox/src/utils/shellQuote.js index 091e02bef4..82ffc22250 100644 --- a/detox/src/utils/shellQuote.js +++ b/detox/src/utils/shellQuote.js @@ -1,5 +1,6 @@ const _ = require('lodash'); const shellQuote = require('shell-quote'); + const { autoEscape } = require('../../src/utils/shellUtils'); function quote(argv) { diff --git a/detox/src/utils/shellQuote.test.js b/detox/src/utils/shellQuote.test.js index c4fb486609..2b456bad26 100644 --- a/detox/src/utils/shellQuote.test.js +++ b/detox/src/utils/shellQuote.test.js @@ -1,4 +1,4 @@ -const { quote, parse } = require('./shellQuote'); +const { parse, quote } = require('./shellQuote'); describe('shellQuote', () => { describe('.quote(argv)', () => { diff --git a/detox/src/utils/shellUtils.js b/detox/src/utils/shellUtils.js index 2601d6f633..e9270573b9 100644 --- a/detox/src/utils/shellUtils.js +++ b/detox/src/utils/shellUtils.js @@ -16,7 +16,7 @@ function escapeWithDoubleQuotedString(fragment) { return DOUBLE_QUOTE + escapeInDoubleQuotedString(fragment) + DOUBLE_QUOTE; } -const SPECIAL_CHARS = /([\^\$\[\]\*\.\\])/g; +const SPECIAL_CHARS = /([\^$[\]*.\\])/g; function escapeInDoubleQuotedRegexp(fragment) { return fragment.replace(SPECIAL_CHARS, '\\$1'); } @@ -26,8 +26,8 @@ function isRunningInCMDEXE() { /* istanbul ignore next */ !process.env['SHELL']; } -const UNSAFE_SHELL = /[\s!"#$&'()*;<=>^?`{,}|~\[\\\]]/m; -const UNSAFE_CMD = /[\s!"#$&'()*;<=>^?`{,}|~\[\]]/m; +const UNSAFE_SHELL = /[\s!"#$&'()*;<=>^?`{,}|~[\\\]]/m; +const UNSAFE_CMD = /[\s!"#$&'()*;<=>^?`{,}|~[\]]/m; /* @see https://unix.stackexchange.com/a/357932 */ function hasUnsafeShellChars(str) { diff --git a/detox/src/utils/shellUtils.test.js b/detox/src/utils/shellUtils.test.js index 6dd8a64cc0..0a1f431f40 100644 --- a/detox/src/utils/shellUtils.test.js +++ b/detox/src/utils/shellUtils.test.js @@ -1,11 +1,11 @@ const { - escapeInDoubleQuotedString, + autoEscape, escapeInDoubleQuotedRegexp, - escapeWithSingleQuotedString, + escapeInDoubleQuotedString, escapeWithDoubleQuotedString, - isRunningInCMDEXE, + escapeWithSingleQuotedString, hasUnsafeChars, - autoEscape, + isRunningInCMDEXE, } = require('./shellUtils'); describe('shellUtils', function() { @@ -74,7 +74,7 @@ describe('shellUtils', function() { [true, true, '>', 'shell syntax'], [true, true, '?', 'a sh wildcard'], [true, true, '[', 'a sh wildcard'], - [false, true, "\\", 'shell syntax'], + [false, true, '\\', 'shell syntax'], [true, true, ']', 'a sh wildcard'], [true, true, '^', 'a history expansion, zsh wildcard'], [true, true, '`', 'shell syntax'], @@ -121,7 +121,7 @@ describe('shellUtils', function() { describe('autoEscape.shell', () => { test.each([ ['test', 'test'], - ["test string", "'test string'"], + ['test string', "'test string'"], ["test 'this' string", `'test '"'"'this'"'"' string'`], ])('should transform [ %s ] to [ %s ]', (input, expected) => { expect(autoEscape.shell(input)).toBe(expected); diff --git a/detox/src/utils/string.js b/detox/src/utils/string.js index 575625cdc5..83e84b91c8 100644 --- a/detox/src/utils/string.js +++ b/detox/src/utils/string.js @@ -15,7 +15,7 @@ function lowerCamelCaseJoin(array) { let retVal = first; _.forEach(rest, (str) => { retVal += capitalizeFirstLetter(str); - }) + }); return retVal; } module.exports = { diff --git a/detox/src/utils/trace.js b/detox/src/utils/trace.js index 4eae09843e..7dbfdf331c 100644 --- a/detox/src/utils/trace.js +++ b/detox/src/utils/trace.js @@ -30,7 +30,7 @@ class Trace { ts: this._timestampProviderFn(), name, args, - } + }; } } diff --git a/detox/src/utils/trace.test.js b/detox/src/utils/trace.test.js index 56c6e74910..1547e886fa 100644 --- a/detox/src/utils/trace.test.js +++ b/detox/src/utils/trace.test.js @@ -24,7 +24,7 @@ describe('Trace util', () => { const section = { name: 'section-name', args: { arg1: 'val1' }, - } + }; uut.startSection(section.name, section.args); expect(uut.events[1]).toEqual({ @@ -38,7 +38,7 @@ describe('Trace util', () => { const section = { name: 'section-name', args: { arg1: 'val1' }, - } + }; uut.startSection(section.name, section.args); uut.endSection(section.name, section.args); @@ -53,7 +53,7 @@ describe('Trace util', () => { const section = { name: 'section-name', args: { arg1: 'val1' }, - } + }; uut.startSection(section.name, section.args); uut.endSection(section.name, section.args);