@react-native-harness/cli 1.0.0-alpha.17 → 1.0.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/errors/errorHandler.d.ts.map +1 -1
- package/dist/errors/errorHandler.js +1 -25
- package/dist/errors/errors.d.ts +2 -7
- package/dist/errors/errors.d.ts.map +1 -1
- package/dist/errors/errors.js +0 -17
- package/dist/external.d.ts +1 -10
- package/dist/external.d.ts.map +1 -1
- package/dist/external.js +1 -27
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/src/external.ts +0 -47
- package/tsconfig.json +0 -3
- package/tsconfig.lib.json +1 -12
- package/src/bundlers/metro.ts +0 -102
- package/src/errors/errorHandler.ts +0 -218
- package/src/errors/errors.ts +0 -131
- package/src/platforms/android/build.ts +0 -49
- package/src/platforms/android/device.ts +0 -48
- package/src/platforms/android/emulator.ts +0 -137
- package/src/platforms/android/index.ts +0 -87
- package/src/platforms/ios/build.ts +0 -71
- package/src/platforms/ios/device.ts +0 -79
- package/src/platforms/ios/index.ts +0 -66
- package/src/platforms/ios/simulator.ts +0 -171
- package/src/platforms/platform-adapter.ts +0 -11
- package/src/platforms/platform-registry.ts +0 -26
- package/src/platforms/vega/build.ts +0 -85
- package/src/platforms/vega/device.ts +0 -258
- package/src/platforms/vega/index.ts +0 -107
- package/src/platforms/web/index.ts +0 -16
- package/src/process.ts +0 -33
- package/src/utils.ts +0 -29
package/src/bundlers/metro.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { type ChildProcess } from 'node:child_process';
|
|
2
|
-
import {
|
|
3
|
-
getReactNativeCliPath,
|
|
4
|
-
getExpoCliPath,
|
|
5
|
-
getTimeoutSignal,
|
|
6
|
-
spawn,
|
|
7
|
-
logger,
|
|
8
|
-
SubprocessError,
|
|
9
|
-
} from '@react-native-harness/tools';
|
|
10
|
-
import { isPortAvailable } from '../utils.js';
|
|
11
|
-
import { MetroPortUnavailableError } from '../errors/errors.js';
|
|
12
|
-
|
|
13
|
-
const METRO_PORT = 8081;
|
|
14
|
-
|
|
15
|
-
export const runMetro = async (isExpo = false): Promise<ChildProcess> => {
|
|
16
|
-
const metro = spawn(
|
|
17
|
-
'node',
|
|
18
|
-
[
|
|
19
|
-
isExpo ? getExpoCliPath() : getReactNativeCliPath(),
|
|
20
|
-
'start',
|
|
21
|
-
'--port',
|
|
22
|
-
METRO_PORT.toString(),
|
|
23
|
-
],
|
|
24
|
-
{
|
|
25
|
-
env: {
|
|
26
|
-
...process.env,
|
|
27
|
-
RN_HARNESS: 'true',
|
|
28
|
-
...(isExpo && { EXPO_NO_METRO_WORKSPACE_ROOT: 'true' }),
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
// Forward metro output to logger
|
|
34
|
-
metro.nodeChildProcess.then((childProcess) => {
|
|
35
|
-
if (childProcess.stdout) {
|
|
36
|
-
childProcess.stdout.on('data', (data) => {
|
|
37
|
-
logger.debug(data.toString().trim());
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
if (childProcess.stderr) {
|
|
41
|
-
childProcess.stderr.on('data', (data) => {
|
|
42
|
-
logger.debug(data.toString().trim());
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
metro.catch((error) => {
|
|
48
|
-
// This process is going to be killed by us, so we don't need to throw an error
|
|
49
|
-
if (error instanceof SubprocessError && error.signalName === 'SIGTERM') {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
logger.error('Metro crashed unexpectedly', error);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const isDefaultPortAvailable = await isPortAvailable(METRO_PORT);
|
|
57
|
-
|
|
58
|
-
if (!isDefaultPortAvailable) {
|
|
59
|
-
throw new MetroPortUnavailableError(METRO_PORT);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
await waitForMetro();
|
|
63
|
-
return metro.nodeChildProcess;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const waitForMetro = async (
|
|
67
|
-
port = 8081,
|
|
68
|
-
maxRetries = 20,
|
|
69
|
-
retryDelay = 1000
|
|
70
|
-
): Promise<void> => {
|
|
71
|
-
let attempts = 0;
|
|
72
|
-
|
|
73
|
-
while (attempts < maxRetries) {
|
|
74
|
-
attempts++;
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const response = await fetch(`http://localhost:${port}/status`, {
|
|
78
|
-
signal: getTimeoutSignal(100),
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (response.ok) {
|
|
82
|
-
const body = await response.text();
|
|
83
|
-
|
|
84
|
-
if (body === 'packager-status:running') {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
} catch {
|
|
89
|
-
// Errors are expected here, we're just waiting for the process to be ready
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (attempts < maxRetries) {
|
|
93
|
-
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
throw new Error(`Metro bundler is not ready after ${maxRetries} attempts`);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export const reloadApp = async (): Promise<void> => {
|
|
101
|
-
await fetch(`http://localhost:${METRO_PORT}/reload`);
|
|
102
|
-
};
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConfigLoadError,
|
|
3
|
-
ConfigNotFoundError,
|
|
4
|
-
ConfigValidationError,
|
|
5
|
-
} from '@react-native-harness/config';
|
|
6
|
-
import { AssertionError } from '../utils.js';
|
|
7
|
-
import {
|
|
8
|
-
NoRunnerSpecifiedError,
|
|
9
|
-
RunnerNotFoundError,
|
|
10
|
-
EnvironmentInitializationError,
|
|
11
|
-
TestExecutionError,
|
|
12
|
-
RpcClientError,
|
|
13
|
-
AppNotInstalledError,
|
|
14
|
-
BridgeTimeoutError,
|
|
15
|
-
BundlingFailedError,
|
|
16
|
-
MetroPortUnavailableError,
|
|
17
|
-
} from './errors.js';
|
|
18
|
-
|
|
19
|
-
export const formatError = (error: unknown): string => {
|
|
20
|
-
const lines: string[] = [];
|
|
21
|
-
|
|
22
|
-
if (error instanceof AssertionError) {
|
|
23
|
-
lines.push(`\n❌ Assertion Error`);
|
|
24
|
-
lines.push(`\nError: ${error.message}`);
|
|
25
|
-
lines.push(`\nPlease check your configuration and try again.`);
|
|
26
|
-
} else if (error instanceof ConfigValidationError) {
|
|
27
|
-
lines.push(`\n❌ Configuration Error`);
|
|
28
|
-
lines.push(`\nFile: ${error.filePath}`);
|
|
29
|
-
lines.push(`\nValidation errors:`);
|
|
30
|
-
error.validationErrors.forEach((err) => {
|
|
31
|
-
lines.push(` • ${err}`);
|
|
32
|
-
});
|
|
33
|
-
lines.push(`\nPlease fix the configuration errors and try again.`);
|
|
34
|
-
} else if (error instanceof ConfigNotFoundError) {
|
|
35
|
-
lines.push(`\n❌ Configuration Not Found`);
|
|
36
|
-
lines.push(
|
|
37
|
-
`\nCould not find 'rn-harness.config' in '${error.searchPath}' or any parent directories.`
|
|
38
|
-
);
|
|
39
|
-
lines.push(`\nSupported file extensions: .js, .mjs, .cjs, .json`);
|
|
40
|
-
lines.push(
|
|
41
|
-
`\nPlease create a configuration file or run from a directory that contains one.`
|
|
42
|
-
);
|
|
43
|
-
} else if (error instanceof ConfigLoadError) {
|
|
44
|
-
lines.push(`\n❌ Configuration Load Error`);
|
|
45
|
-
lines.push(`\nFile: ${error.filePath}`);
|
|
46
|
-
lines.push(`Error: ${error.message}`);
|
|
47
|
-
if (error.cause) {
|
|
48
|
-
lines.push(`\nCause: ${error.cause.message}`);
|
|
49
|
-
}
|
|
50
|
-
lines.push(`\nPlease check your configuration file syntax and try again.`);
|
|
51
|
-
} else if (error instanceof NoRunnerSpecifiedError) {
|
|
52
|
-
lines.push('\n❌ No runner specified');
|
|
53
|
-
lines.push(
|
|
54
|
-
'\nPlease specify a runner name or set a defaultRunner in your config.'
|
|
55
|
-
);
|
|
56
|
-
lines.push('\nUsage: react-native-harness test [runner-name] [pattern]');
|
|
57
|
-
lines.push('\nAvailable runners:');
|
|
58
|
-
error.availableRunners.forEach((r) => {
|
|
59
|
-
lines.push(` • ${r.name} (${r.platform})`);
|
|
60
|
-
});
|
|
61
|
-
lines.push(
|
|
62
|
-
'\nTo set a default runner, add "defaultRunner" to your config:'
|
|
63
|
-
);
|
|
64
|
-
lines.push(' { "defaultRunner": "your-runner-name" }');
|
|
65
|
-
} else if (error instanceof RunnerNotFoundError) {
|
|
66
|
-
lines.push(`\n❌ Runner "${error.runnerName}" not found`);
|
|
67
|
-
lines.push('\nAvailable runners:');
|
|
68
|
-
error.availableRunners.forEach((r) => {
|
|
69
|
-
lines.push(` • ${r.name} (${r.platform})`);
|
|
70
|
-
});
|
|
71
|
-
lines.push('\nTo add a new runner, update your rn-harness.config file.');
|
|
72
|
-
} else if (error instanceof EnvironmentInitializationError) {
|
|
73
|
-
lines.push(`\n❌ Environment Initialization Error`);
|
|
74
|
-
lines.push(`\nRunner: ${error.runnerName} (${error.platform})`);
|
|
75
|
-
lines.push(`\nError: ${error.message}`);
|
|
76
|
-
if (error.details) {
|
|
77
|
-
lines.push(`\nDetails: ${error.details}`);
|
|
78
|
-
}
|
|
79
|
-
lines.push(`\nTroubleshooting steps:`);
|
|
80
|
-
lines.push(
|
|
81
|
-
` • Verify that ${error.platform} development environment is properly set up`
|
|
82
|
-
);
|
|
83
|
-
lines.push(` • Check that the app is built and ready for testing`);
|
|
84
|
-
lines.push(` • Ensure all required dependencies are installed`);
|
|
85
|
-
if (error.platform === 'ios') {
|
|
86
|
-
lines.push(` • Verify Xcode and iOS Simulator are working correctly`);
|
|
87
|
-
} else if (error.platform === 'android') {
|
|
88
|
-
lines.push(` • Verify Android SDK and emulator are working correctly`);
|
|
89
|
-
}
|
|
90
|
-
lines.push(`\nPlease check your environment configuration and try again.`);
|
|
91
|
-
} else if (error instanceof TestExecutionError) {
|
|
92
|
-
lines.push(`\n❌ Test Execution Error`);
|
|
93
|
-
lines.push(`\nFile: ${error.testFile}`);
|
|
94
|
-
if (error.testSuite) {
|
|
95
|
-
lines.push(`\nSuite: ${error.testSuite}`);
|
|
96
|
-
}
|
|
97
|
-
if (error.testName) {
|
|
98
|
-
lines.push(`\nTest: ${error.testName}`);
|
|
99
|
-
}
|
|
100
|
-
lines.push(`\nError: ${error.message}`);
|
|
101
|
-
lines.push(`\nTroubleshooting steps:`);
|
|
102
|
-
lines.push(` • Check the test file syntax and logic`);
|
|
103
|
-
lines.push(` • Verify all test dependencies are available`);
|
|
104
|
-
lines.push(` • Ensure the app is in the expected state for the test`);
|
|
105
|
-
lines.push(` • Check device/emulator logs for additional error details`);
|
|
106
|
-
lines.push(`\nPlease check your test file and try again.`);
|
|
107
|
-
} else if (error instanceof RpcClientError) {
|
|
108
|
-
lines.push(`\n❌ RPC Client Error`);
|
|
109
|
-
lines.push(`\nError: ${error.message}`);
|
|
110
|
-
if (error.bridgePort) {
|
|
111
|
-
lines.push(`\nBridge Port: ${error.bridgePort}`);
|
|
112
|
-
}
|
|
113
|
-
if (error.connectionStatus) {
|
|
114
|
-
lines.push(`\nConnection Status: ${error.connectionStatus}`);
|
|
115
|
-
}
|
|
116
|
-
lines.push(`\nTroubleshooting steps:`);
|
|
117
|
-
lines.push(` • Verify the React Native app is running and connected`);
|
|
118
|
-
lines.push(` • Check that the bridge port is not blocked by firewall`);
|
|
119
|
-
lines.push(
|
|
120
|
-
` • Ensure the app has the React Native Harness runtime integrated`
|
|
121
|
-
);
|
|
122
|
-
lines.push(` • Try restarting the app and test harness`);
|
|
123
|
-
lines.push(`\nPlease check your bridge connection and try again.`);
|
|
124
|
-
} else if (error instanceof AppNotInstalledError) {
|
|
125
|
-
lines.push(`\n❌ App Not Installed`);
|
|
126
|
-
const deviceType =
|
|
127
|
-
error.platform === 'ios'
|
|
128
|
-
? 'simulator'
|
|
129
|
-
: error.platform === 'android'
|
|
130
|
-
? 'emulator'
|
|
131
|
-
: 'virtual device';
|
|
132
|
-
lines.push(
|
|
133
|
-
`\nThe app "${error.bundleId}" is not installed on ${deviceType} "${error.deviceName}".`
|
|
134
|
-
);
|
|
135
|
-
lines.push(`\nTo resolve this issue:`);
|
|
136
|
-
if (error.platform === 'ios') {
|
|
137
|
-
lines.push(
|
|
138
|
-
` • Build and install the app: npx react-native run-ios --simulator="${error.deviceName}"`
|
|
139
|
-
);
|
|
140
|
-
lines.push(
|
|
141
|
-
` • Or install from Xcode: Open ios/*.xcworkspace and run the project`
|
|
142
|
-
);
|
|
143
|
-
} else if (error.platform === 'android') {
|
|
144
|
-
lines.push(` • Build and install the app: npx react-native run-android`);
|
|
145
|
-
lines.push(
|
|
146
|
-
` • Or build manually: ./gradlew assembleDebug && adb install android/app/build/outputs/apk/debug/app-debug.apk`
|
|
147
|
-
);
|
|
148
|
-
} else if (error.platform === 'vega') {
|
|
149
|
-
lines.push(` • Build the Vega app: npm run build:app`);
|
|
150
|
-
lines.push(
|
|
151
|
-
` • Install the app: kepler device install-app -p <path-to-vpkg> --device "${error.deviceName}"`
|
|
152
|
-
);
|
|
153
|
-
lines.push(
|
|
154
|
-
` • Or use the combined command: kepler run-kepler <path-to-vpkg> "${error.bundleId}" -d "${error.deviceName}"`
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
lines.push(`\nPlease install the app and try running the tests again.`);
|
|
158
|
-
} else if (error instanceof BundlingFailedError) {
|
|
159
|
-
lines.push(`\n❌ Test File Bundling Error`);
|
|
160
|
-
lines.push(`\nFile: ${error.modulePath}`);
|
|
161
|
-
lines.push(`\nError: ${error.reason}`);
|
|
162
|
-
lines.push(`\nTroubleshooting steps:`);
|
|
163
|
-
lines.push(` • Check the test file syntax and imports`);
|
|
164
|
-
lines.push(` • Verify all imported modules exist and are accessible`);
|
|
165
|
-
lines.push(` • Ensure the Metro bundler configuration is correct`);
|
|
166
|
-
lines.push(` • Check for any circular dependencies in the test file`);
|
|
167
|
-
lines.push(` • Verify that all required packages are installed`);
|
|
168
|
-
lines.push(`\nPlease fix the bundling issues and try again.`);
|
|
169
|
-
} else if (error instanceof BridgeTimeoutError) {
|
|
170
|
-
lines.push(`\n❌ Bridge Connection Timeout`);
|
|
171
|
-
lines.push(
|
|
172
|
-
`\nThe bridge connection timed out after ${error.timeout}ms while waiting for the "${error.runnerName}" (${error.platform}) runner to be ready.`
|
|
173
|
-
);
|
|
174
|
-
lines.push(`\nThis usually indicates that:`);
|
|
175
|
-
lines.push(
|
|
176
|
-
` • The React Native app failed to load or connect to the bridge`
|
|
177
|
-
);
|
|
178
|
-
lines.push(` • The app crashed during startup`);
|
|
179
|
-
lines.push(
|
|
180
|
-
` • Network connectivity issues between the app and the test harness`
|
|
181
|
-
);
|
|
182
|
-
lines.push(` • The app is taking longer than expected to initialize`);
|
|
183
|
-
lines.push(`\nTo resolve this issue:`);
|
|
184
|
-
lines.push(
|
|
185
|
-
` • Check that the app is properly installed and can start normally`
|
|
186
|
-
);
|
|
187
|
-
lines.push(
|
|
188
|
-
` • Verify that the app has the React Native Harness runtime integrated`
|
|
189
|
-
);
|
|
190
|
-
lines.push(` • Check device/emulator logs for any startup errors`);
|
|
191
|
-
lines.push(` • Ensure the test harness bridge port (3001) is not blocked`);
|
|
192
|
-
lines.push(
|
|
193
|
-
`\nIf the app needs more time to start, consider increasing the timeout in the configuration.`
|
|
194
|
-
);
|
|
195
|
-
} else if (error instanceof MetroPortUnavailableError) {
|
|
196
|
-
lines.push(`\n❌ Metro Port Unavailable`);
|
|
197
|
-
lines.push(`\nPort ${error.port} is already in use or unavailable.`);
|
|
198
|
-
lines.push(`\nThis usually indicates that:`);
|
|
199
|
-
lines.push(` • Another Metro bundler instance is already running`);
|
|
200
|
-
lines.push(` • Another application is using port ${error.port}`);
|
|
201
|
-
lines.push(` • The port is blocked by a firewall or security software`);
|
|
202
|
-
lines.push(`\nTo resolve this issue:`);
|
|
203
|
-
lines.push(` • Stop any running Metro bundler instances`);
|
|
204
|
-
lines.push(
|
|
205
|
-
` • Check for other applications using port ${error.port}: lsof -i :${error.port}`
|
|
206
|
-
);
|
|
207
|
-
lines.push(` • Kill the process using the port: kill -9 <PID>`);
|
|
208
|
-
lines.push(
|
|
209
|
-
` • Or use a different port by updating your Metro configuration`
|
|
210
|
-
);
|
|
211
|
-
lines.push(`\nPlease free up the port and try again.`);
|
|
212
|
-
} else {
|
|
213
|
-
// Re-throw the error to be handled by the caller
|
|
214
|
-
throw error;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return lines.join('');
|
|
218
|
-
};
|
package/src/errors/errors.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { TestRunnerConfig } from '@react-native-harness/config';
|
|
2
|
-
|
|
3
|
-
export class NoRunnerSpecifiedError extends Error {
|
|
4
|
-
constructor(availableRunners: TestRunnerConfig[]) {
|
|
5
|
-
super('No runner specified');
|
|
6
|
-
this.name = 'NoRunnerSpecifiedError';
|
|
7
|
-
this.availableRunners = availableRunners;
|
|
8
|
-
}
|
|
9
|
-
availableRunners: TestRunnerConfig[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class RunnerNotFoundError extends Error {
|
|
13
|
-
constructor(runnerName: string, availableRunners: TestRunnerConfig[]) {
|
|
14
|
-
super(`Runner "${runnerName}" not found`);
|
|
15
|
-
this.name = 'RunnerNotFoundError';
|
|
16
|
-
this.runnerName = runnerName;
|
|
17
|
-
this.availableRunners = availableRunners;
|
|
18
|
-
}
|
|
19
|
-
runnerName: string;
|
|
20
|
-
availableRunners: TestRunnerConfig[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class EnvironmentInitializationError extends Error {
|
|
24
|
-
constructor(
|
|
25
|
-
message: string,
|
|
26
|
-
runnerName: string,
|
|
27
|
-
platform: string,
|
|
28
|
-
details?: string
|
|
29
|
-
) {
|
|
30
|
-
super(
|
|
31
|
-
`Failed to initialize environment for "${runnerName}" (${platform}): ${message}`
|
|
32
|
-
);
|
|
33
|
-
this.name = 'EnvironmentInitializationError';
|
|
34
|
-
this.runnerName = runnerName;
|
|
35
|
-
this.platform = platform;
|
|
36
|
-
this.details = details;
|
|
37
|
-
}
|
|
38
|
-
runnerName: string;
|
|
39
|
-
platform: string;
|
|
40
|
-
details?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export class TestExecutionError extends Error {
|
|
44
|
-
constructor(
|
|
45
|
-
testFile: string,
|
|
46
|
-
error: unknown,
|
|
47
|
-
testSuite?: string,
|
|
48
|
-
testName?: string
|
|
49
|
-
) {
|
|
50
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
51
|
-
const suiteInfo = testSuite ? ` in suite "${testSuite}"` : '';
|
|
52
|
-
const testInfo = testName ? ` test "${testName}"` : '';
|
|
53
|
-
|
|
54
|
-
super(
|
|
55
|
-
`Test execution failed for ${testFile}${suiteInfo}${testInfo}: ${errorMessage}`
|
|
56
|
-
);
|
|
57
|
-
this.name = 'TestExecutionError';
|
|
58
|
-
this.testFile = testFile;
|
|
59
|
-
this.testSuite = testSuite;
|
|
60
|
-
this.testName = testName;
|
|
61
|
-
this.originalError = error;
|
|
62
|
-
}
|
|
63
|
-
testFile: string;
|
|
64
|
-
testSuite?: string;
|
|
65
|
-
testName?: string;
|
|
66
|
-
originalError: unknown;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export class RpcClientError extends Error {
|
|
70
|
-
constructor(message: string, bridgePort?: number, connectionStatus?: string) {
|
|
71
|
-
const portInfo = bridgePort ? ` (port ${bridgePort})` : '';
|
|
72
|
-
const statusInfo = connectionStatus ? ` - Status: ${connectionStatus}` : '';
|
|
73
|
-
|
|
74
|
-
super(`RPC client error${portInfo}: ${message}${statusInfo}`);
|
|
75
|
-
this.name = 'RpcClientError';
|
|
76
|
-
this.bridgePort = bridgePort;
|
|
77
|
-
this.connectionStatus = connectionStatus;
|
|
78
|
-
}
|
|
79
|
-
bridgePort?: number;
|
|
80
|
-
connectionStatus?: string;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export class BridgeTimeoutError extends Error {
|
|
84
|
-
constructor(
|
|
85
|
-
public readonly timeout: number,
|
|
86
|
-
public readonly runnerName: string,
|
|
87
|
-
public readonly platform: string
|
|
88
|
-
) {
|
|
89
|
-
super(
|
|
90
|
-
`Bridge connection timed out after ${timeout}ms while waiting for "${runnerName}" (${platform}) runner to be ready`
|
|
91
|
-
);
|
|
92
|
-
this.name = 'BridgeTimeoutError';
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export class AppNotInstalledError extends Error {
|
|
97
|
-
constructor(
|
|
98
|
-
public readonly deviceName: string,
|
|
99
|
-
public readonly bundleId: string,
|
|
100
|
-
public readonly platform: 'ios' | 'android' | 'vega'
|
|
101
|
-
) {
|
|
102
|
-
const deviceType =
|
|
103
|
-
platform === 'ios'
|
|
104
|
-
? 'simulator'
|
|
105
|
-
: platform === 'android'
|
|
106
|
-
? 'emulator'
|
|
107
|
-
: 'virtual device';
|
|
108
|
-
|
|
109
|
-
super(
|
|
110
|
-
`App "${bundleId}" is not installed on ${deviceType} "${deviceName}"`
|
|
111
|
-
);
|
|
112
|
-
this.name = 'AppNotInstalledError';
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export class BundlingFailedError extends Error {
|
|
117
|
-
constructor(
|
|
118
|
-
public readonly modulePath: string,
|
|
119
|
-
public readonly reason: string
|
|
120
|
-
) {
|
|
121
|
-
super(`Bundling of ${modulePath} failed: ${reason}`);
|
|
122
|
-
this.name = 'BundlingFailedError';
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export class MetroPortUnavailableError extends Error {
|
|
127
|
-
constructor(public readonly port: number) {
|
|
128
|
-
super(`Metro port ${port} is not available`);
|
|
129
|
-
this.name = 'MetroPortUnavailableError';
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { spawn } from '@react-native-harness/tools';
|
|
3
|
-
|
|
4
|
-
export const buildAndroidApp = async (): Promise<void> => {
|
|
5
|
-
await spawn('react-native', ['build-android', '--tasks', 'assembleDebug']);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const installApp = async (deviceId: string): Promise<void> => {
|
|
9
|
-
await spawn('adb', [
|
|
10
|
-
'-s',
|
|
11
|
-
deviceId,
|
|
12
|
-
'install',
|
|
13
|
-
'-r',
|
|
14
|
-
path.join(
|
|
15
|
-
process.cwd(),
|
|
16
|
-
'android',
|
|
17
|
-
'app',
|
|
18
|
-
'build',
|
|
19
|
-
'outputs',
|
|
20
|
-
'apk',
|
|
21
|
-
'debug',
|
|
22
|
-
'app-debug.apk'
|
|
23
|
-
),
|
|
24
|
-
]);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const killApp = async (
|
|
28
|
-
deviceId: string,
|
|
29
|
-
bundleId: string
|
|
30
|
-
): Promise<void> => {
|
|
31
|
-
await spawn('adb', ['-s', deviceId, 'shell', 'am', 'force-stop', bundleId]);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const runApp = async (
|
|
35
|
-
deviceId: string,
|
|
36
|
-
bundleId: string,
|
|
37
|
-
activityName: string
|
|
38
|
-
): Promise<void> => {
|
|
39
|
-
await killApp(deviceId, bundleId);
|
|
40
|
-
await spawn('adb', [
|
|
41
|
-
'-s',
|
|
42
|
-
deviceId,
|
|
43
|
-
'shell',
|
|
44
|
-
'am',
|
|
45
|
-
'start',
|
|
46
|
-
'-n',
|
|
47
|
-
`${bundleId}/${activityName}`,
|
|
48
|
-
]);
|
|
49
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { spawn } from '@react-native-harness/tools';
|
|
2
|
-
|
|
3
|
-
export const killApp = async (
|
|
4
|
-
deviceId: string,
|
|
5
|
-
bundleId: string
|
|
6
|
-
): Promise<void> => {
|
|
7
|
-
await spawn('adb', ['-s', deviceId, 'shell', 'am', 'force-stop', bundleId]);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const runApp = async (
|
|
11
|
-
deviceId: string,
|
|
12
|
-
bundleId: string
|
|
13
|
-
): Promise<void> => {
|
|
14
|
-
await killApp(deviceId, bundleId);
|
|
15
|
-
await spawn('adb', [
|
|
16
|
-
'-s',
|
|
17
|
-
deviceId,
|
|
18
|
-
'shell',
|
|
19
|
-
'am',
|
|
20
|
-
'start',
|
|
21
|
-
'-n',
|
|
22
|
-
`${bundleId}/.MainActivity`,
|
|
23
|
-
]);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const isAppInstalled = async (
|
|
27
|
-
deviceId: string,
|
|
28
|
-
bundleId: string
|
|
29
|
-
): Promise<boolean> => {
|
|
30
|
-
try {
|
|
31
|
-
const { stdout } = await spawn('adb', [
|
|
32
|
-
'-s',
|
|
33
|
-
deviceId,
|
|
34
|
-
'shell',
|
|
35
|
-
'pm',
|
|
36
|
-
'list',
|
|
37
|
-
'packages',
|
|
38
|
-
bundleId,
|
|
39
|
-
]);
|
|
40
|
-
return stdout.trim() !== '';
|
|
41
|
-
} catch {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const reversePort = async (port: number): Promise<void> => {
|
|
47
|
-
await spawn('adb', ['reverse', `tcp:${port}`, `tcp:${port}`]);
|
|
48
|
-
};
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { spawn } from '@react-native-harness/tools';
|
|
2
|
-
import { ChildProcess } from 'node:child_process';
|
|
3
|
-
|
|
4
|
-
export type AndroidEmulatorStatus = 'running' | 'loading' | 'stopped';
|
|
5
|
-
|
|
6
|
-
export const getEmulatorNameFromId = async (
|
|
7
|
-
emulatorId: string
|
|
8
|
-
): Promise<string | null> => {
|
|
9
|
-
try {
|
|
10
|
-
const { stdout } = await spawn('adb', [
|
|
11
|
-
'-s',
|
|
12
|
-
emulatorId,
|
|
13
|
-
'emu',
|
|
14
|
-
'avd',
|
|
15
|
-
'name',
|
|
16
|
-
]);
|
|
17
|
-
const avdName = stdout.split('\n')[0].trim();
|
|
18
|
-
return avdName || null;
|
|
19
|
-
} catch {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const getEmulatorDeviceId = async (
|
|
25
|
-
avdName: string
|
|
26
|
-
): Promise<string | null> => {
|
|
27
|
-
try {
|
|
28
|
-
const { stdout } = await spawn('adb', ['devices']);
|
|
29
|
-
const lines = stdout.split('\n');
|
|
30
|
-
|
|
31
|
-
for (const line of lines) {
|
|
32
|
-
const parts = line.trim().split('\t');
|
|
33
|
-
if (parts.length === 2 && parts[0].startsWith('emulator-')) {
|
|
34
|
-
const emulatorId = parts[0].trim();
|
|
35
|
-
const name = await getEmulatorNameFromId(emulatorId);
|
|
36
|
-
if (name === avdName) {
|
|
37
|
-
return emulatorId;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
} catch {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const getEmulatorStatus = async (
|
|
48
|
-
avdName: string
|
|
49
|
-
): Promise<AndroidEmulatorStatus> => {
|
|
50
|
-
const emulatorId = await getEmulatorDeviceId(avdName);
|
|
51
|
-
if (!emulatorId) {
|
|
52
|
-
return 'stopped';
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
// Check if device is fully booted by checking boot completion
|
|
57
|
-
const { stdout } = await spawn('adb', [
|
|
58
|
-
'-s',
|
|
59
|
-
emulatorId,
|
|
60
|
-
'shell',
|
|
61
|
-
'getprop',
|
|
62
|
-
'sys.boot_completed',
|
|
63
|
-
]);
|
|
64
|
-
const bootCompleted = stdout.trim() === '1';
|
|
65
|
-
return bootCompleted ? 'running' : 'loading';
|
|
66
|
-
} catch {
|
|
67
|
-
return 'loading';
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const runEmulator = async (name: string): Promise<ChildProcess> => {
|
|
72
|
-
// Start the emulator
|
|
73
|
-
const process = spawn('emulator', ['-avd', name]);
|
|
74
|
-
const nodeChildProcess = await process.nodeChildProcess;
|
|
75
|
-
|
|
76
|
-
// Poll for emulator status until it's fully running
|
|
77
|
-
const checkStatus = async (): Promise<void> => {
|
|
78
|
-
const status = await getEmulatorStatus(name);
|
|
79
|
-
|
|
80
|
-
if (status === 'running') {
|
|
81
|
-
return;
|
|
82
|
-
} else if (status === 'loading') {
|
|
83
|
-
// Check again in 2 seconds
|
|
84
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
85
|
-
await checkStatus();
|
|
86
|
-
} else {
|
|
87
|
-
// Still stopped, check again in 1 second
|
|
88
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
89
|
-
await checkStatus();
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// Start checking status after a brief delay to allow emulator to start
|
|
94
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
95
|
-
await checkStatus();
|
|
96
|
-
|
|
97
|
-
return nodeChildProcess;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export const stopEmulator = async (avdName: string): Promise<void> => {
|
|
101
|
-
// First, get the emulator device ID
|
|
102
|
-
const emulatorId = await getEmulatorDeviceId(avdName);
|
|
103
|
-
if (!emulatorId) {
|
|
104
|
-
return; // No emulator running, nothing to stop
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
await stopEmulatorById(emulatorId);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const stopEmulatorById = async (emulatorId: string): Promise<void> => {
|
|
111
|
-
// Stop the emulator using the found ID
|
|
112
|
-
await spawn('adb', ['-s', emulatorId, 'emu', 'kill']);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export const isAppInstalled = async (
|
|
116
|
-
emulatorId: string,
|
|
117
|
-
bundleId: string
|
|
118
|
-
): Promise<boolean> => {
|
|
119
|
-
try {
|
|
120
|
-
const { stdout } = await spawn('adb', [
|
|
121
|
-
'-s',
|
|
122
|
-
emulatorId,
|
|
123
|
-
'shell',
|
|
124
|
-
'pm',
|
|
125
|
-
'list',
|
|
126
|
-
'packages',
|
|
127
|
-
bundleId,
|
|
128
|
-
]);
|
|
129
|
-
return stdout.trim() !== '';
|
|
130
|
-
} catch {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const reversePort = async (port: number): Promise<void> => {
|
|
136
|
-
await spawn('adb', ['reverse', `tcp:${port}`, `tcp:${port}`]);
|
|
137
|
-
};
|