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

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 (76) 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 +1 -1
  14. package/dist/errors/errorHandler.d.ts.map +1 -1
  15. package/dist/errors/errorHandler.js +103 -101
  16. package/dist/errors/errors.d.ts +6 -7
  17. package/dist/errors/errors.d.ts.map +1 -1
  18. package/dist/errors/errors.js +8 -12
  19. package/dist/external.d.ts +2 -0
  20. package/dist/external.d.ts.map +1 -0
  21. package/dist/external.js +1 -0
  22. package/dist/index.js +58 -33
  23. package/dist/jest.d.ts +2 -0
  24. package/dist/jest.d.ts.map +1 -0
  25. package/dist/jest.js +7 -0
  26. package/dist/platforms/android/emulator.d.ts +0 -1
  27. package/dist/platforms/android/emulator.d.ts.map +1 -1
  28. package/dist/platforms/android/emulator.js +26 -20
  29. package/dist/platforms/android/index.js +1 -1
  30. package/dist/platforms/ios/build.d.ts.map +1 -1
  31. package/dist/platforms/ios/build.js +5 -1
  32. package/dist/platforms/ios/device.d.ts +6 -2
  33. package/dist/platforms/ios/device.d.ts.map +1 -1
  34. package/dist/platforms/ios/simulator.d.ts.map +1 -1
  35. package/dist/platforms/ios/simulator.js +8 -3
  36. package/dist/platforms/platform-registry.d.ts.map +1 -1
  37. package/dist/platforms/platform-registry.js +3 -1
  38. package/dist/platforms/vega/build.d.ts +23 -0
  39. package/dist/platforms/vega/build.d.ts.map +1 -0
  40. package/dist/platforms/vega/build.js +55 -0
  41. package/dist/platforms/vega/device.d.ts +57 -0
  42. package/dist/platforms/vega/device.d.ts.map +1 -0
  43. package/dist/platforms/vega/device.js +206 -0
  44. package/dist/platforms/vega/index.d.ts +4 -0
  45. package/dist/platforms/vega/index.d.ts.map +1 -0
  46. package/dist/platforms/vega/index.js +75 -0
  47. package/dist/process.js +1 -1
  48. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  49. package/dist/utils/status-formatter.d.ts +27 -0
  50. package/dist/utils/status-formatter.d.ts.map +1 -0
  51. package/dist/utils/status-formatter.js +54 -0
  52. package/dist/utils.d.ts +1 -0
  53. package/dist/utils.d.ts.map +1 -1
  54. package/dist/utils.js +15 -0
  55. package/eslint.config.mjs +1 -0
  56. package/package.json +25 -9
  57. package/src/external.ts +0 -0
  58. package/src/index.ts +65 -44
  59. package/tsconfig.lib.json +1 -12
  60. package/src/bundlers/metro.ts +0 -89
  61. package/src/commands/test.ts +0 -218
  62. package/src/errors/errorHandler.ts +0 -196
  63. package/src/errors/errors.ts +0 -119
  64. package/src/platforms/android/build.ts +0 -49
  65. package/src/platforms/android/device.ts +0 -48
  66. package/src/platforms/android/emulator.ts +0 -139
  67. package/src/platforms/android/index.ts +0 -87
  68. package/src/platforms/ios/build.ts +0 -68
  69. package/src/platforms/ios/device.ts +0 -76
  70. package/src/platforms/ios/index.ts +0 -66
  71. package/src/platforms/ios/simulator.ts +0 -166
  72. package/src/platforms/platform-adapter.ts +0 -11
  73. package/src/platforms/platform-registry.ts +0 -24
  74. package/src/platforms/web/index.ts +0 -16
  75. package/src/process.ts +0 -33
  76. package/src/utils.ts +0 -12
@@ -1,68 +0,0 @@
1
- import { spawn, spawnAndForget } from '@react-native-harness/tools';
2
-
3
- export const listDevices = async (): Promise<any> => {
4
- const { stdout } = await spawn('xcrun', [
5
- 'simctl',
6
- 'list',
7
- 'devices',
8
- '--json',
9
- ]);
10
- return JSON.parse(stdout);
11
- };
12
-
13
- export const getDeviceByName = async (
14
- simulatorName: string,
15
- systemVersion: string
16
- ): Promise<any | null> => {
17
- const devices = await listDevices();
18
- const expectedRuntimeId = `com.apple.CoreSimulator.SimRuntime.iOS-${systemVersion.replace(
19
- /\./,
20
- '-'
21
- )}`;
22
-
23
- const runtime = devices.devices[expectedRuntimeId];
24
-
25
- if (!runtime) {
26
- return null;
27
- }
28
-
29
- const runtimeDevices = devices.devices[runtime];
30
- const device = runtimeDevices.find((d: any) => d.name === simulatorName);
31
-
32
- if (device) {
33
- return device;
34
- }
35
-
36
- return null;
37
- };
38
-
39
- export const listApps = async (udid: string): Promise<string[]> => {
40
- const { stdout: plistOutput } = await spawn('xcrun', [
41
- 'simctl',
42
- 'listapps',
43
- udid,
44
- ]);
45
- const { stdout: jsonOutput } = await spawn(
46
- 'plutil',
47
- ['-convert', 'json', '-o', '-', '-'],
48
- { stdin: { string: plistOutput } }
49
- );
50
- return Object.keys(JSON.parse(jsonOutput));
51
- };
52
-
53
- export const isAppInstalled = async (
54
- udid: string,
55
- bundleId: string
56
- ): Promise<boolean> => {
57
- const appList = await listApps(udid);
58
- return appList.includes(bundleId);
59
- };
60
-
61
- export const runApp = async (udid: string, appName: string): Promise<void> => {
62
- await killApp(udid, appName);
63
- await spawn('xcrun', ['simctl', 'launch', udid, appName]);
64
- };
65
-
66
- export const killApp = async (udid: string, appName: string): Promise<void> => {
67
- await spawnAndForget('xcrun', ['simctl', 'terminate', udid, appName]);
68
- };
@@ -1,76 +0,0 @@
1
- import { spawn, spawnAndForget } from '@react-native-harness/tools';
2
-
3
- export const listDevices = async (): Promise<any> => {
4
- const { stdout } = await spawn('xcrun', [
5
- 'simctl',
6
- 'list',
7
- 'devices',
8
- '--json',
9
- ]);
10
- return JSON.parse(stdout);
11
- };
12
-
13
- export const getDeviceByName = async (
14
- simulatorName: string
15
- ): Promise<any | null> => {
16
- const devices = await listDevices();
17
-
18
- for (const runtime in devices.devices) {
19
- const runtimeDevices = devices.devices[runtime];
20
- for (const device of runtimeDevices) {
21
- if (device.name === simulatorName && device.isAvailable) {
22
- return device;
23
- }
24
- }
25
- }
26
-
27
- return null;
28
- };
29
-
30
- export const listApps = async (udid: string): Promise<string[]> => {
31
- const { stdout: plistOutput } = await spawn('xcrun', [
32
- 'simctl',
33
- 'listapps',
34
- udid,
35
- ]);
36
- const { stdout: jsonOutput } = await spawn(
37
- 'plutil',
38
- ['-convert', 'json', '-o', '-', '-'],
39
- { stdin: { string: plistOutput } }
40
- );
41
- return Object.keys(JSON.parse(jsonOutput));
42
- };
43
-
44
- export const isAppInstalled = async (
45
- simulatorName: string,
46
- bundleId: string
47
- ): Promise<boolean> => {
48
- const device = await getDeviceByName(simulatorName);
49
-
50
- if (!device) {
51
- throw new Error(`Simulator ${simulatorName} not found`);
52
- }
53
-
54
- const appList = await listApps(device.udid);
55
- return appList.includes(bundleId);
56
- };
57
-
58
- export const runApp = async (
59
- simulatorName: string,
60
- appName: string
61
- ): Promise<void> => {
62
- await killApp(simulatorName, appName);
63
- await spawn('xcrun', ['simctl', 'launch', simulatorName, appName]);
64
- };
65
-
66
- export const killApp = async (
67
- simulatorName: string,
68
- appName: string
69
- ): Promise<void> => {
70
- await spawnAndForget('xcrun', [
71
- 'simctl',
72
- 'terminate',
73
- simulatorName,
74
- appName,
75
- ]);
76
- };
@@ -1,66 +0,0 @@
1
- import {
2
- assertIOSRunnerConfig,
3
- TestRunnerConfig,
4
- } from '@react-native-harness/config';
5
- import { type PlatformAdapter } from '../platform-adapter.js';
6
- import {
7
- getSimulatorDeviceId,
8
- getSimulatorStatus,
9
- runSimulator,
10
- stopSimulator,
11
- } from './simulator.js';
12
- import { isAppInstalled, runApp, killApp } from './build.js';
13
- import { killWithAwait } from '../../process.js';
14
- import { runMetro } from '../../bundlers/metro.js';
15
- import { AppNotInstalledError } from '../../errors/errors.js';
16
- import { assert } from '../../utils.js';
17
-
18
- const iosPlatformAdapter: PlatformAdapter = {
19
- name: 'ios',
20
- getEnvironment: async (runner: TestRunnerConfig) => {
21
- assertIOSRunnerConfig(runner);
22
- // TODO: system version is also important as there may be two emulators with the same name
23
- // but different system versions
24
-
25
- let shouldStopSimulator = false;
26
- const udid = await getSimulatorDeviceId(
27
- runner.deviceId,
28
- runner.systemVersion
29
- );
30
-
31
- assert(!!udid, 'Simulator not found');
32
-
33
- const simulatorStatus = await getSimulatorStatus(udid);
34
- const metroPromise = runMetro();
35
-
36
- if (simulatorStatus === 'stopped') {
37
- await runSimulator(udid);
38
- shouldStopSimulator = true;
39
- }
40
-
41
- const isInstalled = await isAppInstalled(udid, runner.bundleId);
42
-
43
- if (!isInstalled) {
44
- throw new AppNotInstalledError(runner.deviceId, runner.bundleId, 'ios');
45
- }
46
-
47
- const metro = await metroPromise;
48
- await runApp(udid, runner.bundleId);
49
-
50
- return {
51
- restart: async () => {
52
- await runApp(udid, runner.bundleId);
53
- },
54
- dispose: async () => {
55
- await killApp(udid, runner.bundleId);
56
- if (shouldStopSimulator) {
57
- await stopSimulator(udid);
58
- }
59
-
60
- await killWithAwait(metro);
61
- },
62
- };
63
- },
64
- };
65
-
66
- export default iosPlatformAdapter;
@@ -1,166 +0,0 @@
1
- import { spawn } from '@react-native-harness/tools';
2
-
3
- export type IOSSimulatorStatus = 'stopped' | 'loading' | 'running';
4
-
5
- export const getSimulatorDeviceId = async (
6
- simulatorName: string,
7
- systemVersion: string
8
- ): Promise<string | null> => {
9
- try {
10
- const { stdout } = await spawn('xcrun', [
11
- 'simctl',
12
- 'list',
13
- 'devices',
14
- '--json',
15
- ]);
16
- const devices = JSON.parse(stdout);
17
- const expectedRuntimeId = `com.apple.CoreSimulator.SimRuntime.iOS-${systemVersion.replace(
18
- /\./,
19
- '-'
20
- )}`;
21
-
22
- const runtime = devices.devices[expectedRuntimeId];
23
-
24
- if (!runtime) {
25
- return null;
26
- }
27
-
28
- const device = runtime.find((d: any) => d.name === simulatorName);
29
-
30
- if (device) {
31
- return device.udid;
32
- }
33
-
34
- return null;
35
- } catch {
36
- return null;
37
- }
38
- };
39
-
40
- export const getAvailableSimulators = async (): Promise<
41
- Array<{ name: string; udid: string; runtime: string }>
42
- > => {
43
- try {
44
- const { stdout } = await spawn('xcrun', [
45
- 'simctl',
46
- 'list',
47
- 'devices',
48
- '--json',
49
- ]);
50
- const devices = JSON.parse(stdout);
51
- const simulators: Array<{
52
- name: string;
53
- udid: string;
54
- runtime: string;
55
- }> = [];
56
-
57
- for (const runtime in devices.devices) {
58
- if (runtime.includes('iOS')) {
59
- const runtimeDevices = devices.devices[runtime];
60
- runtimeDevices.forEach((device: any) => {
61
- if (device.isAvailable) {
62
- simulators.push({
63
- name: device.name,
64
- udid: device.udid,
65
- runtime: runtime,
66
- });
67
- }
68
- });
69
- }
70
- }
71
-
72
- return simulators;
73
- } catch {
74
- return [];
75
- }
76
- };
77
-
78
- export const getSimulatorStatus = async (
79
- udid: string
80
- ): Promise<IOSSimulatorStatus> => {
81
- try {
82
- const { stdout } = await spawn('xcrun', [
83
- 'simctl',
84
- 'list',
85
- 'devices',
86
- '--json',
87
- ]);
88
- const devices = JSON.parse(stdout);
89
-
90
- for (const runtime in devices.devices) {
91
- if (runtime.includes('iOS')) {
92
- const runtimeDevices = devices.devices[runtime];
93
- const device = runtimeDevices.find((d: any) => d.udid === udid);
94
-
95
- if (device) {
96
- switch (device.state) {
97
- case 'Booted':
98
- return 'running';
99
- case 'Booting':
100
- return 'loading';
101
- default:
102
- return 'stopped';
103
- }
104
- }
105
- }
106
- }
107
-
108
- return 'stopped';
109
- } catch {
110
- return 'stopped';
111
- }
112
- };
113
-
114
- export const runSimulator = async (udid: string): Promise<void> => {
115
- try {
116
- await spawn('xcrun', ['simctl', 'boot', udid]);
117
- } catch (bootError: any) {
118
- // Ignore if simulator is already booted
119
- if (
120
- !bootError.stderr?.includes(
121
- 'Unable to boot device in current state: Booted'
122
- )
123
- ) {
124
- throw bootError;
125
- }
126
- }
127
-
128
- await spawn('open', ['-a', 'Simulator']);
129
-
130
- let attempts = 0;
131
-
132
- while (true) {
133
- attempts++;
134
-
135
- const status = await getSimulatorStatus(udid);
136
-
137
- if (status === 'running') {
138
- break;
139
- }
140
-
141
- if (attempts > 10) {
142
- throw new Error('Simulator not running');
143
- }
144
-
145
- await new Promise((resolve) => setTimeout(resolve, 1000));
146
- }
147
- };
148
-
149
- export const stopSimulator = async (udid: string): Promise<void> => {
150
- await stopSimulatorById(udid);
151
- };
152
-
153
- const stopSimulatorById = async (udid: string): Promise<void> => {
154
- try {
155
- await spawn('xcrun', ['simctl', 'shutdown', udid]);
156
- } catch (shutdownError: any) {
157
- // Ignore if simulator is already shut down
158
- if (
159
- !shutdownError.stderr?.includes(
160
- 'Unable to shutdown device in current state: Shutdown'
161
- )
162
- ) {
163
- throw shutdownError;
164
- }
165
- }
166
- };
@@ -1,11 +0,0 @@
1
- import { TestRunnerConfig } from '@react-native-harness/config';
2
-
3
- export type Environment = {
4
- restart: () => Promise<void>;
5
- dispose: () => Promise<void>;
6
- };
7
-
8
- export type PlatformAdapter = {
9
- name: string;
10
- getEnvironment: (runner: TestRunnerConfig) => Promise<Environment>;
11
- };
@@ -1,24 +0,0 @@
1
- import { PlatformAdapter } from './platform-adapter.js';
2
- import androidPlatformAdapter from './android/index.js';
3
- import iosPlatformAdapter from './ios/index.js';
4
- import webPlatformAdapter from './web/index.js';
5
-
6
- const platformAdapters = {
7
- android: androidPlatformAdapter,
8
- ios: iosPlatformAdapter,
9
- web: webPlatformAdapter,
10
- };
11
-
12
- export const getPlatformAdapter = async (
13
- platformName: string
14
- ): Promise<PlatformAdapter> => {
15
- if (!(platformName in platformAdapters)) {
16
- throw new Error(`Platform adapter for ${platformName} not found`);
17
- }
18
-
19
- try {
20
- return platformAdapters[platformName as keyof typeof platformAdapters];
21
- } catch (error) {
22
- throw new Error(`Platform adapter for ${platformName} not found`);
23
- }
24
- };
@@ -1,16 +0,0 @@
1
- import {
2
- TestRunnerConfig,
3
- assertWebRunnerConfig,
4
- } from '@react-native-harness/config';
5
- import { PlatformAdapter } from '../platform-adapter.js';
6
-
7
- export const webPlatformAdapter: PlatformAdapter = {
8
- name: 'web',
9
- getEnvironment: async (runner: TestRunnerConfig) => {
10
- assertWebRunnerConfig(runner);
11
-
12
- throw new Error('Web platform is currently disabled.');
13
- },
14
- };
15
-
16
- export default webPlatformAdapter;
package/src/process.ts DELETED
@@ -1,33 +0,0 @@
1
- import { type ChildProcess } from 'node:child_process';
2
-
3
- export const killWithAwait = (child: ChildProcess): Promise<void> => {
4
- return new Promise((resolve) => {
5
- const timeout = setTimeout(() => {
6
- child.kill('SIGTERM');
7
- resolve();
8
- }, 10000);
9
-
10
- if (child.killed || child.exitCode !== null) {
11
- clearTimeout(timeout);
12
- resolve();
13
- return;
14
- }
15
-
16
- child.on('exit', () => {
17
- clearTimeout(timeout);
18
- resolve();
19
- });
20
-
21
- child.on('error', () => {
22
- clearTimeout(timeout);
23
- resolve();
24
- });
25
-
26
- try {
27
- child.kill();
28
- } catch (error) {
29
- clearTimeout(timeout);
30
- resolve();
31
- }
32
- });
33
- };
package/src/utils.ts DELETED
@@ -1,12 +0,0 @@
1
- export function assert(condition: boolean, message: string): asserts condition {
2
- if (!condition) {
3
- throw new AssertionError(message);
4
- }
5
- }
6
-
7
- export class AssertionError extends Error {
8
- constructor(message: string) {
9
- super(message);
10
- this.name = 'AssertionError';
11
- }
12
- }