@react-native-harness/cli 1.0.0-alpha.10 → 1.0.0-alpha.12

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 (47) hide show
  1. package/README.md +23 -4
  2. package/dist/bundlers/metro.d.ts.map +1 -1
  3. package/dist/bundlers/metro.js +8 -4
  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 +19 -17
  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 +12 -2
  15. package/dist/errors/errors.d.ts +2 -2
  16. package/dist/errors/errors.d.ts.map +1 -1
  17. package/dist/errors/errors.js +6 -1
  18. package/dist/index.js +20 -4
  19. package/dist/platforms/android/index.js +1 -1
  20. package/dist/platforms/platform-registry.d.ts.map +1 -1
  21. package/dist/platforms/platform-registry.js +2 -0
  22. package/dist/platforms/vega/build.d.ts +23 -0
  23. package/dist/platforms/vega/build.d.ts.map +1 -0
  24. package/dist/platforms/vega/build.js +55 -0
  25. package/dist/platforms/vega/device.d.ts +57 -0
  26. package/dist/platforms/vega/device.d.ts.map +1 -0
  27. package/dist/platforms/vega/device.js +206 -0
  28. package/dist/platforms/vega/index.d.ts +4 -0
  29. package/dist/platforms/vega/index.d.ts.map +1 -0
  30. package/dist/platforms/vega/index.js +75 -0
  31. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  32. package/dist/utils/status-formatter.d.ts +27 -0
  33. package/dist/utils/status-formatter.d.ts.map +1 -0
  34. package/dist/utils/status-formatter.js +54 -0
  35. package/package.json +4 -4
  36. package/src/bundlers/metro.ts +8 -3
  37. package/src/commands/test.ts +33 -23
  38. package/src/discovery/index.ts +2 -0
  39. package/src/discovery/testDiscovery.ts +50 -0
  40. package/src/errors/errorHandler.ts +16 -4
  41. package/src/errors/errors.ts +9 -4
  42. package/src/index.ts +33 -5
  43. package/src/platforms/android/index.ts +1 -1
  44. package/src/platforms/platform-registry.ts +2 -0
  45. package/src/platforms/vega/build.ts +85 -0
  46. package/src/platforms/vega/device.ts +258 -0
  47. package/src/platforms/vega/index.ts +107 -0
@@ -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;