-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e: auto-configure device/emulator names
so we don't have to hardcode devices/emulators in package.json NOTE: this is somewhat hacky, there are dummy ones there or else detox will complain. But the device name keys are only generated last second before detox.init in e2e/init.js
- Loading branch information
Showing
2 changed files
with
37 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,47 @@ | ||
const detox = require('detox'); | ||
const config = require('../package.json').detox; | ||
const adapter = require('detox/runners/jest/adapter'); | ||
const specReporter = require('detox/runners/jest/specReporter'); | ||
const detox = require('detox') | ||
const detoxConfig = require('../package.json').detox | ||
const adapter = require('detox/runners/jest/adapter') | ||
const specReporter = require('detox/runners/jest/specReporter') | ||
|
||
const ADB = require('detox/src/devices/android/ADB') | ||
const adb = new ADB() | ||
|
||
// Set the default timeout | ||
jest.setTimeout(120000); | ||
jasmine.getEnv().addReporter(adapter); | ||
jest.setTimeout(120000) | ||
jasmine.getEnv().addReporter(adapter) | ||
|
||
// This takes care of generating status logs on a per-spec basis. By default, jest only reports at file-level. | ||
// This is strictly optional. | ||
jasmine.getEnv().addReporter(specReporter); | ||
jasmine.getEnv().addReporter(specReporter) | ||
|
||
beforeAll(async () => { | ||
await detox.init(config); | ||
const configs = detoxConfig.configurations | ||
const newConfigs = detoxConfig.configurations = { | ||
'ios.sim.debug': configs['ios.sim.debug'] | ||
} | ||
|
||
try { | ||
const devices = await adb.devices() | ||
devices.forEach(device => { | ||
const key = 'android' + (device.type == 'emulator' ? '.emu' : '') | ||
const releaseTypes = ['debug', 'release'] | ||
releaseTypes.forEach(releaseType => { | ||
const configKey = `${key}.${releaseType}` | ||
newConfigs[configKey] = configs[configKey] | ||
newConfigs[configKey].name = device.name | ||
}) | ||
}) | ||
} catch(err) { | ||
console.error("Could not find android device/emulator", err) | ||
} | ||
await detox.init(detoxConfig) | ||
}); | ||
|
||
beforeEach(async () => { | ||
await adapter.beforeEach(); | ||
await adapter.beforeEach() | ||
}); | ||
|
||
afterAll(async () => { | ||
await adapter.afterAll(); | ||
await detox.cleanup(); | ||
await adapter.afterAll() | ||
await detox.cleanup() | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters