Skip to content

Commit 2a4df94

Browse files
author
Krzysztof Wojnar
committed
chore(e2e): detox config cleanup
1 parent cf5dc93 commit 2a4df94

File tree

7 files changed

+59
-22
lines changed

7 files changed

+59
-22
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ android/.settings
6464
# Local environment (direnv)
6565
.envrc
6666

67+
# e2e
68+
*Example/artifacts

Example/.detoxrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const utils = require('../scripts/detox-utils.cjs');
1+
const utils = require('../scripts/e2e/detox-utils.cjs');
22
module.exports = utils.commonDetoxConfigFactory('ScreensExample');

Example/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"format": "prettier --write --list-different './src/**/*.{js,ts,tsx}'",
1010
"lint": "eslint --ext '.js,.ts,.tsx' --fix src && yarn check-types && yarn format",
1111
"check-types": "tsc --noEmit",
12-
"build-e2e-ios": "detox build --configuration ios.release",
13-
"build-e2e-android": "detox build --configuration android.release",
14-
"test-e2e-ios": "detox test --configuration ios.release --take-screenshots failing",
15-
"test-e2e-android": "detox test --configuration android.release --take-screenshots failing",
12+
"build-e2e-ios": "detox build --configuration ios.sim.release",
13+
"build-e2e-android": "detox build --configuration android.emu.release",
14+
"test-e2e-ios": "detox test --configuration ios.sim.release --take-screenshots failing",
15+
"test-e2e-android": "detox test --configuration android.emu.release --take-screenshots failing",
1616
"postinstall": "patch-package"
1717
},
1818
"dependencies": {

FabricExample/.detoxrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const utils = require('../scripts/detox-utils.cjs');
1+
const utils = require('../scripts/e2e/detox-utils.cjs');
22
module.exports = utils.commonDetoxConfigFactory('FabricExample');
33

FabricExample/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"lint": "eslint .",
99
"start": "npx react-native start",
1010
"test": "jest",
11-
"build-e2e-ios": "detox build --configuration ios.release",
12-
"build-e2e-android": "detox build --configuration android.release",
13-
"test-e2e-ios": "detox test --configuration ios.release --take-screenshots failing",
14-
"test-e2e-android": "detox test --configuration android.release --take-screenshots failing",
11+
"build-e2e-ios": "detox build --configuration ios.sim.release",
12+
"build-e2e-android": "detox build --configuration android.emu.release",
13+
"test-e2e-ios": "detox test --configuration ios.sim.release --take-screenshots failing",
14+
"test-e2e-android": "detox test --configuration android.emu.release --take-screenshots failing",
1515
"postinstall": "patch-package"
1616
},
1717
"dependencies": {

scripts/detox-utils.cjs renamed to scripts/e2e/detox-utils.cjs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const ChildProcess = require('node:child_process');
2+
const { iosDevice } = require('./ios-devices');
23

3-
const CI_AVD_NAME = 'e2e_emulator';
4+
const CI_ADB_NAME = 'e2e_emulator';
45

56
const isRunningCI = process.env.CI != null;
67

@@ -11,10 +12,10 @@ const apkBulidArchitecture = isRunningCI ? 'x86_64' : 'arm64-v8a';
1112
const testButlerApkPath = isRunningCI ? ['../Example/e2e/apps/test-butler-app-2.2.1.apk'] : undefined;
1213

1314
function detectLocalAndroidEmulator() {
14-
// "DETOX_AVD_NAME" can be set for local developement
15-
const detoxAvdName = process.env.DETOX_AVD_NAME ?? null;
16-
if (detoxAvdName !== null) {
17-
return detoxAvdName
15+
// "DETOX_ADB_NAME" can be set for local developement
16+
const detoxAdbName = process.env.DETOX_ADB_NAME ?? null;
17+
if (detoxAdbName !== null) {
18+
return detoxAdbName
1819
}
1920

2021
// Fallback: try to use Android SDK
@@ -36,18 +37,17 @@ function detectLocalAndroidEmulator() {
3637
// TODO: consider giving user a choice here.
3738
return avdList[0];
3839
} catch (error) {
39-
const errorMessage = `Failed to find Android emulator. Set "DETOX_AVD_NAME" env variable pointing to one. Cause: ${error}`
40+
const errorMessage = `Failed to find Android emulator. Set "DETOX_ADB_NAME" env variable pointing to one. Cause: ${error}`
4041
console.error(errorMessage);
4142
throw new Error(errorMessage);
4243
}
4344
}
4445

4546
function detectAndroidEmulatorName() {
46-
return isRunningCI ? CI_AVD_NAME : detectLocalAndroidEmulator();
47+
return isRunningCI ? CI_ADB_NAME : detectLocalAndroidEmulator();
4748
}
4849

4950
/**
50-
* @type {Detox.DetoxConfig}
5151
* @param {string} applicationName name (FabricExample / ScreensExample)
5252
* @returns {Detox.DetoxConfig}
5353
*/
@@ -94,14 +94,12 @@ function commonDetoxConfigFactory(applicationName) {
9494
devices: {
9595
simulator: {
9696
type: 'ios.simulator',
97-
device: {
98-
type: 'iPhone 16 Pro',
99-
},
97+
device: iosDevice,
10098
},
10199
attached: {
102100
type: 'android.attached',
103101
device: {
104-
adbName: CI_AVD_NAME,
102+
adbName: CI_ADB_NAME,
105103
},
106104
utilBinaryPaths: testButlerApkPath,
107105
},

scripts/e2e/ios-devices.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const DEFEAULT_APPLE_MODEL = 'iPhone 17';
2+
const DEVICE_MODEL = process.env.E2E_APPLE_DEVICE || DEFEAULT_APPLE_MODEL
3+
const DEFEAULT_IOS_VERSION = 'iOS 26.2';
4+
5+
/**
6+
* @return {`iOS ${string}`} requested version of ios, or default if not specified
7+
*/
8+
function getiosVersion() {
9+
const passedVersion = process.env.E2E_IOS_VERSION;
10+
if (passedVersion) {
11+
if (passedVersion.startsWith('iOS ')) {
12+
return /** @type {`iOS ${string}`} */ (passedVersion);
13+
}
14+
return `iOS ${passedVersion}`;
15+
}
16+
return DEFEAULT_IOS_VERSION;
17+
}
18+
19+
/**
20+
* @typedef {Object} AppleDevice - creates a new type named 'SpecialType'
21+
* @property {string} type - a string which represents a model of an iPhone
22+
* @property {`iOS ${string}`} os - operation system version
23+
*/
24+
25+
/**
26+
* @satisfies {AppleDevice}
27+
* @readonly
28+
* */
29+
const iosDevice = {
30+
type: DEVICE_MODEL,
31+
os: getiosVersion(),
32+
};
33+
34+
module.exports = {
35+
iosDevice,
36+
getiosVersion,
37+
};

0 commit comments

Comments
 (0)