@react-native-harness/cli 1.0.0-alpha.9 → 1.0.0-canary.1761046904277

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.
Files changed (72) hide show
  1. package/README.md +23 -4
  2. package/dist/bundlers/metro.d.ts.map +1 -1
  3. package/dist/bundlers/metro.js +15 -5
  4. package/dist/commands/test.d.ts +2 -1
  5. package/dist/commands/test.d.ts.map +1 -1
  6. package/dist/commands/test.js +23 -19
  7. package/dist/discovery/index.d.ts +3 -0
  8. package/dist/discovery/index.d.ts.map +1 -0
  9. package/dist/discovery/index.js +1 -0
  10. package/dist/discovery/testDiscovery.d.ts +11 -0
  11. package/dist/discovery/testDiscovery.d.ts.map +1 -0
  12. package/dist/discovery/testDiscovery.js +29 -0
  13. package/dist/errors/errorHandler.d.ts.map +1 -1
  14. package/dist/errors/errorHandler.js +27 -3
  15. package/dist/errors/errors.d.ts +6 -2
  16. package/dist/errors/errors.d.ts.map +1 -1
  17. package/dist/errors/errors.js +14 -1
  18. package/dist/external.d.ts +9 -0
  19. package/dist/external.d.ts.map +1 -0
  20. package/dist/external.js +25 -0
  21. package/dist/index.js +20 -4
  22. package/dist/platforms/android/emulator.d.ts +0 -1
  23. package/dist/platforms/android/emulator.d.ts.map +1 -1
  24. package/dist/platforms/android/emulator.js +26 -20
  25. package/dist/platforms/android/index.js +1 -1
  26. package/dist/platforms/ios/build.d.ts.map +1 -1
  27. package/dist/platforms/ios/build.js +5 -1
  28. package/dist/platforms/ios/device.d.ts +6 -2
  29. package/dist/platforms/ios/device.d.ts.map +1 -1
  30. package/dist/platforms/ios/simulator.d.ts.map +1 -1
  31. package/dist/platforms/ios/simulator.js +8 -3
  32. package/dist/platforms/platform-registry.d.ts.map +1 -1
  33. package/dist/platforms/platform-registry.js +3 -1
  34. package/dist/platforms/vega/build.d.ts +23 -0
  35. package/dist/platforms/vega/build.d.ts.map +1 -0
  36. package/dist/platforms/vega/build.js +55 -0
  37. package/dist/platforms/vega/device.d.ts +57 -0
  38. package/dist/platforms/vega/device.d.ts.map +1 -0
  39. package/dist/platforms/vega/device.js +206 -0
  40. package/dist/platforms/vega/index.d.ts +4 -0
  41. package/dist/platforms/vega/index.d.ts.map +1 -0
  42. package/dist/platforms/vega/index.js +75 -0
  43. package/dist/process.js +1 -1
  44. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  45. package/dist/utils/status-formatter.d.ts +27 -0
  46. package/dist/utils/status-formatter.d.ts.map +1 -0
  47. package/dist/utils/status-formatter.js +54 -0
  48. package/dist/utils.d.ts +1 -0
  49. package/dist/utils.d.ts.map +1 -1
  50. package/dist/utils.js +15 -0
  51. package/eslint.config.mjs +1 -0
  52. package/package.json +21 -6
  53. package/src/bundlers/metro.ts +17 -4
  54. package/src/commands/test.ts +39 -25
  55. package/src/discovery/index.ts +2 -0
  56. package/src/discovery/testDiscovery.ts +50 -0
  57. package/src/errors/errorHandler.ts +34 -4
  58. package/src/errors/errors.ts +16 -4
  59. package/src/external.ts +44 -0
  60. package/src/index.ts +33 -5
  61. package/src/platforms/android/emulator.ts +26 -28
  62. package/src/platforms/android/index.ts +1 -1
  63. package/src/platforms/ios/build.ts +3 -0
  64. package/src/platforms/ios/device.ts +5 -2
  65. package/src/platforms/ios/simulator.ts +8 -3
  66. package/src/platforms/platform-registry.ts +3 -1
  67. package/src/platforms/vega/build.ts +85 -0
  68. package/src/platforms/vega/device.ts +258 -0
  69. package/src/platforms/vega/index.ts +107 -0
  70. package/src/process.ts +1 -1
  71. package/src/utils.ts +17 -0
  72. package/tsconfig.json +3 -0
@@ -0,0 +1,258 @@
1
+ import { spawn } from '@react-native-harness/tools';
2
+
3
+ export type VegaVirtualDeviceStatus = 'running' | 'stopped';
4
+
5
+ /**
6
+ * List all available Vega virtual devices
7
+ * Returns array of device identifiers that can be used with kepler commands
8
+ */
9
+ export const listVegaDevices = async (): Promise<string[]> => {
10
+ try {
11
+ const { stdout } = await spawn('kepler', ['device', 'list']);
12
+ const lines = stdout.trim().split('\n');
13
+ const devices: string[] = [];
14
+
15
+ for (const line of lines) {
16
+ if (line.trim()) {
17
+ // Parse device line format: "VirtualDevice : tv - x86_64 - OS - hostname"
18
+ // or potentially "VegaTV_1 : tv - x86_64 - OS - hostname" for named instances
19
+ const deviceId = line.split(' : ')[0].trim();
20
+ if (
21
+ deviceId &&
22
+ (deviceId === 'VirtualDevice' || deviceId.startsWith('Vega'))
23
+ ) {
24
+ devices.push(deviceId);
25
+ }
26
+ }
27
+ }
28
+
29
+ return devices;
30
+ } catch {
31
+ return [];
32
+ }
33
+ };
34
+
35
+ /**
36
+ * Check if a specific Vega virtual device is connected/available
37
+ */
38
+ export const isVegaDeviceConnected = async (
39
+ deviceId: string
40
+ ): Promise<boolean> => {
41
+ try {
42
+ const { stdout } = await spawn('kepler', [
43
+ 'device',
44
+ 'is-connected',
45
+ '--device',
46
+ deviceId,
47
+ ]);
48
+ return stdout.includes('is connected');
49
+ } catch {
50
+ return false;
51
+ }
52
+ };
53
+
54
+ /**
55
+ * Check if an app is installed on the specified Vega virtual device
56
+ */
57
+ export const isAppInstalled = async (
58
+ deviceId: string,
59
+ bundleId: string
60
+ ): Promise<boolean> => {
61
+ try {
62
+ await spawn('kepler', [
63
+ 'device',
64
+ 'is-app-installed',
65
+ '--device',
66
+ deviceId,
67
+ '--appName',
68
+ bundleId,
69
+ ]);
70
+ return true;
71
+ } catch {
72
+ return false;
73
+ }
74
+ };
75
+
76
+ /**
77
+ * Check if an app is currently running on the specified Vega virtual device
78
+ */
79
+ export const isAppRunning = async (
80
+ deviceId: string,
81
+ bundleId: string
82
+ ): Promise<boolean> => {
83
+ try {
84
+ await spawn('kepler', [
85
+ 'device',
86
+ 'is-app-running',
87
+ '--device',
88
+ deviceId,
89
+ '--appName',
90
+ bundleId,
91
+ ]);
92
+ return true;
93
+ } catch {
94
+ return false;
95
+ }
96
+ };
97
+
98
+ /**
99
+ * Install app on specified Vega virtual device using .vpkg file
100
+ */
101
+ export const installApp = async (
102
+ deviceId: string,
103
+ vpkgPath: string
104
+ ): Promise<void> => {
105
+ await spawn('kepler', [
106
+ 'device',
107
+ 'install-app',
108
+ '-p',
109
+ vpkgPath,
110
+ '--device',
111
+ deviceId,
112
+ ]);
113
+ };
114
+
115
+ /**
116
+ * Terminate app on specified Vega virtual device
117
+ */
118
+ export const terminateApp = async (
119
+ deviceId: string,
120
+ bundleId: string
121
+ ): Promise<void> => {
122
+ await spawn('kepler', [
123
+ 'device',
124
+ 'terminate-app',
125
+ '--device',
126
+ deviceId,
127
+ '--appName',
128
+ bundleId,
129
+ ]);
130
+ };
131
+
132
+ /**
133
+ * Uninstall app from specified Vega virtual device
134
+ */
135
+ export const uninstallApp = async (
136
+ deviceId: string,
137
+ bundleId: string
138
+ ): Promise<void> => {
139
+ await spawn('kepler', [
140
+ 'device',
141
+ 'uninstall-app',
142
+ '--device',
143
+ deviceId,
144
+ '--appName',
145
+ bundleId,
146
+ ]);
147
+ };
148
+
149
+ /**
150
+ * Start port forwarding for debugging on specified Vega virtual device
151
+ */
152
+ export const startPortForwarding = async (
153
+ deviceId: string,
154
+ port: number,
155
+ forward = true
156
+ ): Promise<void> => {
157
+ await spawn('kepler', [
158
+ 'device',
159
+ 'start-port-forwarding',
160
+ '--device',
161
+ deviceId,
162
+ '--port',
163
+ port.toString(),
164
+ '--forward',
165
+ forward.toString(),
166
+ ]);
167
+ };
168
+
169
+ /**
170
+ * Stop port forwarding on specified Vega virtual device
171
+ */
172
+ export const stopPortForwarding = async (
173
+ deviceId: string,
174
+ port: number,
175
+ forward = true
176
+ ): Promise<void> => {
177
+ await spawn('kepler', [
178
+ 'device',
179
+ 'stop-port-forwarding',
180
+ '--device',
181
+ deviceId,
182
+ '--port',
183
+ port.toString(),
184
+ '--forward',
185
+ forward.toString(),
186
+ ]);
187
+ };
188
+
189
+ /**
190
+ * Get status of a specific Vega virtual device
191
+ * Note: Vega CLI might manage virtual devices globally, so this checks if the device is available
192
+ */
193
+ export const getVegaDeviceStatus = async (
194
+ deviceId: string
195
+ ): Promise<VegaVirtualDeviceStatus> => {
196
+ try {
197
+ // First check if the device is connected/available
198
+ const isConnected = await isVegaDeviceConnected(deviceId);
199
+ if (isConnected) {
200
+ return 'running';
201
+ }
202
+
203
+ // Check general virtual device status
204
+ const { stdout } = await spawn('kepler', ['virtual-device', 'status']);
205
+ // Parse the status output to determine if VVD is running
206
+ return stdout.toLowerCase().includes('running') ||
207
+ stdout.toLowerCase().includes('ready')
208
+ ? 'running'
209
+ : 'stopped';
210
+ } catch {
211
+ return 'stopped';
212
+ }
213
+ };
214
+
215
+ /**
216
+ * Start Vega Virtual Device
217
+ * Note: Vega might manage virtual devices globally, this starts the virtual device system
218
+ */
219
+ export const startVirtualDevice = async (): Promise<void> => {
220
+ await spawn('kepler', ['virtual-device', 'start']);
221
+
222
+ // Poll for VVD status until it's running
223
+ let attempts = 0;
224
+ const maxAttempts = 30; // 30 seconds timeout
225
+
226
+ while (attempts < maxAttempts) {
227
+ const { stdout } = await spawn('kepler', ['virtual-device', 'status']);
228
+ if (
229
+ stdout.toLowerCase().includes('running') ||
230
+ stdout.toLowerCase().includes('ready')
231
+ ) {
232
+ return;
233
+ }
234
+
235
+ await new Promise((resolve) => setTimeout(resolve, 1000));
236
+ attempts++;
237
+ }
238
+
239
+ throw new Error('Vega Virtual Device failed to start within timeout');
240
+ };
241
+
242
+ /**
243
+ * Stop Vega Virtual Device
244
+ */
245
+ export const stopVirtualDevice = async (): Promise<void> => {
246
+ await spawn('kepler', ['virtual-device', 'stop']);
247
+ };
248
+
249
+ /**
250
+ * Combined install and run command for specified Vega virtual device (Vega-specific convenience method)
251
+ */
252
+ export const runKepler = async (
253
+ deviceId: string,
254
+ vpkgPath: string,
255
+ bundleId: string
256
+ ): Promise<void> => {
257
+ await spawn('kepler', ['run-kepler', vpkgPath, bundleId, '-d', deviceId]);
258
+ };
@@ -0,0 +1,107 @@
1
+ import {
2
+ assertVegaRunnerConfig,
3
+ TestRunnerConfig,
4
+ } from '@react-native-harness/config';
5
+ import { logger } from '@react-native-harness/tools';
6
+
7
+ import { type PlatformAdapter } from '../platform-adapter.js';
8
+ import {
9
+ isAppInstalled,
10
+ getVegaDeviceStatus,
11
+ isVegaDeviceConnected,
12
+ startVirtualDevice,
13
+ stopVirtualDevice,
14
+ startPortForwarding,
15
+ stopPortForwarding,
16
+ } from './device.js';
17
+ import { runApp, killApp } from './build.js';
18
+ import { killWithAwait } from '../../process.js';
19
+ import { runMetro } from '../../bundlers/metro.js';
20
+ import { AppNotInstalledError } from '../../errors/errors.js';
21
+
22
+ const vegaPlatformAdapter: PlatformAdapter = {
23
+ name: 'vega',
24
+ getEnvironment: async (runner: TestRunnerConfig) => {
25
+ assertVegaRunnerConfig(runner);
26
+
27
+ let shouldStopVirtualDevice = false;
28
+
29
+ // Check if the specific Vega device is available
30
+ const deviceStatus = await getVegaDeviceStatus(runner.deviceId);
31
+ logger.debug(`Vega device ${runner.deviceId} status: ${deviceStatus}`);
32
+
33
+ if (deviceStatus === 'stopped') {
34
+ logger.debug('Starting Vega Virtual Device system');
35
+ await startVirtualDevice();
36
+ shouldStopVirtualDevice = true;
37
+
38
+ // Wait a bit for the device to become available
39
+ await new Promise((resolve) => setTimeout(resolve, 2000));
40
+ }
41
+
42
+ // Verify device is now connected
43
+ const isConnected = await isVegaDeviceConnected(runner.deviceId);
44
+ if (!isConnected) {
45
+ throw new Error(
46
+ `Vega device ${runner.deviceId} is not available. Make sure the virtual device is configured and running.`
47
+ );
48
+ }
49
+
50
+ // Start Metro bundler
51
+ const metroPromise = runMetro();
52
+
53
+ // Set up port forwarding for debugging (similar to Android)
54
+ await Promise.all([
55
+ startPortForwarding(runner.deviceId, 8081, false), // reverse port forwarding for JS debugging
56
+ startPortForwarding(runner.deviceId, 8080, false),
57
+ startPortForwarding(runner.deviceId, 3001, false),
58
+ ]);
59
+ logger.debug('Port forwarding established');
60
+
61
+ // Check if app is installed
62
+ const isInstalled = await isAppInstalled(runner.deviceId, runner.bundleId);
63
+ logger.debug(`App is installed: ${isInstalled}`);
64
+
65
+ if (!isInstalled) {
66
+ throw new AppNotInstalledError(runner.deviceId, runner.bundleId, 'vega');
67
+ }
68
+
69
+ logger.debug('Waiting for Metro to start');
70
+ const metro = await metroPromise;
71
+ logger.debug('Metro started');
72
+
73
+ logger.debug('Running Vega app');
74
+ await runApp(runner.deviceId, runner.bundleId);
75
+ logger.debug('Vega app running');
76
+
77
+ return {
78
+ restart: async () => {
79
+ await runApp(runner.deviceId, runner.bundleId);
80
+ },
81
+ dispose: async () => {
82
+ // Kill the app
83
+ await killApp(runner.deviceId, runner.bundleId);
84
+
85
+ // Stop port forwarding
86
+ await Promise.all([
87
+ stopPortForwarding(runner.deviceId, 8081, false),
88
+ stopPortForwarding(runner.deviceId, 8080, false),
89
+ stopPortForwarding(runner.deviceId, 3001, false),
90
+ ]).catch((error) => {
91
+ // Don't fail disposal if port forwarding cleanup fails
92
+ logger.debug(`Port forwarding cleanup failed: ${error.message}`);
93
+ });
94
+
95
+ // Stop Virtual Device if we started it
96
+ if (shouldStopVirtualDevice) {
97
+ await stopVirtualDevice();
98
+ }
99
+
100
+ // Kill Metro
101
+ await killWithAwait(metro);
102
+ },
103
+ };
104
+ },
105
+ };
106
+
107
+ export default vegaPlatformAdapter;
package/src/process.ts CHANGED
@@ -25,7 +25,7 @@ export const killWithAwait = (child: ChildProcess): Promise<void> => {
25
25
 
26
26
  try {
27
27
  child.kill();
28
- } catch (error) {
28
+ } catch {
29
29
  clearTimeout(timeout);
30
30
  resolve();
31
31
  }
package/src/utils.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import net from 'node:net';
2
+
1
3
  export function assert(condition: boolean, message: string): asserts condition {
2
4
  if (!condition) {
3
5
  throw new AssertionError(message);
@@ -10,3 +12,18 @@ export class AssertionError extends Error {
10
12
  this.name = 'AssertionError';
11
13
  }
12
14
  }
15
+
16
+ export const isPortAvailable = (port: number): Promise<boolean> => {
17
+ return new Promise((resolve) => {
18
+ const server = net.createServer();
19
+ server.once('error', () => {
20
+ server.close();
21
+ resolve(false);
22
+ });
23
+ server.once('listening', () => {
24
+ server.close();
25
+ resolve(true);
26
+ });
27
+ server.listen(port);
28
+ });
29
+ };
package/tsconfig.json CHANGED
@@ -3,6 +3,9 @@
3
3
  "files": [],
4
4
  "include": [],
5
5
  "references": [
6
+ {
7
+ "path": "../tools"
8
+ },
6
9
  {
7
10
  "path": "../config"
8
11
  },