Repository navigation
Expand file tree
/
Copy pathe2eSlotEnv.test.js
More file actions
176 lines (162 loc) · 6.65 KB
/
Copy pathe2eSlotEnv.test.js
File metadata and controls
176 lines (162 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
const { execFileSync } = require('child_process');
const path = require('path');
const repoRoot = path.resolve(__dirname, '../../..');
const exportSlotEnv = path.join(repoRoot, 'scripts/e2e/export-slot-env.sh');
function exportAndroidSlot(slot) {
return execFileSync('bash', [exportSlotEnv, 'android', String(slot)], {
encoding: 'utf8',
cwd: repoRoot,
});
}
describe('export-slot-env android console pin', function () {
it('exports emulator-5556 for slot 0 and does not unset ANDROID_SERIAL', function () {
const out = exportAndroidSlot(0);
expect(out).toMatch(/export RNFB_ANDROID_CONSOLE_PORT=5556\b/);
expect(out).toMatch(/export ANDROID_SERIAL=emulator-5556\b/);
expect(out).not.toMatch(/^unset ANDROID_SERIAL$/m);
expect(out).not.toMatch(/^unset RNFB_ANDROID_CONSOLE_PORT$/m);
expect(out).toMatch(/export RNFB_ANDROID_AVD=TestingAVD-0\b/);
});
it('pins slot 1 and 2 to 5558 and 5560', function () {
expect(exportAndroidSlot(1)).toMatch(/export ANDROID_SERIAL=emulator-5558\b/);
expect(exportAndroidSlot(2)).toMatch(/export ANDROID_SERIAL=emulator-5560\b/);
});
});
describe('export-slot-env iOS simulator pin', function () {
it('exports the exact neutral base for slotted iOS including slots 0 and 7', function () {
const out0 = execFileSync('bash', [exportSlotEnv, 'ios', '0'], {
encoding: 'utf8',
cwd: repoRoot,
});
expect(out0).toMatch(/^export RNFB_IOS_SIMULATOR=RN\\ E2E\\ iOS\\ slot-0$/m);
expect(out0).toMatch(/^export RNFB_IOS_SIM_RUNTIME=iOS\\ 27\.0$/m);
expect(out0).not.toMatch(/slot-0-Detox/);
expect(out0).not.toMatch(/iPhone 17/);
const out7 = execFileSync('bash', [exportSlotEnv, 'ios', '7'], {
encoding: 'utf8',
cwd: repoRoot,
});
expect(out7).toMatch(/^export RNFB_IOS_SIMULATOR=RN\\ E2E\\ iOS\\ slot-7$/m);
expect(out7).toMatch(/^export RNFB_IOS_SIM_RUNTIME=iOS\\ 27\.0$/m);
});
it('respects an explicit RNFB_IOS_SIM_RUNTIME override', function () {
const out = execFileSync('bash', [exportSlotEnv, 'ios', '1'], {
encoding: 'utf8',
cwd: repoRoot,
env: { ...process.env, RNFB_IOS_SIM_RUNTIME: 'iOS 26.0' },
});
expect(out).toMatch(/^export RNFB_IOS_SIM_RUNTIME=iOS\\ 26\.0$/m);
expect(out).not.toMatch(/^export RNFB_IOS_SIM_RUNTIME=iOS\\ 27\.0$/m);
});
});
describe('e2e_sanitize_serial_env iOS runtime pin', function () {
it('keeps RNFB_IOS_SIM_RUNTIME and RNFB_IOS_SIMULATOR_UDID for the serial Detox device while dropping the slot simulator', function () {
const slotEnvLib = path.join(repoRoot, 'scripts/e2e/lib/e2e-slot-env.sh');
const env = {
...process.env,
RNFB_IOS_SIM_RUNTIME: 'iOS 27.0',
RNFB_IOS_SIMULATOR_UDID: 'BOOTED-UDID',
RNFB_IOS_SIMULATOR: 'RN E2E iOS slot-2',
};
delete env.RNFB_E2E_SLOT;
delete env.RNFB_E2E_HOST_SLOT;
const out = execFileSync(
'bash',
[
'-c',
`source "${slotEnvLib}" && e2e_sanitize_serial_env && echo "runtime=\${RNFB_IOS_SIM_RUNTIME:-unset} udid=\${RNFB_IOS_SIMULATOR_UDID:-unset} sim=\${RNFB_IOS_SIMULATOR:-unset}"`,
],
{ encoding: 'utf8', cwd: repoRoot, env },
);
expect(out).toContain('runtime=iOS 27.0 udid=BOOTED-UDID sim=unset');
});
});
function exportSlotFail(platform, slot, extraEnv = {}) {
const env = { ...process.env, ...extraEnv };
delete env.E2E_SLOTTED_MAX;
delete env.E2E_MACOS_SLOTTED_MAX;
Object.assign(env, extraEnv);
try {
const stdout = execFileSync('bash', [exportSlotEnv, platform, String(slot)], {
encoding: 'utf8',
cwd: repoRoot,
env,
stdio: ['pipe', 'pipe', 'pipe'],
});
return { status: 0, stdout, stderr: '' };
} catch (error) {
return {
status: error.status,
stdout: error.stdout || '',
stderr: error.stderr || '',
};
}
}
describe('export-slot-env slot bounds', function () {
it('accepts slot 7 with exact Detox configs, ports, and device names', function () {
const env = { ...process.env };
delete env.E2E_SLOTTED_MAX;
delete env.E2E_MACOS_SLOTTED_MAX;
const out = execFileSync('bash', [exportSlotEnv, 'android', '7'], {
encoding: 'utf8',
cwd: repoRoot,
env,
});
expect(out).toMatch(/^export RNFB_E2E_SLOT=7$/m);
expect(out).toMatch(/^export RNFB_ANDROID_AVD=TestingAVD-7$/m);
expect(out).toMatch(/^export RNFB_DETOX_ANDROID_CONFIG=android.emu.debug.slot7$/m);
expect(out).toMatch(/^export RNFB_DETOX_IOS_CONFIG=ios.sim.debug.slot7$/m);
expect(out).toMatch(/^export RNFB_IOS_SIMULATOR=RN\\ E2E\\ iOS\\ slot-7$/m);
expect(out).toMatch(/^export RNFB_ANDROID_CONSOLE_PORT=5570$/m);
expect(out).toMatch(/^export ANDROID_SERIAL=emulator-5570$/m);
expect(out).toMatch(/^export RNFB_ANDROID_METRO_PORT=19007$/m);
expect(out).toMatch(/^export RNFB_IOS_METRO_PORT=19107$/m);
expect(out).toMatch(/^export RNFB_MACOS_METRO_PORT=19207$/m);
expect(out).not.toMatch(/slot8/);
expect(out).not.toMatch(/-Detox/);
});
it('rejects slot 8, negatives, and non-integers with empty stdout', function () {
for (const slot of ['8', '-1', '1.5', 'foo', '07']) {
const result = exportSlotFail('ios', slot);
expect(result.status).toBe(1);
expect(result.stdout).toBe('');
expect(result.stdout).not.toMatch(/^export /m);
expect(result.stderr).toMatch(/slot must be an integer 0\.\.7 \(got /);
}
});
it('honors a lowered E2E_SLOTTED_MAX but still rejects a raised ceiling past 7', function () {
const loweredOk = execFileSync('bash', [exportSlotEnv, 'android', '2'], {
encoding: 'utf8',
cwd: repoRoot,
env: { ...process.env, E2E_SLOTTED_MAX: '2' },
});
expect(loweredOk).toMatch(/^export RNFB_E2E_SLOT=2$/m);
const loweredReject = exportSlotFail('android', '3', { E2E_SLOTTED_MAX: '2' });
expect(loweredReject.status).toBe(1);
expect(loweredReject.stdout).toBe('');
expect(loweredReject.stderr).toMatch(/slot must be an integer 0\.\.2 \(got 3\)/);
const raisedReject = exportSlotFail('android', '8', { E2E_SLOTTED_MAX: '99' });
expect(raisedReject.status).toBe(1);
expect(raisedReject.stdout).toBe('');
expect(raisedReject.stderr).toMatch(/slot must be an integer 0\.\.7 \(got 8\)/);
});
});
describe('setup slot count bounds', function () {
it('accepts counts 1 and 8 at the hard provisioning boundary', function () {
const slotLib = path.join(repoRoot, 'scripts/e2e/lib/e2e-slot-env.sh');
const out = execFileSync(
'bash',
[
'-c',
`set -euo pipefail
source ${JSON.stringify(slotLib)}
e2e_validate_slot_count 1
e2e_validate_slot_count 8
echo VALID
`,
],
{ encoding: 'utf8', cwd: repoRoot },
);
expect(out.trim()).toBe('VALID');
});
});