Skip to content

Commit

Permalink
e2e: auto-configure device/emulator names
Browse files Browse the repository at this point in the history
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
mnzaki committed Aug 20, 2019
1 parent 0e757b2 commit f1c847a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
44 changes: 33 additions & 11 deletions e2e/init.js
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()
});
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,26 @@
"build":
"cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_24"
"name": "dynamic"
},
"android.emu.release": {
"binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
"build": "cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_26"
"name": "dynamic"
},
"android.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build":
"cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.attached",
"name": "PL2GARB832801755"
"name": "dynamic"
},
"android.release": {
"binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
"build": "cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..",
"type": "android.attached",
"name": "PL2GARB832801755"
"name": "dynamic"
}
},
"test-runner": "jest",
Expand Down

0 comments on commit f1c847a

Please sign in to comment.