@react-native-harness/jest 1.1.0-rc.2 → 1.1.0-rc.3
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/dist/__tests__/errors.test.js +6 -1
- package/dist/__tests__/harness-cache.test.js +1 -1
- package/dist/__tests__/harness.test.js +147 -3
- package/dist/__tests__/resource-lock.test.d.ts +2 -0
- package/dist/__tests__/resource-lock.test.d.ts.map +1 -0
- package/dist/__tests__/resource-lock.test.js +103 -0
- package/dist/action-hooks.d.ts +9 -0
- package/dist/action-hooks.d.ts.map +1 -0
- package/dist/action-hooks.js +36 -0
- package/dist/cli-args.test.d.ts +2 -0
- package/dist/cli-args.test.d.ts.map +1 -0
- package/dist/cli-args.test.js +1 -0
- package/dist/crash-monitor.d.ts +16 -0
- package/dist/crash-monitor.d.ts.map +1 -0
- package/dist/crash-monitor.js +75 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -2
- package/dist/event-mapper.d.ts +16 -0
- package/dist/event-mapper.d.ts.map +1 -0
- package/dist/event-mapper.js +120 -0
- package/dist/global-setup.d.ts +3 -0
- package/dist/global-setup.d.ts.map +1 -0
- package/dist/global-setup.js +60 -0
- package/dist/global-teardown.d.ts +3 -0
- package/dist/global-teardown.d.ts.map +1 -0
- package/dist/global-teardown.js +11 -0
- package/dist/harness-reporter.d.ts +8 -0
- package/dist/harness-reporter.d.ts.map +1 -0
- package/dist/harness-reporter.js +12 -0
- package/dist/harness.d.ts.map +1 -1
- package/dist/harness.js +478 -386
- package/dist/jest-options.d.ts +2 -0
- package/dist/jest-options.d.ts.map +1 -0
- package/dist/jest-options.js +1 -0
- package/dist/logs.d.ts +3 -0
- package/dist/logs.d.ts.map +1 -1
- package/dist/logs.js +9 -0
- package/dist/resource-lock.d.ts +25 -0
- package/dist/resource-lock.d.ts.map +1 -0
- package/dist/resource-lock.js +278 -0
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +11 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +7 -7
- package/src/__tests__/errors.test.ts +18 -6
- package/src/__tests__/harness-cache.test.ts +2 -2
- package/src/__tests__/harness.test.ts +254 -19
- package/src/__tests__/resource-lock.test.ts +138 -0
- package/src/action-hooks.ts +66 -0
- package/src/errors.ts +10 -4
- package/src/harness.ts +585 -445
- package/src/logs.ts +13 -3
- package/src/resource-lock.ts +450 -0
- package/src/setup.ts +21 -1
package/dist/harness.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { getBridgeServer, } from '@react-native-harness/bridge/server';
|
|
2
|
+
import { HARNESS_BRIDGE_PATH, } from '@react-native-harness/bridge';
|
|
2
3
|
import { getMetroInstance, isMetroCacheReusable, waitForMetroBackedAppReady, } from '@react-native-harness/bundler-metro';
|
|
3
4
|
import { createHarnessPluginManager, } from '@react-native-harness/plugins';
|
|
4
|
-
import { logger, createCrashArtifactWriter } from '@react-native-harness/tools';
|
|
5
|
-
import {
|
|
5
|
+
import { logger, createCrashArtifactWriter, getTimeoutSignal, raceAbortSignals, } from '@react-native-harness/tools';
|
|
6
|
+
import { PlatformReadyTimeoutError } from './errors.js';
|
|
6
7
|
import { createCrashSupervisor, } from './crash-supervisor.js';
|
|
7
8
|
import { createClientLogListener } from './client-log-handler.js';
|
|
8
9
|
import path from 'node:path';
|
|
9
|
-
import { logMetroCacheReused } from './logs.js';
|
|
10
|
+
import { logMetroCacheReused, logRunnerStarting, logRunnerStillWaitingInQueue, logRunnerWaitingInQueue, } from './logs.js';
|
|
11
|
+
import { createResourceLockManager } from './resource-lock.js';
|
|
10
12
|
const harnessLogger = logger.child('runtime');
|
|
13
|
+
const resourceLockManager = createResourceLockManager();
|
|
11
14
|
export const maybeLogMetroCacheReuse = (config, platform, projectRoot) => {
|
|
12
|
-
if (config.unstable__enableMetroCache &&
|
|
13
|
-
isMetroCacheReusable(projectRoot)) {
|
|
15
|
+
if (config.unstable__enableMetroCache && isMetroCacheReusable(projectRoot)) {
|
|
14
16
|
logMetroCacheReused(platform);
|
|
15
17
|
}
|
|
16
18
|
};
|
|
17
19
|
const createAbortError = () => new DOMException('The operation was aborted', 'AbortError');
|
|
20
|
+
const getDefaultResourceLockKey = (platform) => `${platform.platformId}:${platform.name}`;
|
|
18
21
|
const waitForAbort = (signal) => {
|
|
19
22
|
if (signal.aborted) {
|
|
20
23
|
return Promise.reject(signal.reason ?? createAbortError());
|
|
@@ -25,6 +28,22 @@ const waitForAbort = (signal) => {
|
|
|
25
28
|
}, { once: true });
|
|
26
29
|
});
|
|
27
30
|
};
|
|
31
|
+
const withPlatformReadyTimeout = async (options) => {
|
|
32
|
+
const timeoutSignal = getTimeoutSignal(options.timeout);
|
|
33
|
+
const combinedSignal = raceAbortSignals([options.signal, timeoutSignal]);
|
|
34
|
+
try {
|
|
35
|
+
return await options.work(combinedSignal);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error instanceof DOMException &&
|
|
39
|
+
error.name === 'AbortError' &&
|
|
40
|
+
timeoutSignal.aborted &&
|
|
41
|
+
!options.signal.aborted) {
|
|
42
|
+
throw new PlatformReadyTimeoutError(options.timeout);
|
|
43
|
+
}
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
28
47
|
export const waitForAppReady = async (options) => {
|
|
29
48
|
const { metroInstance, serverBridge, platformInstance, platformId, bundleStartTimeout, readyTimeout, maxAppRestarts, testFilePath, crashSupervisor, appLaunchOptions, launchApp = () => platformInstance.restartApp(appLaunchOptions), } = options;
|
|
30
49
|
const signal = options.signal ?? new AbortController().signal;
|
|
@@ -93,417 +112,490 @@ const getHarnessInternal = async (config, platform, projectRoot, signal) => {
|
|
|
93
112
|
platform,
|
|
94
113
|
};
|
|
95
114
|
harnessLogger.debug('creating Harness internals for runner=%s platform=%s', platform.name, platform.platformId);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
const resourceLockKey = await (platform.getResourceLockKey?.() ??
|
|
116
|
+
getDefaultResourceLockKey(platform));
|
|
117
|
+
let didWaitForResourceLock = false;
|
|
118
|
+
let lastStillWaitingLogAt = 0;
|
|
119
|
+
const resourceLease = await resourceLockManager.acquire(resourceLockKey, {
|
|
120
|
+
signal,
|
|
121
|
+
onWait: () => {
|
|
122
|
+
didWaitForResourceLock = true;
|
|
123
|
+
logRunnerWaitingInQueue(platform);
|
|
124
|
+
harnessLogger.debug('waiting in queue for runner=%s key=%s', platform.name, resourceLockKey);
|
|
125
|
+
},
|
|
126
|
+
onStillWaiting: (elapsedMs) => {
|
|
127
|
+
if (elapsedMs - lastStillWaitingLogAt < 5000) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
lastStillWaitingLogAt = elapsedMs;
|
|
131
|
+
logRunnerStillWaitingInQueue(platform);
|
|
132
|
+
harnessLogger.debug('still waiting in queue for runner=%s key=%s elapsedMs=%d', platform.name, resourceLockKey, elapsedMs);
|
|
133
|
+
},
|
|
104
134
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (pendingHookError !== undefined) {
|
|
119
|
-
const error = pendingHookError;
|
|
120
|
-
pendingHookError = undefined;
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const trackHook = (promise) => {
|
|
125
|
-
const trackedPromise = promise
|
|
126
|
-
.catch((error) => {
|
|
127
|
-
pendingHookError ??= error;
|
|
128
|
-
})
|
|
129
|
-
.finally(() => {
|
|
130
|
-
pendingHookPromises.delete(trackedPromise);
|
|
135
|
+
if (didWaitForResourceLock) {
|
|
136
|
+
logRunnerStarting(platform);
|
|
137
|
+
}
|
|
138
|
+
harnessLogger.debug('resource lock acquired for runner=%s key=%s', platform.name, resourceLockKey);
|
|
139
|
+
try {
|
|
140
|
+
maybeLogMetroCacheReuse(config, platform, projectRoot);
|
|
141
|
+
const pluginAbortController = new AbortController();
|
|
142
|
+
const pluginManager = createHarnessPluginManager({
|
|
143
|
+
plugins: (config.plugins ?? []),
|
|
144
|
+
projectRoot,
|
|
145
|
+
config,
|
|
146
|
+
runner: platform,
|
|
147
|
+
abortSignal: pluginAbortController.signal,
|
|
131
148
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
let currentRun = null;
|
|
150
|
+
let activeTestFilePath;
|
|
151
|
+
const pendingHookPromises = new Set();
|
|
152
|
+
let pendingHookError;
|
|
153
|
+
const getCurrentRunId = () => currentRun?.runId;
|
|
154
|
+
const toRelativeTestFilePath = (testFilePath) => testFilePath == null
|
|
155
|
+
? undefined
|
|
156
|
+
: path.relative(projectRoot, testFilePath);
|
|
157
|
+
const setActiveTestFilePath = (testFilePath) => {
|
|
158
|
+
activeTestFilePath = toRelativeTestFilePath(testFilePath);
|
|
159
|
+
};
|
|
160
|
+
const flushPendingHooks = async () => {
|
|
161
|
+
if (pendingHookPromises.size > 0) {
|
|
162
|
+
await Promise.allSettled([...pendingHookPromises]);
|
|
163
|
+
}
|
|
164
|
+
if (pendingHookError !== undefined) {
|
|
165
|
+
const error = pendingHookError;
|
|
166
|
+
pendingHookError = undefined;
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const trackHook = (promise) => {
|
|
171
|
+
const trackedPromise = promise
|
|
172
|
+
.catch((error) => {
|
|
173
|
+
pendingHookError ??= error;
|
|
174
|
+
})
|
|
175
|
+
.finally(() => {
|
|
176
|
+
pendingHookPromises.delete(trackedPromise);
|
|
177
|
+
});
|
|
178
|
+
pendingHookPromises.add(trackedPromise);
|
|
179
|
+
};
|
|
180
|
+
const scheduleHook = (name, payload) => {
|
|
181
|
+
trackHook(pluginManager.callHook(name, payload));
|
|
182
|
+
};
|
|
183
|
+
const serverBridge = await getBridgeServer({
|
|
184
|
+
noServer: true,
|
|
151
185
|
timeout: config.bridgeTimeout,
|
|
152
186
|
context,
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
187
|
+
});
|
|
188
|
+
harnessLogger.debug('starting Metro, platform runner, and bridge initialization');
|
|
189
|
+
harnessLogger.debug('bridge server initialized on Metro websocket path %s', HARNESS_BRIDGE_PATH);
|
|
190
|
+
const [metroInstance, platformInstance] = await (async () => {
|
|
191
|
+
try {
|
|
192
|
+
return await Promise.all([
|
|
193
|
+
getMetroInstance({
|
|
194
|
+
projectRoot,
|
|
195
|
+
harnessConfig: config,
|
|
196
|
+
websocketEndpoints: {
|
|
197
|
+
[HARNESS_BRIDGE_PATH]: serverBridge.ws,
|
|
198
|
+
},
|
|
199
|
+
}, signal).then((instance) => {
|
|
200
|
+
harnessLogger.debug('Metro initialized');
|
|
201
|
+
return instance;
|
|
202
|
+
}),
|
|
203
|
+
withPlatformReadyTimeout({
|
|
204
|
+
timeout: config.platformReadyTimeout,
|
|
205
|
+
signal,
|
|
206
|
+
work: async () => {
|
|
207
|
+
return await import(platform.runner)
|
|
208
|
+
.then((module) => module.default(platform.config, config, {
|
|
209
|
+
signal,
|
|
210
|
+
}))
|
|
211
|
+
.then((instance) => {
|
|
212
|
+
harnessLogger.debug('platform runner initialized');
|
|
213
|
+
return instance;
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
}),
|
|
217
|
+
]);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
await Promise.allSettled([
|
|
221
|
+
resourceLease.release(),
|
|
222
|
+
serverBridge.dispose(),
|
|
223
|
+
]);
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
})();
|
|
227
|
+
const crashArtifactWriter = createCrashArtifactWriter({
|
|
228
|
+
runnerName: platform.name,
|
|
229
|
+
platformId: platform.platformId,
|
|
230
|
+
});
|
|
231
|
+
const appMonitor = platformInstance.createAppMonitor({
|
|
232
|
+
crashArtifactWriter,
|
|
233
|
+
});
|
|
234
|
+
const appLaunchOptions = platform.config.appLaunchOptions;
|
|
235
|
+
const clientLogListener = createClientLogListener();
|
|
236
|
+
const bridgeEventListener = (event) => {
|
|
237
|
+
const runId = getCurrentRunId();
|
|
238
|
+
if (!runId) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
switch (event.type) {
|
|
242
|
+
case 'collection-started':
|
|
243
|
+
scheduleHook('collection:started', {
|
|
244
|
+
runId,
|
|
245
|
+
file: event.file,
|
|
246
|
+
});
|
|
247
|
+
break;
|
|
248
|
+
case 'collection-finished':
|
|
249
|
+
scheduleHook('collection:finished', {
|
|
250
|
+
runId,
|
|
251
|
+
file: event.file,
|
|
252
|
+
duration: event.duration,
|
|
253
|
+
totalTests: event.totalTests,
|
|
254
|
+
});
|
|
255
|
+
break;
|
|
256
|
+
case 'suite-started':
|
|
257
|
+
scheduleHook('suite:started', {
|
|
258
|
+
runId,
|
|
259
|
+
file: event.file,
|
|
260
|
+
name: event.name,
|
|
261
|
+
});
|
|
262
|
+
break;
|
|
263
|
+
case 'suite-finished':
|
|
264
|
+
scheduleHook('suite:finished', {
|
|
265
|
+
runId,
|
|
266
|
+
file: event.file,
|
|
267
|
+
name: event.name,
|
|
268
|
+
duration: event.duration,
|
|
269
|
+
status: event.status,
|
|
270
|
+
error: event.error,
|
|
271
|
+
});
|
|
272
|
+
break;
|
|
273
|
+
case 'test-started':
|
|
274
|
+
scheduleHook('test:started', {
|
|
275
|
+
runId,
|
|
276
|
+
file: event.file,
|
|
277
|
+
suite: event.suite,
|
|
278
|
+
name: event.name,
|
|
279
|
+
});
|
|
280
|
+
break;
|
|
281
|
+
case 'test-finished':
|
|
282
|
+
scheduleHook('test:finished', {
|
|
283
|
+
runId,
|
|
284
|
+
file: event.file,
|
|
285
|
+
suite: event.suite,
|
|
286
|
+
name: event.name,
|
|
287
|
+
duration: event.duration,
|
|
288
|
+
status: event.status,
|
|
289
|
+
error: event.error,
|
|
290
|
+
});
|
|
291
|
+
break;
|
|
292
|
+
case 'module-bundling-started':
|
|
293
|
+
scheduleHook('metro:bundle-started', {
|
|
294
|
+
runId,
|
|
295
|
+
target: 'module',
|
|
296
|
+
file: event.file,
|
|
297
|
+
});
|
|
298
|
+
break;
|
|
299
|
+
case 'module-bundling-finished':
|
|
300
|
+
scheduleHook('metro:bundle-finished', {
|
|
301
|
+
runId,
|
|
302
|
+
target: 'module',
|
|
303
|
+
file: event.file,
|
|
304
|
+
duration: event.duration,
|
|
305
|
+
});
|
|
306
|
+
break;
|
|
307
|
+
case 'module-bundling-failed':
|
|
308
|
+
scheduleHook('metro:bundle-failed', {
|
|
309
|
+
runId,
|
|
310
|
+
target: 'module',
|
|
311
|
+
file: event.file,
|
|
312
|
+
duration: event.duration,
|
|
313
|
+
error: event.error,
|
|
314
|
+
});
|
|
315
|
+
break;
|
|
316
|
+
case 'setup-file-bundling-started':
|
|
317
|
+
scheduleHook('metro:bundle-started', {
|
|
318
|
+
runId,
|
|
319
|
+
target: 'setupFile',
|
|
320
|
+
file: event.file,
|
|
321
|
+
setupType: event.setupType,
|
|
322
|
+
});
|
|
323
|
+
break;
|
|
324
|
+
case 'setup-file-bundling-finished':
|
|
325
|
+
scheduleHook('metro:bundle-finished', {
|
|
326
|
+
runId,
|
|
327
|
+
target: 'setupFile',
|
|
328
|
+
file: event.file,
|
|
329
|
+
setupType: event.setupType,
|
|
330
|
+
duration: event.duration,
|
|
331
|
+
});
|
|
332
|
+
break;
|
|
333
|
+
case 'setup-file-bundling-failed':
|
|
334
|
+
scheduleHook('metro:bundle-failed', {
|
|
335
|
+
runId,
|
|
336
|
+
target: 'setupFile',
|
|
337
|
+
file: event.file,
|
|
338
|
+
setupType: event.setupType,
|
|
339
|
+
duration: event.duration,
|
|
340
|
+
error: event.error,
|
|
341
|
+
});
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
const onMetroEvent = (event) => {
|
|
346
|
+
const runId = getCurrentRunId();
|
|
347
|
+
if (runId && event.type === 'client_log') {
|
|
348
|
+
scheduleHook('metro:client-log', {
|
|
225
349
|
runId,
|
|
226
|
-
|
|
227
|
-
|
|
350
|
+
level: event.level,
|
|
351
|
+
data: event.data,
|
|
228
352
|
});
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
const crashSupervisor = createCrashSupervisor({
|
|
356
|
+
appMonitor,
|
|
357
|
+
platformRunner: platformInstance,
|
|
358
|
+
});
|
|
359
|
+
const onReady = (device) => {
|
|
360
|
+
crashSupervisor.markReady();
|
|
361
|
+
const runId = getCurrentRunId();
|
|
362
|
+
if (!runId) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
scheduleHook('runtime:ready', {
|
|
366
|
+
runId,
|
|
367
|
+
device,
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
const onDisconnect = () => {
|
|
371
|
+
const runId = getCurrentRunId();
|
|
372
|
+
if (!runId) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
scheduleHook('runtime:disconnected', {
|
|
376
|
+
runId,
|
|
377
|
+
reason: 'bridge-disconnected',
|
|
378
|
+
});
|
|
379
|
+
};
|
|
380
|
+
const onAppMonitorEvent = (event) => {
|
|
381
|
+
const runId = getCurrentRunId();
|
|
382
|
+
if (!runId) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (event.type === 'app_started') {
|
|
386
|
+
scheduleHook('app:started', {
|
|
232
387
|
runId,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
388
|
+
testFile: activeTestFilePath,
|
|
389
|
+
pid: event.pid,
|
|
390
|
+
source: event.source,
|
|
391
|
+
line: event.line,
|
|
236
392
|
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (event.type === 'app_exited') {
|
|
396
|
+
scheduleHook('app:exited', {
|
|
240
397
|
runId,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
398
|
+
testFile: activeTestFilePath,
|
|
399
|
+
pid: event.pid,
|
|
400
|
+
source: event.source,
|
|
401
|
+
line: event.line,
|
|
402
|
+
isConfirmed: event.isConfirmed,
|
|
403
|
+
crashDetails: event.crashDetails,
|
|
245
404
|
});
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
if (event.type === 'possible_crash') {
|
|
408
|
+
scheduleHook('app:possible-crash', {
|
|
249
409
|
runId,
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
410
|
+
testFile: activeTestFilePath,
|
|
411
|
+
pid: event.pid,
|
|
412
|
+
source: event.source,
|
|
413
|
+
line: event.line,
|
|
414
|
+
isConfirmed: event.isConfirmed,
|
|
415
|
+
crashDetails: event.crashDetails,
|
|
253
416
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
serverBridge.on('ready', onReady);
|
|
420
|
+
serverBridge.on('disconnect', onDisconnect);
|
|
421
|
+
serverBridge.on('event', bridgeEventListener);
|
|
422
|
+
metroInstance.events.addListener(onMetroEvent);
|
|
423
|
+
appMonitor.addListener(onAppMonitorEvent);
|
|
424
|
+
harnessLogger.debug('registered runtime, bridge, and Metro listeners');
|
|
425
|
+
if (config.forwardClientLogs) {
|
|
426
|
+
metroInstance.events.addListener(clientLogListener);
|
|
427
|
+
harnessLogger.debug('client log forwarding enabled');
|
|
428
|
+
}
|
|
429
|
+
const dispose = async (reason = 'normal') => {
|
|
430
|
+
harnessLogger.debug('disposing Harness (reason=%s)', reason);
|
|
431
|
+
let hookError;
|
|
432
|
+
try {
|
|
433
|
+
await flushPendingHooks();
|
|
434
|
+
await pluginManager.callHook('harness:after-run', {
|
|
435
|
+
runId: currentRun?.runId,
|
|
436
|
+
reason,
|
|
437
|
+
summary: currentRun?.summary,
|
|
438
|
+
status: currentRun?.status,
|
|
439
|
+
error: currentRun?.error,
|
|
262
440
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
duration: event.duration,
|
|
271
|
-
error: event.error,
|
|
441
|
+
await flushPendingHooks();
|
|
442
|
+
await pluginManager.callHook('harness:before-dispose', {
|
|
443
|
+
runId: currentRun?.runId,
|
|
444
|
+
reason,
|
|
445
|
+
summary: currentRun?.summary,
|
|
446
|
+
status: currentRun?.status,
|
|
447
|
+
error: currentRun?.error,
|
|
272
448
|
});
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
if (!runId) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
if (event.type === 'app_started') {
|
|
317
|
-
scheduleHook('app:started', {
|
|
318
|
-
runId,
|
|
319
|
-
testFile: activeTestFilePath,
|
|
320
|
-
pid: event.pid,
|
|
321
|
-
source: event.source,
|
|
322
|
-
line: event.line,
|
|
323
|
-
});
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
if (event.type === 'app_exited') {
|
|
327
|
-
scheduleHook('app:exited', {
|
|
328
|
-
runId,
|
|
329
|
-
testFile: activeTestFilePath,
|
|
330
|
-
pid: event.pid,
|
|
331
|
-
source: event.source,
|
|
332
|
-
line: event.line,
|
|
333
|
-
isConfirmed: event.isConfirmed,
|
|
334
|
-
crashDetails: event.crashDetails,
|
|
335
|
-
});
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
if (event.type === 'possible_crash') {
|
|
339
|
-
scheduleHook('app:possible-crash', {
|
|
340
|
-
runId,
|
|
341
|
-
testFile: activeTestFilePath,
|
|
342
|
-
pid: event.pid,
|
|
343
|
-
source: event.source,
|
|
344
|
-
line: event.line,
|
|
345
|
-
isConfirmed: event.isConfirmed,
|
|
346
|
-
crashDetails: event.crashDetails,
|
|
347
|
-
});
|
|
449
|
+
await flushPendingHooks();
|
|
450
|
+
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
hookError = error;
|
|
453
|
+
}
|
|
454
|
+
if (config.forwardClientLogs) {
|
|
455
|
+
metroInstance.events.removeListener(clientLogListener);
|
|
456
|
+
}
|
|
457
|
+
metroInstance.events.removeListener(onMetroEvent);
|
|
458
|
+
appMonitor.removeListener(onAppMonitorEvent);
|
|
459
|
+
serverBridge.off('ready', onReady);
|
|
460
|
+
serverBridge.off('disconnect', onDisconnect);
|
|
461
|
+
serverBridge.off('event', bridgeEventListener);
|
|
462
|
+
let cleanupError;
|
|
463
|
+
try {
|
|
464
|
+
await Promise.all([
|
|
465
|
+
crashSupervisor.dispose(),
|
|
466
|
+
serverBridge.dispose(),
|
|
467
|
+
platformInstance.dispose(),
|
|
468
|
+
metroInstance.dispose(),
|
|
469
|
+
]);
|
|
470
|
+
}
|
|
471
|
+
catch (error) {
|
|
472
|
+
cleanupError = error;
|
|
473
|
+
}
|
|
474
|
+
finally {
|
|
475
|
+
await resourceLease.release();
|
|
476
|
+
pluginAbortController.abort();
|
|
477
|
+
}
|
|
478
|
+
harnessLogger.debug('Harness resources disposed');
|
|
479
|
+
if (hookError) {
|
|
480
|
+
throw hookError;
|
|
481
|
+
}
|
|
482
|
+
if (cleanupError) {
|
|
483
|
+
throw cleanupError;
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
if (signal.aborted) {
|
|
487
|
+
await dispose('abort');
|
|
488
|
+
throw new DOMException('The operation was aborted', 'AbortError');
|
|
348
489
|
}
|
|
349
|
-
};
|
|
350
|
-
serverBridge.on('ready', onReady);
|
|
351
|
-
serverBridge.on('disconnect', onDisconnect);
|
|
352
|
-
serverBridge.on('event', bridgeEventListener);
|
|
353
|
-
metroInstance.events.addListener(onMetroEvent);
|
|
354
|
-
appMonitor.addListener(onAppMonitorEvent);
|
|
355
|
-
harnessLogger.debug('registered runtime, bridge, and Metro listeners');
|
|
356
|
-
if (config.forwardClientLogs) {
|
|
357
|
-
metroInstance.events.addListener(clientLogListener);
|
|
358
|
-
harnessLogger.debug('client log forwarding enabled');
|
|
359
|
-
}
|
|
360
|
-
const dispose = async (reason = 'normal') => {
|
|
361
|
-
harnessLogger.debug('disposing Harness (reason=%s)', reason);
|
|
362
|
-
let hookError;
|
|
363
490
|
try {
|
|
491
|
+
await pluginManager.callHook('harness:before-creation', {
|
|
492
|
+
appLaunchOptions,
|
|
493
|
+
});
|
|
364
494
|
await flushPendingHooks();
|
|
365
|
-
await
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
status: currentRun?.status,
|
|
370
|
-
error: currentRun?.error,
|
|
495
|
+
await appMonitor.start();
|
|
496
|
+
harnessLogger.debug('app monitor started');
|
|
497
|
+
await pluginManager.callHook('harness:before-run', {
|
|
498
|
+
appLaunchOptions,
|
|
371
499
|
});
|
|
372
500
|
await flushPendingHooks();
|
|
373
501
|
}
|
|
374
502
|
catch (error) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
serverBridge.off('event', bridgeEventListener);
|
|
385
|
-
await Promise.all([
|
|
386
|
-
crashSupervisor.dispose(),
|
|
387
|
-
serverBridge.dispose(),
|
|
388
|
-
platformInstance.dispose(),
|
|
389
|
-
metroInstance.dispose(),
|
|
390
|
-
]);
|
|
391
|
-
pluginAbortController.abort();
|
|
392
|
-
harnessLogger.debug('Harness resources disposed');
|
|
393
|
-
if (hookError) {
|
|
394
|
-
throw hookError;
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
if (signal.aborted) {
|
|
398
|
-
await dispose('abort');
|
|
399
|
-
throw new DOMException('The operation was aborted', 'AbortError');
|
|
400
|
-
}
|
|
401
|
-
try {
|
|
402
|
-
await pluginManager.callHook('harness:before-creation', {
|
|
403
|
-
appLaunchOptions,
|
|
404
|
-
});
|
|
405
|
-
await appMonitor.start();
|
|
406
|
-
harnessLogger.debug('app monitor started');
|
|
407
|
-
}
|
|
408
|
-
catch (error) {
|
|
409
|
-
const runState = currentRun;
|
|
410
|
-
if (runState) {
|
|
411
|
-
runState.error = error;
|
|
412
|
-
currentRun = runState;
|
|
413
|
-
}
|
|
414
|
-
await dispose(error instanceof DOMException && error.name === 'AbortError' ? 'abort' : 'error');
|
|
415
|
-
throw error;
|
|
416
|
-
}
|
|
417
|
-
const ensureAppReady = async (testFilePath) => {
|
|
418
|
-
await flushPendingHooks();
|
|
419
|
-
setActiveTestFilePath(testFilePath);
|
|
420
|
-
crashSupervisor.setActiveTestFile(testFilePath);
|
|
421
|
-
harnessLogger.debug('ensuring app is ready for %s', testFilePath);
|
|
422
|
-
if (crashSupervisor.isReady() && (await platformInstance.isAppRunning())) {
|
|
423
|
-
harnessLogger.debug('reusing existing ready app for %s', testFilePath);
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
crashSupervisor.reset();
|
|
427
|
-
harnessLogger.debug('app not ready, waiting for launch and runtime readiness');
|
|
428
|
-
await waitForAppReady({
|
|
429
|
-
metroInstance,
|
|
430
|
-
serverBridge,
|
|
431
|
-
platformInstance: platformInstance,
|
|
432
|
-
platformId: platform.platformId,
|
|
433
|
-
bundleStartTimeout: config.bundleStartTimeout ?? 60000,
|
|
434
|
-
readyTimeout: config.bridgeTimeout,
|
|
435
|
-
maxAppRestarts: config.maxAppRestarts ?? 2,
|
|
436
|
-
testFilePath,
|
|
437
|
-
crashSupervisor,
|
|
438
|
-
appLaunchOptions,
|
|
439
|
-
});
|
|
440
|
-
await flushPendingHooks();
|
|
441
|
-
harnessLogger.debug('app is ready for %s', testFilePath);
|
|
442
|
-
};
|
|
443
|
-
const restart = async (testFilePath) => {
|
|
444
|
-
await flushPendingHooks();
|
|
445
|
-
await crashSupervisor.stop();
|
|
446
|
-
setActiveTestFilePath(testFilePath);
|
|
447
|
-
harnessLogger.debug('restarting app (testFile=%s mode=%s)', testFilePath ?? 'n/a', testFilePath ? 'stop-and-ensure-ready' : 'direct-restart');
|
|
448
|
-
if (testFilePath) {
|
|
449
|
-
harnessLogger.debug('stopping app before restart');
|
|
450
|
-
await platformInstance.stopApp();
|
|
451
|
-
}
|
|
452
|
-
else {
|
|
453
|
-
harnessLogger.debug('requesting direct app restart');
|
|
454
|
-
await platformInstance.restartApp(appLaunchOptions);
|
|
455
|
-
}
|
|
456
|
-
crashSupervisor.reset();
|
|
457
|
-
await crashSupervisor.start();
|
|
458
|
-
if (testFilePath) {
|
|
459
|
-
await ensureAppReady(testFilePath);
|
|
503
|
+
const runState = currentRun;
|
|
504
|
+
if (runState) {
|
|
505
|
+
runState.error = error;
|
|
506
|
+
currentRun = runState;
|
|
507
|
+
}
|
|
508
|
+
await dispose(error instanceof DOMException && error.name === 'AbortError'
|
|
509
|
+
? 'abort'
|
|
510
|
+
: 'error');
|
|
511
|
+
throw error;
|
|
460
512
|
}
|
|
461
|
-
|
|
462
|
-
harnessLogger.debug('restart completed');
|
|
463
|
-
};
|
|
464
|
-
return {
|
|
465
|
-
context,
|
|
466
|
-
runTests: async (path, options) => {
|
|
513
|
+
const ensureAppReady = async (testFilePath) => {
|
|
467
514
|
await flushPendingHooks();
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
515
|
+
setActiveTestFilePath(testFilePath);
|
|
516
|
+
crashSupervisor.setActiveTestFile(testFilePath);
|
|
517
|
+
harnessLogger.debug('ensuring app is ready for %s', testFilePath);
|
|
518
|
+
if (crashSupervisor.isReady() &&
|
|
519
|
+
(await platformInstance.isAppRunning())) {
|
|
520
|
+
harnessLogger.debug('reusing existing ready app for %s', testFilePath);
|
|
521
|
+
return;
|
|
472
522
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
523
|
+
crashSupervisor.reset();
|
|
524
|
+
harnessLogger.debug('app not ready, waiting for launch and runtime readiness');
|
|
525
|
+
await waitForAppReady({
|
|
526
|
+
metroInstance,
|
|
527
|
+
serverBridge,
|
|
528
|
+
platformInstance: platformInstance,
|
|
529
|
+
platformId: platform.platformId,
|
|
530
|
+
bundleStartTimeout: config.bundleStartTimeout ?? 60000,
|
|
531
|
+
readyTimeout: config.bridgeTimeout,
|
|
532
|
+
maxAppRestarts: config.maxAppRestarts ?? 2,
|
|
533
|
+
testFilePath,
|
|
534
|
+
crashSupervisor,
|
|
535
|
+
appLaunchOptions,
|
|
477
536
|
});
|
|
478
537
|
await flushPendingHooks();
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
restart,
|
|
483
|
-
dispose: () => dispose('normal'),
|
|
484
|
-
crashSupervisor,
|
|
485
|
-
callHook: async (name, payload) => {
|
|
538
|
+
harnessLogger.debug('app is ready for %s', testFilePath);
|
|
539
|
+
};
|
|
540
|
+
const restart = async (testFilePath) => {
|
|
486
541
|
await flushPendingHooks();
|
|
487
|
-
await
|
|
542
|
+
await crashSupervisor.stop();
|
|
543
|
+
setActiveTestFilePath(testFilePath);
|
|
544
|
+
harnessLogger.debug('restarting app (testFile=%s mode=%s)', testFilePath ?? 'n/a', testFilePath ? 'stop-and-ensure-ready' : 'direct-restart');
|
|
545
|
+
if (testFilePath) {
|
|
546
|
+
harnessLogger.debug('stopping app before restart');
|
|
547
|
+
await platformInstance.stopApp();
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
harnessLogger.debug('requesting direct app restart');
|
|
551
|
+
await platformInstance.restartApp(appLaunchOptions);
|
|
552
|
+
}
|
|
553
|
+
crashSupervisor.reset();
|
|
554
|
+
await crashSupervisor.start();
|
|
555
|
+
if (testFilePath) {
|
|
556
|
+
await ensureAppReady(testFilePath);
|
|
557
|
+
}
|
|
488
558
|
await flushPendingHooks();
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
559
|
+
harnessLogger.debug('restart completed');
|
|
560
|
+
};
|
|
561
|
+
return {
|
|
562
|
+
context,
|
|
563
|
+
runTests: async (path, options) => {
|
|
564
|
+
await flushPendingHooks();
|
|
565
|
+
activeTestFilePath = path;
|
|
566
|
+
const client = serverBridge.rpc.clients.at(-1);
|
|
567
|
+
if (!client) {
|
|
568
|
+
throw new Error('No client found');
|
|
569
|
+
}
|
|
570
|
+
harnessLogger.debug('running test file on client: %s', path);
|
|
571
|
+
const result = await client.runTests(path, {
|
|
572
|
+
...options,
|
|
573
|
+
runner: platform.runner,
|
|
574
|
+
});
|
|
575
|
+
await flushPendingHooks();
|
|
576
|
+
return result;
|
|
577
|
+
},
|
|
578
|
+
ensureAppReady,
|
|
579
|
+
restart,
|
|
580
|
+
dispose: () => dispose('normal'),
|
|
581
|
+
crashSupervisor,
|
|
582
|
+
callHook: async (name, payload) => {
|
|
583
|
+
await flushPendingHooks();
|
|
584
|
+
await pluginManager.callHook(name, payload);
|
|
585
|
+
await flushPendingHooks();
|
|
586
|
+
},
|
|
587
|
+
setRunState: (runState) => {
|
|
588
|
+
currentRun = runState;
|
|
589
|
+
},
|
|
590
|
+
getRunState: () => currentRun,
|
|
591
|
+
};
|
|
502
592
|
}
|
|
503
593
|
catch (error) {
|
|
504
|
-
|
|
505
|
-
throw new InitializationTimeoutError();
|
|
506
|
-
}
|
|
594
|
+
await resourceLease.release();
|
|
507
595
|
throw error;
|
|
508
596
|
}
|
|
509
597
|
};
|
|
598
|
+
export const getHarness = async (config, platform, projectRoot) => {
|
|
599
|
+
harnessLogger.debug('creating Harness with platform ready timeout %dms', config.platformReadyTimeout);
|
|
600
|
+
return await getHarnessInternal(config, platform, projectRoot, new AbortController().signal);
|
|
601
|
+
};
|