react-native-harness 0.0.0 → 1.0.0-alpha.1
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/LICENSE +20 -0
- package/README.md +7 -0
- package/bin.js +3 -0
- package/dist/bundlers/metro.d.ts +5 -0
- package/dist/bundlers/metro.d.ts.map +1 -0
- package/dist/bundlers/metro.js +52 -0
- package/dist/bundlers/webpack.d.ts +2 -0
- package/dist/bundlers/webpack.d.ts.map +1 -0
- package/dist/bundlers/webpack.js +49 -0
- package/dist/commands/test.d.ts +2 -0
- package/dist/commands/test.d.ts.map +1 -0
- package/dist/commands/test.js +111 -0
- package/dist/errors/appNotInstalledError.d.ts +7 -0
- package/dist/errors/appNotInstalledError.d.ts.map +1 -0
- package/dist/errors/appNotInstalledError.js +12 -0
- package/dist/errors/bridgeTimeoutError.d.ts +7 -0
- package/dist/errors/bridgeTimeoutError.d.ts.map +1 -0
- package/dist/errors/bridgeTimeoutError.js +12 -0
- package/dist/errors/errorHandler.d.ts +2 -0
- package/dist/errors/errorHandler.d.ts.map +1 -0
- package/dist/errors/errorHandler.js +138 -0
- package/dist/errors/errors.d.ts +41 -0
- package/dist/errors/errors.d.ts.map +1 -0
- package/dist/errors/errors.js +83 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/platforms/android/build.d.ts +5 -0
- package/dist/platforms/android/build.d.ts.map +1 -0
- package/dist/platforms/android/build.js +29 -0
- package/dist/platforms/android/device.d.ts +5 -0
- package/dist/platforms/android/device.d.ts.map +1 -0
- package/dist/platforms/android/device.js +36 -0
- package/dist/platforms/android/emulator.d.ts +11 -0
- package/dist/platforms/android/emulator.d.ts.map +1 -0
- package/dist/platforms/android/emulator.js +110 -0
- package/dist/platforms/android/index.d.ts +4 -0
- package/dist/platforms/android/index.d.ts.map +1 -0
- package/dist/platforms/android/index.js +56 -0
- package/dist/platforms/ios/build.d.ts +7 -0
- package/dist/platforms/ios/build.d.ts.map +1 -0
- package/dist/platforms/ios/build.js +51 -0
- package/dist/platforms/ios/device.d.ts +7 -0
- package/dist/platforms/ios/device.d.ts.map +1 -0
- package/dist/platforms/ios/device.js +51 -0
- package/dist/platforms/ios/index.d.ts +4 -0
- package/dist/platforms/ios/index.d.ts.map +1 -0
- package/dist/platforms/ios/index.js +38 -0
- package/dist/platforms/ios/simulator.d.ts +11 -0
- package/dist/platforms/ios/simulator.d.ts.map +1 -0
- package/dist/platforms/ios/simulator.js +133 -0
- package/dist/platforms/platform-adapter.d.ts +10 -0
- package/dist/platforms/platform-adapter.d.ts.map +1 -0
- package/dist/platforms/platform-adapter.js +1 -0
- package/dist/platforms/platform-registry.d.ts +3 -0
- package/dist/platforms/platform-registry.d.ts.map +1 -0
- package/dist/platforms/platform-registry.js +19 -0
- package/dist/platforms/web/index.d.ts +4 -0
- package/dist/platforms/web/index.d.ts.map +1 -0
- package/dist/platforms/web/index.js +73 -0
- package/dist/process.d.ts +3 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +28 -0
- package/dist/reporters/default-reporter.d.ts +3 -0
- package/dist/reporters/default-reporter.d.ts.map +1 -0
- package/dist/reporters/default-reporter.js +116 -0
- package/dist/reporters/junit-reporter.d.ts +3 -0
- package/dist/reporters/junit-reporter.d.ts.map +1 -0
- package/dist/reporters/junit-reporter.js +119 -0
- package/dist/reporters/live-reporter.d.ts +20 -0
- package/dist/reporters/live-reporter.d.ts.map +1 -0
- package/dist/reporters/live-reporter.js +176 -0
- package/dist/src/reporters/default-reporter.js +135 -0
- package/dist/test-reporter-demo.js +95 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +11 -0
- package/eslint.config.mjs +19 -0
- package/package.json +16 -8
- package/src/bundlers/metro.ts +79 -0
- package/src/commands/test.ts +189 -0
- package/src/errors/errorHandler.ts +184 -0
- package/src/errors/errors.ts +109 -0
- package/src/index.ts +52 -0
- package/src/platforms/android/build.ts +48 -0
- package/src/platforms/android/device.ts +48 -0
- package/src/platforms/android/emulator.ts +139 -0
- package/src/platforms/android/index.ts +87 -0
- package/src/platforms/ios/build.ts +76 -0
- package/src/platforms/ios/device.ts +76 -0
- package/src/platforms/ios/index.ts +55 -0
- package/src/platforms/ios/simulator.ts +177 -0
- package/src/platforms/platform-adapter.ts +11 -0
- package/src/platforms/platform-registry.ts +24 -0
- package/src/platforms/web/index.ts +95 -0
- package/src/process.ts +33 -0
- package/src/reporters/default-reporter.ts +149 -0
- package/src/reporters/junit-reporter.ts +179 -0
- package/src/utils.ts +12 -0
- package/tsconfig.json +16 -0
- package/tsconfig.lib.json +33 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertNativeRunnerConfig,
|
|
3
|
+
TestRunnerConfig,
|
|
4
|
+
} from '@react-native-harness/config';
|
|
5
|
+
import { type PlatformAdapter } from '../platform-adapter.js';
|
|
6
|
+
import {
|
|
7
|
+
getSimulatorStatus,
|
|
8
|
+
runSimulator,
|
|
9
|
+
stopSimulator,
|
|
10
|
+
} from './simulator.js';
|
|
11
|
+
import { isAppInstalled, runApp, killApp } from './build.js';
|
|
12
|
+
import { killWithAwait } from '../../process.js';
|
|
13
|
+
import { runMetro } from '../../bundlers/metro.js';
|
|
14
|
+
import { AppNotInstalledError } from '../../errors/errors.js';
|
|
15
|
+
|
|
16
|
+
const iosPlatformAdapter: PlatformAdapter = {
|
|
17
|
+
name: 'ios',
|
|
18
|
+
getEnvironment: async (runner: TestRunnerConfig) => {
|
|
19
|
+
assertNativeRunnerConfig(runner);
|
|
20
|
+
|
|
21
|
+
let shouldStopSimulator = false;
|
|
22
|
+
const simulatorStatus = await getSimulatorStatus(runner.deviceId);
|
|
23
|
+
const metroPromise = runMetro();
|
|
24
|
+
|
|
25
|
+
if (simulatorStatus === 'stopped') {
|
|
26
|
+
await runSimulator(runner.deviceId);
|
|
27
|
+
shouldStopSimulator = true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isInstalled = await isAppInstalled(runner.deviceId, runner.bundleId);
|
|
31
|
+
|
|
32
|
+
if (!isInstalled) {
|
|
33
|
+
throw new AppNotInstalledError(runner.deviceId, runner.bundleId, 'ios');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const metro = await metroPromise;
|
|
37
|
+
await runApp(runner.deviceId, runner.bundleId);
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
restart: async () => {
|
|
41
|
+
await runApp(runner.deviceId, runner.bundleId);
|
|
42
|
+
},
|
|
43
|
+
dispose: async () => {
|
|
44
|
+
await killApp(runner.deviceId, runner.bundleId);
|
|
45
|
+
if (shouldStopSimulator) {
|
|
46
|
+
await stopSimulator(runner.deviceId);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await killWithAwait(metro);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default iosPlatformAdapter;
|
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
): Promise<string | null> => {
|
|
8
|
+
try {
|
|
9
|
+
const { stdout } = await spawn('xcrun', [
|
|
10
|
+
'simctl',
|
|
11
|
+
'list',
|
|
12
|
+
'devices',
|
|
13
|
+
'--json',
|
|
14
|
+
]);
|
|
15
|
+
const devices = JSON.parse(stdout);
|
|
16
|
+
|
|
17
|
+
// Find the device across all iOS versions
|
|
18
|
+
for (const runtime in devices.devices) {
|
|
19
|
+
if (runtime.includes('iOS')) {
|
|
20
|
+
const runtimeDevices = devices.devices[runtime];
|
|
21
|
+
const device = runtimeDevices.find(
|
|
22
|
+
(d: any) => d.name === simulatorName
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (device) {
|
|
26
|
+
return device.udid;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return null;
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const getAvailableSimulators = async (): Promise<
|
|
38
|
+
Array<{ name: string; udid: string; runtime: string }>
|
|
39
|
+
> => {
|
|
40
|
+
try {
|
|
41
|
+
const { stdout } = await spawn('xcrun', [
|
|
42
|
+
'simctl',
|
|
43
|
+
'list',
|
|
44
|
+
'devices',
|
|
45
|
+
'--json',
|
|
46
|
+
]);
|
|
47
|
+
const devices = JSON.parse(stdout);
|
|
48
|
+
const simulators: Array<{
|
|
49
|
+
name: string;
|
|
50
|
+
udid: string;
|
|
51
|
+
runtime: string;
|
|
52
|
+
}> = [];
|
|
53
|
+
|
|
54
|
+
for (const runtime in devices.devices) {
|
|
55
|
+
if (runtime.includes('iOS')) {
|
|
56
|
+
const runtimeDevices = devices.devices[runtime];
|
|
57
|
+
runtimeDevices.forEach((device: any) => {
|
|
58
|
+
if (device.isAvailable) {
|
|
59
|
+
simulators.push({
|
|
60
|
+
name: device.name,
|
|
61
|
+
udid: device.udid,
|
|
62
|
+
runtime: runtime,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return simulators;
|
|
70
|
+
} catch {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const getSimulatorStatus = async (
|
|
76
|
+
simulatorName: string
|
|
77
|
+
): Promise<IOSSimulatorStatus> => {
|
|
78
|
+
try {
|
|
79
|
+
const { stdout } = await spawn('xcrun', [
|
|
80
|
+
'simctl',
|
|
81
|
+
'list',
|
|
82
|
+
'devices',
|
|
83
|
+
'--json',
|
|
84
|
+
]);
|
|
85
|
+
const devices = JSON.parse(stdout);
|
|
86
|
+
|
|
87
|
+
for (const runtime in devices.devices) {
|
|
88
|
+
if (runtime.includes('iOS')) {
|
|
89
|
+
const runtimeDevices = devices.devices[runtime];
|
|
90
|
+
const device = runtimeDevices.find(
|
|
91
|
+
(d: any) => d.name === simulatorName
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (device) {
|
|
95
|
+
switch (device.state) {
|
|
96
|
+
case 'Booted':
|
|
97
|
+
return 'running';
|
|
98
|
+
case 'Booting':
|
|
99
|
+
return 'loading';
|
|
100
|
+
default:
|
|
101
|
+
return 'stopped';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return 'stopped';
|
|
108
|
+
} catch {
|
|
109
|
+
return 'stopped';
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const runSimulator = async (name: string): Promise<void> => {
|
|
114
|
+
const deviceId = await getSimulatorDeviceId(name);
|
|
115
|
+
|
|
116
|
+
if (!deviceId) {
|
|
117
|
+
throw new Error('Simulator not found');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
await spawn('xcrun', ['simctl', 'boot', deviceId]);
|
|
122
|
+
} catch (bootError: any) {
|
|
123
|
+
// Ignore if simulator is already booted
|
|
124
|
+
if (
|
|
125
|
+
!bootError.stderr?.includes(
|
|
126
|
+
'Unable to boot device in current state: Booted'
|
|
127
|
+
)
|
|
128
|
+
) {
|
|
129
|
+
throw bootError;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
await spawn('open', ['-a', 'Simulator']);
|
|
134
|
+
|
|
135
|
+
let attempts = 0;
|
|
136
|
+
|
|
137
|
+
while (true) {
|
|
138
|
+
attempts++;
|
|
139
|
+
|
|
140
|
+
const status = await getSimulatorStatus(name);
|
|
141
|
+
|
|
142
|
+
if (status === 'running') {
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (attempts > 10) {
|
|
147
|
+
throw new Error('Simulator not running');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const stopSimulator = async (name: string): Promise<void> => {
|
|
155
|
+
const simulatorId = await getSimulatorDeviceId(name);
|
|
156
|
+
|
|
157
|
+
if (!simulatorId) {
|
|
158
|
+
return; // Already stopped
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
await stopSimulatorById(simulatorId);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const stopSimulatorById = async (simulatorId: string): Promise<void> => {
|
|
165
|
+
try {
|
|
166
|
+
await spawn('xcrun', ['simctl', 'shutdown', simulatorId]);
|
|
167
|
+
} catch (shutdownError: any) {
|
|
168
|
+
// Ignore if simulator is already shut down
|
|
169
|
+
if (
|
|
170
|
+
!shutdownError.stderr?.includes(
|
|
171
|
+
'Unable to shutdown device in current state: Shutdown'
|
|
172
|
+
)
|
|
173
|
+
) {
|
|
174
|
+
throw shutdownError;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { TestRunnerConfig, WebTestRunnerConfig, assertWebRunnerConfig } from '@react-native-harness/config';
|
|
2
|
+
import { logger } from '@react-native-harness/tools';
|
|
3
|
+
import { Browser, chromium, firefox, Page, webkit } from 'playwright';
|
|
4
|
+
import { PlatformAdapter } from '../platform-adapter.js';
|
|
5
|
+
import { runMetro } from '../../bundlers/metro.js';
|
|
6
|
+
|
|
7
|
+
const runBrowser = async (
|
|
8
|
+
url: string,
|
|
9
|
+
browserType: WebTestRunnerConfig['browser']
|
|
10
|
+
): Promise<{ browser: Browser; page: Page }> => {
|
|
11
|
+
// For now, we're only supporting Firefox, but this will be expanded
|
|
12
|
+
// to support other browsers based on the config
|
|
13
|
+
let browser: Browser;
|
|
14
|
+
|
|
15
|
+
switch (browserType) {
|
|
16
|
+
case 'firefox':
|
|
17
|
+
browser = await firefox.launch({
|
|
18
|
+
headless: false,
|
|
19
|
+
devtools: false,
|
|
20
|
+
args: [
|
|
21
|
+
'--no-sandbox',
|
|
22
|
+
'--disable-setuid-sandbox',
|
|
23
|
+
'--disable-dev-shm-usage',
|
|
24
|
+
'--disable-web-security',
|
|
25
|
+
'--allow-insecure-localhost',
|
|
26
|
+
'--ignore-certificate-errors',
|
|
27
|
+
],
|
|
28
|
+
ignoreDefaultArgs: ['--disable-extensions'],
|
|
29
|
+
});
|
|
30
|
+
break;
|
|
31
|
+
case 'chrome':
|
|
32
|
+
browser = await chromium.launch({
|
|
33
|
+
headless: false,
|
|
34
|
+
devtools: false,
|
|
35
|
+
});
|
|
36
|
+
break;
|
|
37
|
+
case 'safari':
|
|
38
|
+
browser = await webkit.launch({
|
|
39
|
+
headless: false,
|
|
40
|
+
devtools: false,
|
|
41
|
+
});
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`Unsupported browser type: ${browserType}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const context = await browser.newContext({
|
|
48
|
+
bypassCSP: true,
|
|
49
|
+
ignoreHTTPSErrors: true,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const page = await context.newPage();
|
|
53
|
+
|
|
54
|
+
await page.setViewportSize({ width: 1280, height: 720 });
|
|
55
|
+
|
|
56
|
+
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 60000 });
|
|
57
|
+
|
|
58
|
+
return { browser, page };
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const webPlatformAdapter: PlatformAdapter = {
|
|
62
|
+
name: 'web',
|
|
63
|
+
getEnvironment: async (runner: TestRunnerConfig) => {
|
|
64
|
+
assertWebRunnerConfig(runner);
|
|
65
|
+
|
|
66
|
+
logger.debug('Starting web environment');
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
logger.debug('Running metro');
|
|
71
|
+
const metro = await runMetro(true);
|
|
72
|
+
logger.debug('Metro running');
|
|
73
|
+
|
|
74
|
+
logger.debug(`Running browser: ${runner.browser}`);
|
|
75
|
+
const { browser, page } = await runBrowser('http://localhost:8081', runner.browser);
|
|
76
|
+
logger.debug('Browser running');
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
restart: async () => {
|
|
82
|
+
logger.debug('Reloading page');
|
|
83
|
+
await page.reload({ waitUntil: 'domcontentloaded', timeout: 60000 });
|
|
84
|
+
},
|
|
85
|
+
dispose: async () => {
|
|
86
|
+
logger.debug('Closing browser');
|
|
87
|
+
await browser.close();
|
|
88
|
+
|
|
89
|
+
metro.kill();
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export default webPlatformAdapter;
|
package/src/process.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { color, spinner } from '@react-native-harness/tools';
|
|
2
|
+
import type { TestSuiteResult, TestResult } from '@react-native-harness/bridge';
|
|
3
|
+
import { Reporter } from '@react-native-harness/config';
|
|
4
|
+
|
|
5
|
+
export const defaultReporter: Reporter = {
|
|
6
|
+
report: async (results) => {
|
|
7
|
+
const resultsSpinner = spinner();
|
|
8
|
+
resultsSpinner.start('Test Results');
|
|
9
|
+
|
|
10
|
+
for (const suite of results) {
|
|
11
|
+
resultsSpinner.message(formatSuiteResult(suite));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Summary
|
|
15
|
+
let totalPassed = 0,
|
|
16
|
+
totalFailed = 0,
|
|
17
|
+
totalSkipped = 0,
|
|
18
|
+
totalTodo = 0;
|
|
19
|
+
let totalDuration = 0;
|
|
20
|
+
|
|
21
|
+
for (const suite of results) {
|
|
22
|
+
const summary = getTestSummary(suite);
|
|
23
|
+
totalPassed += summary.passed;
|
|
24
|
+
totalFailed += summary.failed;
|
|
25
|
+
totalSkipped += summary.skipped;
|
|
26
|
+
totalTodo += summary.todo;
|
|
27
|
+
totalDuration += suite.duration || 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const summaryText = [
|
|
31
|
+
color.green(`${totalPassed} passed`),
|
|
32
|
+
color.red(`${totalFailed} failed`),
|
|
33
|
+
color.yellow(`${totalSkipped} skipped`),
|
|
34
|
+
color.blue(`${totalTodo} todo`),
|
|
35
|
+
].join(', ');
|
|
36
|
+
|
|
37
|
+
resultsSpinner.message(`Summary: ${summaryText}`);
|
|
38
|
+
resultsSpinner.message(`Total time: ${formatDuration(totalDuration)}`);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const formatDuration = (duration?: number): string => {
|
|
43
|
+
if (duration == null) return '';
|
|
44
|
+
return color.dim(` (${duration}ms)`);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const getStatusIcon = (status: string): string => {
|
|
48
|
+
switch (status) {
|
|
49
|
+
case 'passed':
|
|
50
|
+
return color.green('✓');
|
|
51
|
+
case 'failed':
|
|
52
|
+
return color.red('✗');
|
|
53
|
+
case 'skipped':
|
|
54
|
+
return color.yellow('○');
|
|
55
|
+
case 'todo':
|
|
56
|
+
return color.blue('◐');
|
|
57
|
+
default:
|
|
58
|
+
return '?';
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const formatTestResult = (test: TestResult, indent = ''): string => {
|
|
63
|
+
const icon = getStatusIcon(test.status);
|
|
64
|
+
const name = test.status === 'failed' ? color.red(test.name) : test.name;
|
|
65
|
+
const duration = formatDuration(test.duration);
|
|
66
|
+
|
|
67
|
+
let result = `${indent}${icon} ${name}${duration}`;
|
|
68
|
+
|
|
69
|
+
if (test.error) {
|
|
70
|
+
const errorLines = test.error.message?.split('\n') || [];
|
|
71
|
+
result +=
|
|
72
|
+
'\n' +
|
|
73
|
+
errorLines
|
|
74
|
+
.map((line: string) => `${indent} ${color.red(line)}`)
|
|
75
|
+
.join('\n');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const formatSuiteResult = (suite: TestSuiteResult, indent = ''): string => {
|
|
82
|
+
const icon = getStatusIcon(suite.status);
|
|
83
|
+
const name =
|
|
84
|
+
suite.status === 'failed' ? color.red(suite.name) : color.bold(suite.name);
|
|
85
|
+
const duration = formatDuration(suite.duration);
|
|
86
|
+
|
|
87
|
+
let result = `${indent}${icon} ${name}${duration}`;
|
|
88
|
+
|
|
89
|
+
if (suite.error) {
|
|
90
|
+
const errorLines = suite.error.message.split('\n');
|
|
91
|
+
result +=
|
|
92
|
+
'\n' +
|
|
93
|
+
errorLines
|
|
94
|
+
.map((line: string) => `${indent} ${color.red(line)}`)
|
|
95
|
+
.join('\n');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const childIndent = indent + ' ';
|
|
99
|
+
|
|
100
|
+
// Format tests
|
|
101
|
+
for (const test of suite.tests) {
|
|
102
|
+
result += '\n' + formatTestResult(test, childIndent);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Format nested suites
|
|
106
|
+
for (const childSuite of suite.suites) {
|
|
107
|
+
result += '\n' + formatSuiteResult(childSuite, childIndent);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return result;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const getTestSummary = (
|
|
114
|
+
suite: TestSuiteResult
|
|
115
|
+
): { passed: number; failed: number; skipped: number; todo: number } => {
|
|
116
|
+
let passed = 0,
|
|
117
|
+
failed = 0,
|
|
118
|
+
skipped = 0,
|
|
119
|
+
todo = 0;
|
|
120
|
+
|
|
121
|
+
// Count tests in current suite
|
|
122
|
+
for (const test of suite.tests) {
|
|
123
|
+
switch (test.status) {
|
|
124
|
+
case 'passed':
|
|
125
|
+
passed++;
|
|
126
|
+
break;
|
|
127
|
+
case 'failed':
|
|
128
|
+
failed++;
|
|
129
|
+
break;
|
|
130
|
+
case 'skipped':
|
|
131
|
+
skipped++;
|
|
132
|
+
break;
|
|
133
|
+
case 'todo':
|
|
134
|
+
todo++;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Count tests in nested suites
|
|
140
|
+
for (const childSuite of suite.suites) {
|
|
141
|
+
const childSummary = getTestSummary(childSuite);
|
|
142
|
+
passed += childSummary.passed;
|
|
143
|
+
failed += childSummary.failed;
|
|
144
|
+
skipped += childSummary.skipped;
|
|
145
|
+
todo += childSummary.todo;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return { passed, failed, skipped, todo };
|
|
149
|
+
};
|