@react-native-harness/cli 1.0.0-alpha.21 → 1.0.0-alpha.22

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 (94) hide show
  1. package/dist/bundlers/metro.d.ts +5 -0
  2. package/dist/bundlers/metro.d.ts.map +1 -0
  3. package/dist/bundlers/metro.js +71 -0
  4. package/dist/bundlers/webpack.d.ts +2 -0
  5. package/dist/bundlers/webpack.d.ts.map +1 -0
  6. package/dist/bundlers/webpack.js +49 -0
  7. package/dist/commands/test.d.ts +3 -0
  8. package/dist/commands/test.d.ts.map +1 -0
  9. package/dist/commands/test.js +140 -0
  10. package/dist/discovery/index.d.ts +3 -0
  11. package/dist/discovery/index.d.ts.map +1 -0
  12. package/dist/discovery/index.js +1 -0
  13. package/dist/discovery/testDiscovery.d.ts +11 -0
  14. package/dist/discovery/testDiscovery.d.ts.map +1 -0
  15. package/dist/discovery/testDiscovery.js +29 -0
  16. package/dist/errors/appNotInstalledError.d.ts +7 -0
  17. package/dist/errors/appNotInstalledError.d.ts.map +1 -0
  18. package/dist/errors/appNotInstalledError.js +12 -0
  19. package/dist/errors/bridgeTimeoutError.d.ts +7 -0
  20. package/dist/errors/bridgeTimeoutError.d.ts.map +1 -0
  21. package/dist/errors/bridgeTimeoutError.js +12 -0
  22. package/dist/errors/errorHandler.d.ts +2 -0
  23. package/dist/errors/errorHandler.d.ts.map +1 -0
  24. package/dist/errors/errorHandler.js +152 -0
  25. package/dist/errors/errors.d.ts +45 -0
  26. package/dist/errors/errors.d.ts.map +1 -0
  27. package/dist/errors/errors.js +89 -0
  28. package/dist/jest.d.ts +2 -0
  29. package/dist/jest.d.ts.map +1 -0
  30. package/dist/jest.js +7 -0
  31. package/dist/platforms/android/build.d.ts +5 -0
  32. package/dist/platforms/android/build.d.ts.map +1 -0
  33. package/dist/platforms/android/build.js +29 -0
  34. package/dist/platforms/android/device.d.ts +5 -0
  35. package/dist/platforms/android/device.d.ts.map +1 -0
  36. package/dist/platforms/android/device.js +36 -0
  37. package/dist/platforms/android/emulator.d.ts +10 -0
  38. package/dist/platforms/android/emulator.d.ts.map +1 -0
  39. package/dist/platforms/android/emulator.js +116 -0
  40. package/dist/platforms/android/index.d.ts +4 -0
  41. package/dist/platforms/android/index.d.ts.map +1 -0
  42. package/dist/platforms/android/index.js +56 -0
  43. package/dist/platforms/ios/build.d.ts +7 -0
  44. package/dist/platforms/ios/build.d.ts.map +1 -0
  45. package/dist/platforms/ios/build.js +48 -0
  46. package/dist/platforms/ios/device.d.ts +11 -0
  47. package/dist/platforms/ios/device.d.ts.map +1 -0
  48. package/dist/platforms/ios/device.js +51 -0
  49. package/dist/platforms/ios/index.d.ts +4 -0
  50. package/dist/platforms/ios/index.d.ts.map +1 -0
  51. package/dist/platforms/ios/index.js +43 -0
  52. package/dist/platforms/ios/simulator.d.ts +11 -0
  53. package/dist/platforms/ios/simulator.d.ts.map +1 -0
  54. package/dist/platforms/ios/simulator.js +129 -0
  55. package/dist/platforms/platform-adapter.d.ts +10 -0
  56. package/dist/platforms/platform-adapter.d.ts.map +1 -0
  57. package/dist/platforms/platform-adapter.js +1 -0
  58. package/dist/platforms/platform-registry.d.ts +3 -0
  59. package/dist/platforms/platform-registry.d.ts.map +1 -0
  60. package/dist/platforms/platform-registry.js +21 -0
  61. package/dist/platforms/vega/build.d.ts +23 -0
  62. package/dist/platforms/vega/build.d.ts.map +1 -0
  63. package/dist/platforms/vega/build.js +55 -0
  64. package/dist/platforms/vega/device.d.ts +57 -0
  65. package/dist/platforms/vega/device.d.ts.map +1 -0
  66. package/dist/platforms/vega/device.js +206 -0
  67. package/dist/platforms/vega/index.d.ts +4 -0
  68. package/dist/platforms/vega/index.d.ts.map +1 -0
  69. package/dist/platforms/vega/index.js +75 -0
  70. package/dist/platforms/web/index.d.ts +4 -0
  71. package/dist/platforms/web/index.d.ts.map +1 -0
  72. package/dist/platforms/web/index.js +9 -0
  73. package/dist/process.d.ts +3 -0
  74. package/dist/process.d.ts.map +1 -0
  75. package/dist/process.js +28 -0
  76. package/dist/reporters/default-reporter.d.ts +3 -0
  77. package/dist/reporters/default-reporter.d.ts.map +1 -0
  78. package/dist/reporters/default-reporter.js +116 -0
  79. package/dist/reporters/junit-reporter.d.ts +3 -0
  80. package/dist/reporters/junit-reporter.d.ts.map +1 -0
  81. package/dist/reporters/junit-reporter.js +119 -0
  82. package/dist/reporters/live-reporter.d.ts +20 -0
  83. package/dist/reporters/live-reporter.d.ts.map +1 -0
  84. package/dist/reporters/live-reporter.js +176 -0
  85. package/dist/src/reporters/default-reporter.js +135 -0
  86. package/dist/test-reporter-demo.js +95 -0
  87. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  88. package/dist/utils/status-formatter.d.ts +27 -0
  89. package/dist/utils/status-formatter.d.ts.map +1 -0
  90. package/dist/utils/status-formatter.js +54 -0
  91. package/dist/utils.d.ts +6 -0
  92. package/dist/utils.d.ts.map +1 -0
  93. package/dist/utils.js +26 -0
  94. package/package.json +3 -3
@@ -0,0 +1,89 @@
1
+ export class NoRunnerSpecifiedError extends Error {
2
+ constructor(availableRunners) {
3
+ super('No runner specified');
4
+ this.name = 'NoRunnerSpecifiedError';
5
+ this.availableRunners = availableRunners;
6
+ }
7
+ availableRunners;
8
+ }
9
+ export class RunnerNotFoundError extends Error {
10
+ constructor(runnerName, availableRunners) {
11
+ super(`Runner "${runnerName}" not found`);
12
+ this.name = 'RunnerNotFoundError';
13
+ this.runnerName = runnerName;
14
+ this.availableRunners = availableRunners;
15
+ }
16
+ runnerName;
17
+ availableRunners;
18
+ }
19
+ export class EnvironmentInitializationError extends Error {
20
+ constructor(message, runnerName, platform, details) {
21
+ super(`Failed to initialize environment for "${runnerName}" (${platform}): ${message}`);
22
+ this.name = 'EnvironmentInitializationError';
23
+ this.runnerName = runnerName;
24
+ this.platform = platform;
25
+ this.details = details;
26
+ }
27
+ runnerName;
28
+ platform;
29
+ details;
30
+ }
31
+ export class TestExecutionError extends Error {
32
+ constructor(testFile, error, testSuite, testName) {
33
+ const errorMessage = error instanceof Error ? error.message : String(error);
34
+ const suiteInfo = testSuite ? ` in suite "${testSuite}"` : '';
35
+ const testInfo = testName ? ` test "${testName}"` : '';
36
+ super(`Test execution failed for ${testFile}${suiteInfo}${testInfo}: ${errorMessage}`);
37
+ this.name = 'TestExecutionError';
38
+ this.testFile = testFile;
39
+ this.testSuite = testSuite;
40
+ this.testName = testName;
41
+ this.originalError = error;
42
+ }
43
+ testFile;
44
+ testSuite;
45
+ testName;
46
+ originalError;
47
+ }
48
+ export class RpcClientError extends Error {
49
+ constructor(message, bridgePort, connectionStatus) {
50
+ const portInfo = bridgePort ? ` (port ${bridgePort})` : '';
51
+ const statusInfo = connectionStatus ? ` - Status: ${connectionStatus}` : '';
52
+ super(`RPC client error${portInfo}: ${message}${statusInfo}`);
53
+ this.name = 'RpcClientError';
54
+ this.bridgePort = bridgePort;
55
+ this.connectionStatus = connectionStatus;
56
+ }
57
+ bridgePort;
58
+ connectionStatus;
59
+ }
60
+ export class BridgeTimeoutError extends Error {
61
+ timeout;
62
+ runnerName;
63
+ platform;
64
+ constructor(timeout, runnerName, platform) {
65
+ super(`Bridge connection timed out after ${timeout}ms while waiting for "${runnerName}" (${platform}) runner to be ready`);
66
+ this.timeout = timeout;
67
+ this.runnerName = runnerName;
68
+ this.platform = platform;
69
+ this.name = 'BridgeTimeoutError';
70
+ }
71
+ }
72
+ export class BundlingFailedError extends Error {
73
+ modulePath;
74
+ reason;
75
+ constructor(modulePath, reason) {
76
+ super(`Bundling of ${modulePath} failed: ${reason}`);
77
+ this.modulePath = modulePath;
78
+ this.reason = reason;
79
+ this.name = 'BundlingFailedError';
80
+ }
81
+ }
82
+ export class MetroPortUnavailableError extends Error {
83
+ port;
84
+ constructor(port) {
85
+ super(`Metro port ${port} is not available`);
86
+ this.port = port;
87
+ this.name = 'MetroPortUnavailableError';
88
+ }
89
+ }
package/dist/jest.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=jest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.d.ts","sourceRoot":"","sources":["../src/jest.ts"],"names":[],"mappings":""}
package/dist/jest.js ADDED
@@ -0,0 +1,7 @@
1
+ import { run, yargsOptions } from 'jest-cli';
2
+ yargsOptions.harnessRunner = {
3
+ type: 'string',
4
+ description: 'Specify which Harness runner to use',
5
+ requiresArg: true,
6
+ };
7
+ run();
@@ -0,0 +1,5 @@
1
+ export declare const buildAndroidApp: () => Promise<void>;
2
+ export declare const installApp: (deviceId: string) => Promise<void>;
3
+ export declare const killApp: (deviceId: string, bundleId: string) => Promise<void>;
4
+ export declare const runApp: (deviceId: string, bundleId: string, activityName: string) => Promise<void>;
5
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/platforms/android/build.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,QAAa,OAAO,CAAC,IAAI,CAEpD,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,UAAU,MAAM,KAAG,OAAO,CAAC,IAAI,CAiB/D,CAAC;AAEF,eAAO,MAAM,OAAO,GAClB,UAAU,MAAM,EAChB,UAAU,MAAM,KACf,OAAO,CAAC,IAAI,CAEd,CAAC;AAEF,eAAO,MAAM,MAAM,GACjB,UAAU,MAAM,EAChB,UAAU,MAAM,EAChB,cAAc,MAAM,KACnB,OAAO,CAAC,IAAI,CAWd,CAAC"}
@@ -0,0 +1,29 @@
1
+ import path from 'node:path';
2
+ import { spawn } from '@react-native-harness/tools';
3
+ export const buildAndroidApp = async () => {
4
+ await spawn('react-native', ['build-android', '--tasks', 'assembleDebug']);
5
+ };
6
+ export const installApp = async (deviceId) => {
7
+ await spawn('adb', [
8
+ '-s',
9
+ deviceId,
10
+ 'install',
11
+ '-r',
12
+ path.join(process.cwd(), 'android', 'app', 'build', 'outputs', 'apk', 'debug', 'app-debug.apk'),
13
+ ]);
14
+ };
15
+ export const killApp = async (deviceId, bundleId) => {
16
+ await spawn('adb', ['-s', deviceId, 'shell', 'am', 'force-stop', bundleId]);
17
+ };
18
+ export const runApp = async (deviceId, bundleId, activityName) => {
19
+ await killApp(deviceId, bundleId);
20
+ await spawn('adb', [
21
+ '-s',
22
+ deviceId,
23
+ 'shell',
24
+ 'am',
25
+ 'start',
26
+ '-n',
27
+ `${bundleId}/${activityName}`,
28
+ ]);
29
+ };
@@ -0,0 +1,5 @@
1
+ export declare const killApp: (deviceId: string, bundleId: string) => Promise<void>;
2
+ export declare const runApp: (deviceId: string, bundleId: string) => Promise<void>;
3
+ export declare const isAppInstalled: (deviceId: string, bundleId: string) => Promise<boolean>;
4
+ export declare const reversePort: (port: number) => Promise<void>;
5
+ //# sourceMappingURL=device.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../../src/platforms/android/device.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,GAClB,UAAU,MAAM,EAChB,UAAU,MAAM,KACf,OAAO,CAAC,IAAI,CAEd,CAAC;AAEF,eAAO,MAAM,MAAM,GACjB,UAAU,MAAM,EAChB,UAAU,MAAM,KACf,OAAO,CAAC,IAAI,CAWd,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,UAAU,MAAM,KACf,OAAO,CAAC,OAAO,CAejB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,IAAI,CAE5D,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { spawn } from '@react-native-harness/tools';
2
+ export const killApp = async (deviceId, bundleId) => {
3
+ await spawn('adb', ['-s', deviceId, 'shell', 'am', 'force-stop', bundleId]);
4
+ };
5
+ export const runApp = async (deviceId, bundleId) => {
6
+ await killApp(deviceId, bundleId);
7
+ await spawn('adb', [
8
+ '-s',
9
+ deviceId,
10
+ 'shell',
11
+ 'am',
12
+ 'start',
13
+ '-n',
14
+ `${bundleId}/.MainActivity`,
15
+ ]);
16
+ };
17
+ export const isAppInstalled = async (deviceId, bundleId) => {
18
+ try {
19
+ const { stdout } = await spawn('adb', [
20
+ '-s',
21
+ deviceId,
22
+ 'shell',
23
+ 'pm',
24
+ 'list',
25
+ 'packages',
26
+ bundleId,
27
+ ]);
28
+ return stdout.trim() !== '';
29
+ }
30
+ catch {
31
+ return false;
32
+ }
33
+ };
34
+ export const reversePort = async (port) => {
35
+ await spawn('adb', ['reverse', `tcp:${port}`, `tcp:${port}`]);
36
+ };
@@ -0,0 +1,10 @@
1
+ import { ChildProcess } from 'node:child_process';
2
+ export type AndroidEmulatorStatus = 'running' | 'loading' | 'stopped';
3
+ export declare const getEmulatorNameFromId: (emulatorId: string) => Promise<string | null>;
4
+ export declare const getEmulatorDeviceId: (avdName: string) => Promise<string | null>;
5
+ export declare const getEmulatorStatus: (avdName: string) => Promise<AndroidEmulatorStatus>;
6
+ export declare const runEmulator: (name: string) => Promise<ChildProcess>;
7
+ export declare const stopEmulator: (avdName: string) => Promise<void>;
8
+ export declare const isAppInstalled: (emulatorId: string, bundleId: string) => Promise<boolean>;
9
+ export declare const reversePort: (port: number) => Promise<void>;
10
+ //# sourceMappingURL=emulator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emulator.d.ts","sourceRoot":"","sources":["../../../src/platforms/android/emulator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAEtE,eAAO,MAAM,qBAAqB,GAChC,YAAY,MAAM,KACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAcvB,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,SAAS,MAAM,KACd,OAAO,CAAC,MAAM,GAAG,IAAI,CAmBvB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,KACd,OAAO,CAAC,qBAAqB,CAoB/B,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,YAAY,CA2BpE,CAAC;AAEF,eAAO,MAAM,YAAY,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,IAAI,CAQhE,CAAC;AAOF,eAAO,MAAM,cAAc,GACzB,YAAY,MAAM,EAClB,UAAU,MAAM,KACf,OAAO,CAAC,OAAO,CAejB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,IAAI,CAE5D,CAAC"}
@@ -0,0 +1,116 @@
1
+ import { spawn } from '@react-native-harness/tools';
2
+ export const getEmulatorNameFromId = async (emulatorId) => {
3
+ try {
4
+ const { stdout } = await spawn('adb', [
5
+ '-s',
6
+ emulatorId,
7
+ 'emu',
8
+ 'avd',
9
+ 'name',
10
+ ]);
11
+ const avdName = stdout.split('\n')[0].trim();
12
+ return avdName || null;
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ };
18
+ export const getEmulatorDeviceId = async (avdName) => {
19
+ try {
20
+ const { stdout } = await spawn('adb', ['devices']);
21
+ const lines = stdout.split('\n');
22
+ for (const line of lines) {
23
+ const parts = line.trim().split('\t');
24
+ if (parts.length === 2 && parts[0].startsWith('emulator-')) {
25
+ const emulatorId = parts[0].trim();
26
+ const name = await getEmulatorNameFromId(emulatorId);
27
+ if (name === avdName) {
28
+ return emulatorId;
29
+ }
30
+ }
31
+ }
32
+ return null;
33
+ }
34
+ catch {
35
+ return null;
36
+ }
37
+ };
38
+ export const getEmulatorStatus = async (avdName) => {
39
+ const emulatorId = await getEmulatorDeviceId(avdName);
40
+ if (!emulatorId) {
41
+ return 'stopped';
42
+ }
43
+ try {
44
+ // Check if device is fully booted by checking boot completion
45
+ const { stdout } = await spawn('adb', [
46
+ '-s',
47
+ emulatorId,
48
+ 'shell',
49
+ 'getprop',
50
+ 'sys.boot_completed',
51
+ ]);
52
+ const bootCompleted = stdout.trim() === '1';
53
+ return bootCompleted ? 'running' : 'loading';
54
+ }
55
+ catch {
56
+ return 'loading';
57
+ }
58
+ };
59
+ export const runEmulator = async (name) => {
60
+ // Start the emulator
61
+ const process = spawn('emulator', ['-avd', name]);
62
+ const nodeChildProcess = await process.nodeChildProcess;
63
+ // Poll for emulator status until it's fully running
64
+ const checkStatus = async () => {
65
+ const status = await getEmulatorStatus(name);
66
+ if (status === 'running') {
67
+ return;
68
+ }
69
+ else if (status === 'loading') {
70
+ // Check again in 2 seconds
71
+ await new Promise((resolve) => setTimeout(resolve, 2000));
72
+ await checkStatus();
73
+ }
74
+ else {
75
+ // Still stopped, check again in 1 second
76
+ await new Promise((resolve) => setTimeout(resolve, 1000));
77
+ await checkStatus();
78
+ }
79
+ };
80
+ // Start checking status after a brief delay to allow emulator to start
81
+ await new Promise((resolve) => setTimeout(resolve, 3000));
82
+ await checkStatus();
83
+ return nodeChildProcess;
84
+ };
85
+ export const stopEmulator = async (avdName) => {
86
+ // First, get the emulator device ID
87
+ const emulatorId = await getEmulatorDeviceId(avdName);
88
+ if (!emulatorId) {
89
+ return; // No emulator running, nothing to stop
90
+ }
91
+ await stopEmulatorById(emulatorId);
92
+ };
93
+ const stopEmulatorById = async (emulatorId) => {
94
+ // Stop the emulator using the found ID
95
+ await spawn('adb', ['-s', emulatorId, 'emu', 'kill']);
96
+ };
97
+ export const isAppInstalled = async (emulatorId, bundleId) => {
98
+ try {
99
+ const { stdout } = await spawn('adb', [
100
+ '-s',
101
+ emulatorId,
102
+ 'shell',
103
+ 'pm',
104
+ 'list',
105
+ 'packages',
106
+ bundleId,
107
+ ]);
108
+ return stdout.trim() !== '';
109
+ }
110
+ catch {
111
+ return false;
112
+ }
113
+ };
114
+ export const reversePort = async (port) => {
115
+ await spawn('adb', ['reverse', `tcp:${port}`, `tcp:${port}`]);
116
+ };
@@ -0,0 +1,4 @@
1
+ import { type PlatformAdapter } from '../platform-adapter.js';
2
+ declare const androidPlatformAdapter: PlatformAdapter;
3
+ export default androidPlatformAdapter;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/platforms/android/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAa9D,QAAA,MAAM,sBAAsB,EAAE,eAgE7B,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { assertAndroidRunnerConfig, } from '@react-native-harness/config';
2
+ import { logger } from '@react-native-harness/tools';
3
+ import { runEmulator, getEmulatorDeviceId, reversePort, isAppInstalled, getEmulatorStatus, } from './emulator.js';
4
+ import { runApp, killApp } from './build.js';
5
+ import { killWithAwait } from '../../process.js';
6
+ import { runMetro } from '../../bundlers/metro.js';
7
+ import { AppNotInstalledError } from '../../errors/errors.js';
8
+ const androidPlatformAdapter = {
9
+ name: 'android',
10
+ getEnvironment: async (runner) => {
11
+ assertAndroidRunnerConfig(runner);
12
+ let emulator = null;
13
+ const emulatorStatus = await getEmulatorStatus(runner.deviceId);
14
+ logger.debug(`Emulator status: ${emulatorStatus}`);
15
+ const metroPromise = runMetro();
16
+ if (emulatorStatus === 'stopped') {
17
+ logger.debug(`Emulator ${runner.deviceId} is stopped, starting it`);
18
+ emulator = await runEmulator(runner.deviceId);
19
+ }
20
+ const deviceId = await getEmulatorDeviceId(runner.deviceId);
21
+ logger.debug(`Device ID: ${deviceId}`);
22
+ if (!deviceId) {
23
+ throw new Error('Emulator not found');
24
+ }
25
+ await Promise.all([
26
+ reversePort(8081),
27
+ reversePort(8080),
28
+ reversePort(3001),
29
+ ]);
30
+ logger.debug('Ports reversed');
31
+ const isInstalled = await isAppInstalled(deviceId, runner.bundleId);
32
+ logger.debug(`App is installed: ${isInstalled}`);
33
+ if (!isInstalled) {
34
+ throw new AppNotInstalledError(runner.deviceId, runner.bundleId, 'android');
35
+ }
36
+ logger.debug('Waiting for Metro to start');
37
+ const metro = await metroPromise;
38
+ logger.debug('Metro started');
39
+ logger.debug('Running app');
40
+ await runApp(deviceId, runner.bundleId, runner.activityName);
41
+ logger.debug('App running');
42
+ return {
43
+ restart: async () => {
44
+ await runApp(deviceId, runner.bundleId, runner.activityName);
45
+ },
46
+ dispose: async () => {
47
+ await killApp(deviceId, runner.bundleId);
48
+ if (emulator) {
49
+ await killWithAwait(emulator);
50
+ }
51
+ await killWithAwait(metro);
52
+ },
53
+ };
54
+ },
55
+ };
56
+ export default androidPlatformAdapter;
@@ -0,0 +1,7 @@
1
+ export declare const listDevices: () => Promise<any>;
2
+ export declare const getDeviceByName: (simulatorName: string, systemVersion: string) => Promise<any | null>;
3
+ export declare const listApps: (udid: string) => Promise<string[]>;
4
+ export declare const isAppInstalled: (udid: string, bundleId: string) => Promise<boolean>;
5
+ export declare const runApp: (udid: string, appName: string) => Promise<void>;
6
+ export declare const killApp: (udid: string, appName: string) => Promise<void>;
7
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/platforms/ios/build.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,GAAG,CAQ/C,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,eAAe,MAAM,EACrB,eAAe,MAAM,KAEpB,OAAO,CAAC,GAAG,GAAG,IAAI,CAsBpB,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,CAY7D,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,MAAM,MAAM,EACZ,UAAU,MAAM,KACf,OAAO,CAAC,OAAO,CAGjB,CAAC;AAEF,eAAO,MAAM,MAAM,GAAU,MAAM,MAAM,EAAE,SAAS,MAAM,KAAG,OAAO,CAAC,IAAI,CAGxE,CAAC;AAEF,eAAO,MAAM,OAAO,GAAU,MAAM,MAAM,EAAE,SAAS,MAAM,KAAG,OAAO,CAAC,IAAI,CAEzE,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { spawn, spawnAndForget } from '@react-native-harness/tools';
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ export const listDevices = async () => {
4
+ const { stdout } = await spawn('xcrun', [
5
+ 'simctl',
6
+ 'list',
7
+ 'devices',
8
+ '--json',
9
+ ]);
10
+ return JSON.parse(stdout);
11
+ };
12
+ export const getDeviceByName = async (simulatorName, systemVersion
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ ) => {
15
+ const devices = await listDevices();
16
+ const expectedRuntimeId = `com.apple.CoreSimulator.SimRuntime.iOS-${systemVersion.replace(/\./, '-')}`;
17
+ const runtime = devices.devices[expectedRuntimeId];
18
+ if (!runtime) {
19
+ return null;
20
+ }
21
+ const runtimeDevices = devices.devices[runtime];
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ const device = runtimeDevices.find((d) => d.name === simulatorName);
24
+ if (device) {
25
+ return device;
26
+ }
27
+ return null;
28
+ };
29
+ export const listApps = async (udid) => {
30
+ const { stdout: plistOutput } = await spawn('xcrun', [
31
+ 'simctl',
32
+ 'listapps',
33
+ udid,
34
+ ]);
35
+ const { stdout: jsonOutput } = await spawn('plutil', ['-convert', 'json', '-o', '-', '-'], { stdin: { string: plistOutput } });
36
+ return Object.keys(JSON.parse(jsonOutput));
37
+ };
38
+ export const isAppInstalled = async (udid, bundleId) => {
39
+ const appList = await listApps(udid);
40
+ return appList.includes(bundleId);
41
+ };
42
+ export const runApp = async (udid, appName) => {
43
+ await killApp(udid, appName);
44
+ await spawn('xcrun', ['simctl', 'launch', udid, appName]);
45
+ };
46
+ export const killApp = async (udid, appName) => {
47
+ await spawnAndForget('xcrun', ['simctl', 'terminate', udid, appName]);
48
+ };
@@ -0,0 +1,11 @@
1
+ type Device = any;
2
+ export declare const listDevices: () => Promise<{
3
+ devices: Device[];
4
+ }>;
5
+ export declare const getDeviceByName: (simulatorName: string) => Promise<Device | null>;
6
+ export declare const listApps: (udid: string) => Promise<string[]>;
7
+ export declare const isAppInstalled: (simulatorName: string, bundleId: string) => Promise<boolean>;
8
+ export declare const runApp: (simulatorName: string, appName: string) => Promise<void>;
9
+ export declare const killApp: (simulatorName: string, appName: string) => Promise<void>;
10
+ export {};
11
+ //# sourceMappingURL=device.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../../src/platforms/ios/device.ts"],"names":[],"mappings":"AAGA,KAAK,MAAM,GAAG,GAAG,CAAC;AAElB,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAQjE,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,eAAe,MAAM,KACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CAavB,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,CAY7D,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,eAAe,MAAM,EACrB,UAAU,MAAM,KACf,OAAO,CAAC,OAAO,CASjB,CAAC;AAEF,eAAO,MAAM,MAAM,GACjB,eAAe,MAAM,EACrB,SAAS,MAAM,KACd,OAAO,CAAC,IAAI,CAGd,CAAC;AAEF,eAAO,MAAM,OAAO,GAClB,eAAe,MAAM,EACrB,SAAS,MAAM,KACd,OAAO,CAAC,IAAI,CAOd,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { spawn, spawnAndForget } from '@react-native-harness/tools';
2
+ export const listDevices = async () => {
3
+ const { stdout } = await spawn('xcrun', [
4
+ 'simctl',
5
+ 'list',
6
+ 'devices',
7
+ '--json',
8
+ ]);
9
+ return JSON.parse(stdout);
10
+ };
11
+ export const getDeviceByName = async (simulatorName) => {
12
+ const devices = await listDevices();
13
+ for (const runtime in devices.devices) {
14
+ const runtimeDevices = devices.devices[runtime];
15
+ for (const device of runtimeDevices) {
16
+ if (device.name === simulatorName && device.isAvailable) {
17
+ return device;
18
+ }
19
+ }
20
+ }
21
+ return null;
22
+ };
23
+ export const listApps = async (udid) => {
24
+ const { stdout: plistOutput } = await spawn('xcrun', [
25
+ 'simctl',
26
+ 'listapps',
27
+ udid,
28
+ ]);
29
+ const { stdout: jsonOutput } = await spawn('plutil', ['-convert', 'json', '-o', '-', '-'], { stdin: { string: plistOutput } });
30
+ return Object.keys(JSON.parse(jsonOutput));
31
+ };
32
+ export const isAppInstalled = async (simulatorName, bundleId) => {
33
+ const device = await getDeviceByName(simulatorName);
34
+ if (!device) {
35
+ throw new Error(`Simulator ${simulatorName} not found`);
36
+ }
37
+ const appList = await listApps(device.udid);
38
+ return appList.includes(bundleId);
39
+ };
40
+ export const runApp = async (simulatorName, appName) => {
41
+ await killApp(simulatorName, appName);
42
+ await spawn('xcrun', ['simctl', 'launch', simulatorName, appName]);
43
+ };
44
+ export const killApp = async (simulatorName, appName) => {
45
+ await spawnAndForget('xcrun', [
46
+ 'simctl',
47
+ 'terminate',
48
+ simulatorName,
49
+ appName,
50
+ ]);
51
+ };
@@ -0,0 +1,4 @@
1
+ import { type PlatformAdapter } from '../platform-adapter.js';
2
+ declare const iosPlatformAdapter: PlatformAdapter;
3
+ export default iosPlatformAdapter;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/platforms/ios/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAa9D,QAAA,MAAM,kBAAkB,EAAE,eA8CzB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { assertIOSRunnerConfig, } from '@react-native-harness/config';
2
+ import { getSimulatorDeviceId, getSimulatorStatus, runSimulator, stopSimulator, } from './simulator.js';
3
+ import { isAppInstalled, runApp, killApp } from './build.js';
4
+ import { killWithAwait } from '../../process.js';
5
+ import { runMetro } from '../../bundlers/metro.js';
6
+ import { AppNotInstalledError } from '../../errors/errors.js';
7
+ import { assert } from '../../utils.js';
8
+ const iosPlatformAdapter = {
9
+ name: 'ios',
10
+ getEnvironment: async (runner) => {
11
+ assertIOSRunnerConfig(runner);
12
+ // TODO: system version is also important as there may be two emulators with the same name
13
+ // but different system versions
14
+ let shouldStopSimulator = false;
15
+ const udid = await getSimulatorDeviceId(runner.deviceId, runner.systemVersion);
16
+ assert(!!udid, 'Simulator not found');
17
+ const simulatorStatus = await getSimulatorStatus(udid);
18
+ const metroPromise = runMetro();
19
+ if (simulatorStatus === 'stopped') {
20
+ await runSimulator(udid);
21
+ shouldStopSimulator = true;
22
+ }
23
+ const isInstalled = await isAppInstalled(udid, runner.bundleId);
24
+ if (!isInstalled) {
25
+ throw new AppNotInstalledError(runner.deviceId, runner.bundleId, 'ios');
26
+ }
27
+ const metro = await metroPromise;
28
+ await runApp(udid, runner.bundleId);
29
+ return {
30
+ restart: async () => {
31
+ await runApp(udid, runner.bundleId);
32
+ },
33
+ dispose: async () => {
34
+ await killApp(udid, runner.bundleId);
35
+ if (shouldStopSimulator) {
36
+ await stopSimulator(udid);
37
+ }
38
+ await killWithAwait(metro);
39
+ },
40
+ };
41
+ },
42
+ };
43
+ export default iosPlatformAdapter;
@@ -0,0 +1,11 @@
1
+ export type IOSSimulatorStatus = 'stopped' | 'loading' | 'running';
2
+ export declare const getSimulatorDeviceId: (simulatorName: string, systemVersion: string) => Promise<string | null>;
3
+ export declare const getAvailableSimulators: () => Promise<Array<{
4
+ name: string;
5
+ udid: string;
6
+ runtime: string;
7
+ }>>;
8
+ export declare const getSimulatorStatus: (udid: string) => Promise<IOSSimulatorStatus>;
9
+ export declare const runSimulator: (udid: string) => Promise<void>;
10
+ export declare const stopSimulator: (udid: string) => Promise<void>;
11
+ //# sourceMappingURL=simulator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulator.d.ts","sourceRoot":"","sources":["../../../src/platforms/ios/simulator.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAEnE,eAAO,MAAM,oBAAoB,GAC/B,eAAe,MAAM,EACrB,eAAe,MAAM,KACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CA+BvB,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAAa,OAAO,CACrD,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAoCvD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,MAAM,MAAM,KACX,OAAO,CAAC,kBAAkB,CAiC5B,CAAC;AAEF,eAAO,MAAM,YAAY,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,IAAI,CAkC7D,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,IAAI,CAE9D,CAAC"}