-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.ts
More file actions
95 lines (84 loc) · 2.94 KB
/
setup.ts
File metadata and controls
95 lines (84 loc) · 2.94 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
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { sleep } from './actions';
import { getAppId, getAppPath } from './constants';
export async function launchFreshApp() {
const appId = getAppId();
await driver.terminateApp(appId);
await driver.activateApp(appId);
await sleep(3000);
}
/**
* Uninstalls and reinstalls the app (like Detox `launchApp({ delete: true })`)
*/
export async function reinstallApp() {
console.info('→ Reinstalling app...');
const appId = getAppId();
const appPath = getAppPath();
await driver.removeApp(appId);
resetBootedIOSKeychain();
await driver.installApp(appPath);
await driver.activateApp(appId);
}
export function getRnAppPath(): string {
const fallback = path.join(__dirname, '..', '..', 'aut', 'bitkit_rn_regtest.apk');
const appPath = process.env.RN_APK_PATH ?? fallback;
if (!fs.existsSync(appPath)) {
throw new Error(
`RN APK not found at: ${appPath}. Set RN_APK_PATH or place it at ${fallback}`
);
}
return appPath;
}
export function getNativeAppPath(): string {
const fallback = path.join(__dirname, '..', '..', 'aut', 'bitkit_e2e.apk');
const appPath = process.env.NATIVE_APK_PATH ?? fallback;
if (!fs.existsSync(appPath)) {
throw new Error(
`Native APK not found at: ${appPath}. Set NATIVE_APK_PATH or place it at ${fallback}`
);
}
return appPath;
}
export async function reinstallAppFromPath(appPath: string, appId: string = getAppId()) {
console.info(`→ Reinstalling app from: ${appPath}`);
await driver.removeApp(appId);
resetBootedIOSKeychain();
await driver.installApp(appPath);
await driver.activateApp(appId);
}
/**
* Resets iOS simulator to remove stored data between app reinstall cycles.
* (Wallet data is stored in iOS Keychain and persists even after app uninstall
* unless the whole simulator is reset or keychain is reset specifically)
*/
function resetBootedIOSKeychain() {
if (!driver.isIOS) return;
let udid = '';
try {
udid =
(driver.capabilities as Record<string, unknown>)['appium:udid']?.toString() ??
(driver.capabilities as Record<string, unknown>).udid?.toString() ??
(driver.capabilities as Record<string, unknown>).deviceUDID?.toString() ??
'';
} catch {}
if (!udid) {
console.warn(
'⚠ Could not determine iOS simulator UDID; trying to reset booted simulator keychain'
);
try {
execSync(`xcrun simctl keychain booted reset`, { stdio: 'ignore' });
console.info(`→ Reset iOS simulator keychain for booted simulator`);
} catch (error) {
console.warn(`⚠ Failed to reset iOS simulator keychain for booted simulator`, error);
}
return;
}
try {
execSync(`xcrun simctl keychain ${udid} reset`, { stdio: 'ignore' });
console.info(`→ Reset iOS simulator keychain for ${udid}`);
} catch (error) {
console.warn(`⚠ Failed to reset iOS simulator keychain for ${udid}`, error);
}
}