@react-native-harness/platform-android 1.0.0 → 1.1.0-rc.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/dist/__tests__/adb.test.d.ts +2 -0
- package/dist/__tests__/adb.test.d.ts.map +1 -0
- package/dist/__tests__/adb.test.js +72 -0
- package/dist/__tests__/app-monitor.test.d.ts +2 -0
- package/dist/__tests__/app-monitor.test.d.ts.map +1 -0
- package/dist/__tests__/app-monitor.test.js +202 -0
- package/dist/__tests__/crash-parser.test.d.ts +2 -0
- package/dist/__tests__/crash-parser.test.d.ts.map +1 -0
- package/dist/__tests__/crash-parser.test.js +45 -0
- package/dist/adb.d.ts +6 -1
- package/dist/adb.d.ts.map +1 -1
- package/dist/adb.js +84 -18
- package/dist/app-monitor.d.ts +13 -0
- package/dist/app-monitor.d.ts.map +1 -0
- package/dist/app-monitor.js +358 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +6 -0
- package/dist/crash-parser.d.ts +11 -0
- package/dist/crash-parser.d.ts.map +1 -0
- package/dist/crash-parser.js +39 -0
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +16 -4
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/eslint.config.mjs +4 -1
- package/package.json +4 -4
- package/src/__tests__/adb.test.ts +89 -0
- package/src/__tests__/app-monitor.test.ts +273 -0
- package/src/__tests__/crash-parser.test.ts +52 -0
- package/src/adb.ts +111 -18
- package/src/app-monitor.ts +542 -0
- package/src/config.ts +10 -0
- package/src/crash-parser.ts +66 -0
- package/src/runner.ts +20 -4
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { escapeRegExp, getEmitter, logger, spawn, SubprocessError } from '@react-native-harness/tools';
|
|
2
|
+
import * as adb from './adb.js';
|
|
3
|
+
import { androidCrashParser } from './crash-parser.js';
|
|
4
|
+
const getLogcatArgs = (uid, fromTime) => ['logcat', '-v', 'threadtime', '-b', 'crash', `--uid=${uid}`, '-T', fromTime];
|
|
5
|
+
const MAX_RECENT_LOG_LINES = 200;
|
|
6
|
+
const MAX_RECENT_CRASH_ARTIFACTS = 10;
|
|
7
|
+
const CRASH_ARTIFACT_SETTLE_DELAY_MS = 100;
|
|
8
|
+
const startProcPattern = (bundleId) => new RegExp(`Start proc (\\d+):${escapeRegExp(bundleId)}(?:/|\\s)`);
|
|
9
|
+
const processPattern = (bundleId) => new RegExp(`Process:\\s*${escapeRegExp(bundleId)},\\s*PID:\\s*(\\d+)`);
|
|
10
|
+
const nativeCrashPattern = (bundleId) => new RegExp(`>>>\\s*${escapeRegExp(bundleId)}\\s*<<<`);
|
|
11
|
+
const processDiedPattern = (bundleId) => new RegExp(`Process\\s+${escapeRegExp(bundleId)}\\s+\\(pid\\s+(\\d+)\\)\\s+has\\s+died`, 'i');
|
|
12
|
+
const getSignal = (line) => {
|
|
13
|
+
const namedSignalMatch = line.match(/\b(SIG[A-Z0-9]+)\b/);
|
|
14
|
+
if (namedSignalMatch) {
|
|
15
|
+
return namedSignalMatch[1];
|
|
16
|
+
}
|
|
17
|
+
const signalNumberMatch = line.match(/signal\s+(\d+)/i);
|
|
18
|
+
if (signalNumberMatch) {
|
|
19
|
+
return `signal ${signalNumberMatch[1]}`;
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
};
|
|
23
|
+
const getAndroidLogLineCrashDetails = ({ line, bundleId, pid, }) => {
|
|
24
|
+
const fatalExceptionMatch = line.match(/FATAL EXCEPTION:\s*(.+)$/i);
|
|
25
|
+
const processMatch = line.match(processPattern(bundleId));
|
|
26
|
+
return {
|
|
27
|
+
source: 'logs',
|
|
28
|
+
summary: line.trim(),
|
|
29
|
+
signal: getSignal(line),
|
|
30
|
+
exceptionType: fatalExceptionMatch?.[1]?.trim(),
|
|
31
|
+
processName: processMatch ? bundleId : line.includes(bundleId) ? bundleId : undefined,
|
|
32
|
+
pid: pid ?? (processMatch ? Number(processMatch[1]) : undefined),
|
|
33
|
+
rawLines: [line],
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const CRASH_BLOCK_HEADER = '--------- beginning of crash';
|
|
37
|
+
const getLatestCrashBlock = (recentLogLines) => {
|
|
38
|
+
const lines = recentLogLines.map(({ line }) => line);
|
|
39
|
+
let latestCrashHeaderIndex = -1;
|
|
40
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
41
|
+
if (/FATAL EXCEPTION:|Process:\s+.+,\s+PID:/i.test(lines[index])) {
|
|
42
|
+
latestCrashHeaderIndex = index;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const blockStartIndex = Math.max(lines.lastIndexOf(CRASH_BLOCK_HEADER), latestCrashHeaderIndex);
|
|
47
|
+
if (blockStartIndex === -1) {
|
|
48
|
+
return lines;
|
|
49
|
+
}
|
|
50
|
+
return lines.slice(blockStartIndex);
|
|
51
|
+
};
|
|
52
|
+
const getCrashBlockForArtifact = ({ artifact, recentLogLines, }) => {
|
|
53
|
+
const targetIndex = recentLogLines.findIndex(({ line, occurredAt }) => line === artifact.triggerLine &&
|
|
54
|
+
(artifact.triggerOccurredAt === undefined ||
|
|
55
|
+
occurredAt === artifact.triggerOccurredAt));
|
|
56
|
+
if (targetIndex === -1) {
|
|
57
|
+
return artifact.rawLines ?? [];
|
|
58
|
+
}
|
|
59
|
+
let blockStartIndex = targetIndex;
|
|
60
|
+
for (let index = targetIndex; index >= 0; index -= 1) {
|
|
61
|
+
const { line } = recentLogLines[index];
|
|
62
|
+
if (line === CRASH_BLOCK_HEADER) {
|
|
63
|
+
blockStartIndex = index;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
let blockEndIndex = recentLogLines.length;
|
|
68
|
+
for (let index = targetIndex + 1; index < recentLogLines.length; index += 1) {
|
|
69
|
+
if (recentLogLines[index].line === CRASH_BLOCK_HEADER) {
|
|
70
|
+
blockEndIndex = index;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return recentLogLines
|
|
75
|
+
.slice(blockStartIndex, blockEndIndex)
|
|
76
|
+
.map(({ line }) => line);
|
|
77
|
+
};
|
|
78
|
+
const hydrateCrashArtifact = ({ artifact, recentLogLines, }) => {
|
|
79
|
+
const rawLines = getCrashBlockForArtifact({ artifact, recentLogLines });
|
|
80
|
+
if (rawLines.length === 0) {
|
|
81
|
+
return artifact;
|
|
82
|
+
}
|
|
83
|
+
const parsedDetails = androidCrashParser.parse({
|
|
84
|
+
contents: rawLines.join('\n'),
|
|
85
|
+
bundleId: artifact.processName ?? '',
|
|
86
|
+
pid: artifact.pid,
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
...artifact,
|
|
90
|
+
...parsedDetails,
|
|
91
|
+
artifactType: artifact.artifactType,
|
|
92
|
+
artifactPath: artifact.artifactPath,
|
|
93
|
+
rawLines,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const createCrashArtifact = ({ details, recentLogLines, }) => {
|
|
97
|
+
const occurredAt = Date.now();
|
|
98
|
+
const rawLines = getLatestCrashBlock(recentLogLines);
|
|
99
|
+
const triggerOccurredAt = [...recentLogLines]
|
|
100
|
+
.reverse()
|
|
101
|
+
.find(({ line }) => line === details.summary)?.occurredAt;
|
|
102
|
+
const contents = rawLines.length > 0
|
|
103
|
+
? rawLines.join('\n')
|
|
104
|
+
: (details.rawLines ?? []).join('\n');
|
|
105
|
+
const parsedDetails = details.processName !== undefined
|
|
106
|
+
? androidCrashParser.parse({
|
|
107
|
+
contents,
|
|
108
|
+
bundleId: details.processName,
|
|
109
|
+
pid: details.pid,
|
|
110
|
+
})
|
|
111
|
+
: details;
|
|
112
|
+
return {
|
|
113
|
+
...parsedDetails,
|
|
114
|
+
occurredAt,
|
|
115
|
+
triggerLine: details.summary ?? '',
|
|
116
|
+
triggerOccurredAt,
|
|
117
|
+
artifactType: 'logcat',
|
|
118
|
+
rawLines: rawLines.length > 0 ? rawLines : parsedDetails.rawLines ?? details.rawLines,
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
const persistCrashArtifact = ({ details, crashArtifactWriter, }) => {
|
|
122
|
+
if (!crashArtifactWriter || details.artifactType !== 'logcat') {
|
|
123
|
+
return details;
|
|
124
|
+
}
|
|
125
|
+
const artifactBody = details.rawLines?.join('\n');
|
|
126
|
+
if (!artifactBody) {
|
|
127
|
+
return details;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
...details,
|
|
131
|
+
artifactPath: crashArtifactWriter.persistArtifact({
|
|
132
|
+
artifactKind: details.artifactType,
|
|
133
|
+
source: {
|
|
134
|
+
kind: 'text',
|
|
135
|
+
fileName: 'logcat.txt',
|
|
136
|
+
text: `${artifactBody}\n`,
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
const getLatestCrashArtifact = ({ crashArtifacts, recentLogLines, processName, pid, occurredAt, }) => {
|
|
142
|
+
const matchingByPid = pid
|
|
143
|
+
? crashArtifacts.filter((artifact) => artifact.pid === pid)
|
|
144
|
+
: [];
|
|
145
|
+
const matchingByProcess = processName
|
|
146
|
+
? crashArtifacts.filter((artifact) => artifact.processName === processName)
|
|
147
|
+
: [];
|
|
148
|
+
const candidates = matchingByPid.length > 0
|
|
149
|
+
? matchingByPid
|
|
150
|
+
: matchingByProcess.length > 0
|
|
151
|
+
? matchingByProcess
|
|
152
|
+
: crashArtifacts;
|
|
153
|
+
const sortedCandidates = [...candidates].sort((left, right) => Math.abs(left.occurredAt - occurredAt) - Math.abs(right.occurredAt - occurredAt));
|
|
154
|
+
const artifact = sortedCandidates[0];
|
|
155
|
+
if (!artifact) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return hydrateCrashArtifact({
|
|
159
|
+
artifact,
|
|
160
|
+
recentLogLines,
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
const createAndroidLogEvent = (line, bundleId) => {
|
|
164
|
+
const startMatch = line.match(startProcPattern(bundleId));
|
|
165
|
+
if (startMatch) {
|
|
166
|
+
return {
|
|
167
|
+
type: 'app_started',
|
|
168
|
+
pid: Number(startMatch[1]),
|
|
169
|
+
source: 'logs',
|
|
170
|
+
line,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const processMatch = line.match(processPattern(bundleId));
|
|
174
|
+
if (processMatch) {
|
|
175
|
+
return {
|
|
176
|
+
type: 'possible_crash',
|
|
177
|
+
pid: Number(processMatch[1]),
|
|
178
|
+
source: 'logs',
|
|
179
|
+
line,
|
|
180
|
+
crashDetails: getAndroidLogLineCrashDetails({
|
|
181
|
+
line,
|
|
182
|
+
bundleId,
|
|
183
|
+
pid: Number(processMatch[1]),
|
|
184
|
+
}),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
if (nativeCrashPattern(bundleId).test(line)) {
|
|
188
|
+
return {
|
|
189
|
+
type: 'possible_crash',
|
|
190
|
+
source: 'logs',
|
|
191
|
+
line,
|
|
192
|
+
crashDetails: getAndroidLogLineCrashDetails({
|
|
193
|
+
line,
|
|
194
|
+
bundleId,
|
|
195
|
+
}),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const diedMatch = line.match(processDiedPattern(bundleId));
|
|
199
|
+
if (diedMatch) {
|
|
200
|
+
return {
|
|
201
|
+
type: 'app_exited',
|
|
202
|
+
pid: Number(diedMatch[1]),
|
|
203
|
+
source: 'logs',
|
|
204
|
+
line,
|
|
205
|
+
crashDetails: getAndroidLogLineCrashDetails({
|
|
206
|
+
line,
|
|
207
|
+
bundleId,
|
|
208
|
+
pid: Number(diedMatch[1]),
|
|
209
|
+
}),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
if (line.includes(bundleId) &&
|
|
213
|
+
/fatal|crash|signal 11|signal 6|backtrace/i.test(line)) {
|
|
214
|
+
return {
|
|
215
|
+
type: 'possible_crash',
|
|
216
|
+
source: 'logs',
|
|
217
|
+
line,
|
|
218
|
+
crashDetails: getAndroidLogLineCrashDetails({
|
|
219
|
+
line,
|
|
220
|
+
bundleId,
|
|
221
|
+
}),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
};
|
|
226
|
+
export const createAndroidAppMonitor = ({ adbId, bundleId, appUid, crashArtifactWriter, }) => {
|
|
227
|
+
const emitter = getEmitter();
|
|
228
|
+
let isStarted = false;
|
|
229
|
+
let logcatProcess = null;
|
|
230
|
+
let logTask = null;
|
|
231
|
+
let recentLogLines = [];
|
|
232
|
+
let recentCrashArtifacts = [];
|
|
233
|
+
const emit = (event) => {
|
|
234
|
+
emitter.emit(event);
|
|
235
|
+
};
|
|
236
|
+
const recordLogLine = (line) => {
|
|
237
|
+
recentLogLines = [...recentLogLines, { line, occurredAt: Date.now() }].slice(-MAX_RECENT_LOG_LINES);
|
|
238
|
+
};
|
|
239
|
+
const recordCrashArtifact = (details) => {
|
|
240
|
+
if (!details) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
recentCrashArtifacts = [
|
|
244
|
+
...recentCrashArtifacts,
|
|
245
|
+
createCrashArtifact({
|
|
246
|
+
details,
|
|
247
|
+
recentLogLines,
|
|
248
|
+
}),
|
|
249
|
+
].slice(-MAX_RECENT_CRASH_ARTIFACTS);
|
|
250
|
+
};
|
|
251
|
+
const stopProcess = async (child) => {
|
|
252
|
+
if (!child) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
(await child.nodeChildProcess).kill();
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
// Ignore termination failures for background monitors.
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
const startLogcat = async () => {
|
|
263
|
+
const logcatTimestamp = await adb.getLogcatTimestamp(adbId);
|
|
264
|
+
logcatProcess = spawn('adb', ['-s', adbId, ...getLogcatArgs(appUid, logcatTimestamp)], {
|
|
265
|
+
stdout: 'pipe',
|
|
266
|
+
stderr: 'pipe',
|
|
267
|
+
});
|
|
268
|
+
const currentProcess = logcatProcess;
|
|
269
|
+
if (!currentProcess) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
logTask = (async () => {
|
|
273
|
+
try {
|
|
274
|
+
for await (const line of currentProcess) {
|
|
275
|
+
recordLogLine(line);
|
|
276
|
+
emit({ type: 'log', source: 'logs', line });
|
|
277
|
+
const event = createAndroidLogEvent(line, bundleId);
|
|
278
|
+
if (event) {
|
|
279
|
+
if (event.type === 'possible_crash' || event.type === 'app_exited') {
|
|
280
|
+
recordCrashArtifact(event.crashDetails);
|
|
281
|
+
}
|
|
282
|
+
emit(event);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
if (!(error instanceof SubprocessError && error.signalName === 'SIGTERM')) {
|
|
288
|
+
logger.debug('Android logcat monitor stopped', error);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
})();
|
|
292
|
+
};
|
|
293
|
+
const start = async () => {
|
|
294
|
+
if (isStarted) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
await startLogcat();
|
|
299
|
+
isStarted = true;
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
const currentProcess = logcatProcess;
|
|
303
|
+
const currentTask = logTask;
|
|
304
|
+
logcatProcess = null;
|
|
305
|
+
logTask = null;
|
|
306
|
+
await stopProcess(currentProcess);
|
|
307
|
+
await currentTask;
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
const stop = async () => {
|
|
312
|
+
if (!isStarted) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
isStarted = false;
|
|
316
|
+
const currentProcess = logcatProcess;
|
|
317
|
+
const currentTask = logTask;
|
|
318
|
+
logcatProcess = null;
|
|
319
|
+
logTask = null;
|
|
320
|
+
await stopProcess(currentProcess);
|
|
321
|
+
await currentTask;
|
|
322
|
+
};
|
|
323
|
+
const dispose = async () => {
|
|
324
|
+
await stop();
|
|
325
|
+
emitter.clearAllListeners();
|
|
326
|
+
recentLogLines = [];
|
|
327
|
+
recentCrashArtifacts = [];
|
|
328
|
+
};
|
|
329
|
+
const addListener = (listener) => {
|
|
330
|
+
emitter.addListener(listener);
|
|
331
|
+
};
|
|
332
|
+
const removeListener = (listener) => {
|
|
333
|
+
emitter.removeListener(listener);
|
|
334
|
+
};
|
|
335
|
+
return {
|
|
336
|
+
start,
|
|
337
|
+
stop,
|
|
338
|
+
dispose,
|
|
339
|
+
addListener,
|
|
340
|
+
removeListener,
|
|
341
|
+
getCrashDetails: async (options) => {
|
|
342
|
+
await new Promise((resolve) => setTimeout(resolve, CRASH_ARTIFACT_SETTLE_DELAY_MS));
|
|
343
|
+
const details = getLatestCrashArtifact({
|
|
344
|
+
crashArtifacts: recentCrashArtifacts,
|
|
345
|
+
recentLogLines,
|
|
346
|
+
...options,
|
|
347
|
+
});
|
|
348
|
+
if (!details) {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
return persistCrashArtifact({
|
|
352
|
+
details,
|
|
353
|
+
crashArtifactWriter,
|
|
354
|
+
});
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
export { createAndroidLogEvent };
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
export declare const AndroidAppLaunchOptionsSchema: z.ZodObject<{
|
|
3
|
+
extras: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber]>>>;
|
|
4
|
+
}, "strip", z.ZodTypeAny, {
|
|
5
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
6
|
+
}, {
|
|
7
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
8
|
+
}>;
|
|
2
9
|
export declare const AndroidEmulatorAVDConfigSchema: z.ZodObject<{
|
|
3
10
|
apiLevel: z.ZodNumber;
|
|
4
11
|
profile: z.ZodString;
|
|
@@ -170,6 +177,13 @@ export declare const AndroidPlatformConfigSchema: z.ZodObject<{
|
|
|
170
177
|
}>]>;
|
|
171
178
|
bundleId: z.ZodString;
|
|
172
179
|
activityName: z.ZodDefault<z.ZodString>;
|
|
180
|
+
appLaunchOptions: z.ZodOptional<z.ZodObject<{
|
|
181
|
+
extras: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber]>>>;
|
|
182
|
+
}, "strip", z.ZodTypeAny, {
|
|
183
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
184
|
+
}, {
|
|
185
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
186
|
+
}>>;
|
|
173
187
|
}, "strip", z.ZodTypeAny, {
|
|
174
188
|
name: string;
|
|
175
189
|
device: {
|
|
@@ -188,6 +202,9 @@ export declare const AndroidPlatformConfigSchema: z.ZodObject<{
|
|
|
188
202
|
};
|
|
189
203
|
bundleId: string;
|
|
190
204
|
activityName: string;
|
|
205
|
+
appLaunchOptions?: {
|
|
206
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
207
|
+
} | undefined;
|
|
191
208
|
}, {
|
|
192
209
|
name: string;
|
|
193
210
|
device: {
|
|
@@ -206,11 +223,15 @@ export declare const AndroidPlatformConfigSchema: z.ZodObject<{
|
|
|
206
223
|
};
|
|
207
224
|
bundleId: string;
|
|
208
225
|
activityName?: string | undefined;
|
|
226
|
+
appLaunchOptions?: {
|
|
227
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
228
|
+
} | undefined;
|
|
209
229
|
}>;
|
|
210
230
|
export type AndroidEmulator = z.infer<typeof AndroidEmulatorSchema>;
|
|
211
231
|
export type PhysicalAndroidDevice = z.infer<typeof PhysicalAndroidDeviceSchema>;
|
|
212
232
|
export type AndroidDevice = z.infer<typeof AndroidDeviceSchema>;
|
|
213
233
|
export type AndroidPlatformConfig = z.infer<typeof AndroidPlatformConfigSchema>;
|
|
234
|
+
export type AndroidAppLaunchOptions = z.infer<typeof AndroidAppLaunchOptionsSchema>;
|
|
214
235
|
export type AndroidEmulatorAVDConfig = z.infer<typeof AndroidEmulatorAVDConfigSchema>;
|
|
215
236
|
export declare const isAndroidDeviceEmulator: (device: AndroidDevice) => device is AndroidEmulator;
|
|
216
237
|
export declare const isAndroidDevicePhysical: (device: AndroidDevice) => device is PhysicalAndroidDevice;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;EAKzC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIhC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;EAItC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAG9B,CAAC;AAEH,eAAO,MAAM,2BAA2B
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,6BAA6B;;;;;;EAIxC,CAAC;AAEH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;EAKzC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIhC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;EAItC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAG9B,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAStC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAChF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAChF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC;AACF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAC5C,OAAO,8BAA8B,CACtC,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,QAAQ,aAAa,KACpB,MAAM,IAAI,eAEZ,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,QAAQ,aAAa,KACpB,MAAM,IAAI,qBAEZ,CAAC;AAEF,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,IAAI,eAAe,CAInC;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,IAAI,qBAAqB,CAIzC"}
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
export const AndroidAppLaunchOptionsSchema = z.object({
|
|
3
|
+
extras: z
|
|
4
|
+
.record(z.union([z.string(), z.boolean(), z.number().int().safe()]))
|
|
5
|
+
.optional(),
|
|
6
|
+
});
|
|
2
7
|
export const AndroidEmulatorAVDConfigSchema = z.object({
|
|
3
8
|
apiLevel: z.number().min(1, 'API level is required'),
|
|
4
9
|
profile: z.string().min(1, 'Profile is required'),
|
|
@@ -27,6 +32,7 @@ export const AndroidPlatformConfigSchema = z.object({
|
|
|
27
32
|
.string()
|
|
28
33
|
.min(1, 'Activity name is required')
|
|
29
34
|
.default('.MainActivity'),
|
|
35
|
+
appLaunchOptions: AndroidAppLaunchOptionsSchema.optional(),
|
|
30
36
|
});
|
|
31
37
|
export const isAndroidDeviceEmulator = (device) => {
|
|
32
38
|
return device.type === 'emulator';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AppCrashDetails } from '@react-native-harness/platforms';
|
|
2
|
+
type ParseAndroidCrashReportOptions = {
|
|
3
|
+
contents: string;
|
|
4
|
+
bundleId: string;
|
|
5
|
+
pid?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const androidCrashParser: {
|
|
8
|
+
parse({ contents, bundleId, pid, }: ParseAndroidCrashReportOptions): AppCrashDetails;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=crash-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crash-parser.d.ts","sourceRoot":"","sources":["../src/crash-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGvE,KAAK,8BAA8B,GAAG;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AA4BF,eAAO,MAAM,kBAAkB;wCAK1B,8BAA8B,GAAG,eAAe;CAyBpD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { escapeRegExp } from '@react-native-harness/tools';
|
|
2
|
+
const getSignal = (contents) => {
|
|
3
|
+
const namedSignalMatch = contents.match(/\b(SIG[A-Z0-9]+)\b/);
|
|
4
|
+
if (namedSignalMatch) {
|
|
5
|
+
return namedSignalMatch[1];
|
|
6
|
+
}
|
|
7
|
+
const signalNumberMatch = contents.match(/signal\s+(\d+)/i);
|
|
8
|
+
if (signalNumberMatch) {
|
|
9
|
+
return `signal ${signalNumberMatch[1]}`;
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
};
|
|
13
|
+
const getStackTrace = (rawLines) => {
|
|
14
|
+
const frames = rawLines.filter((line) => /^\S.*(?:\s+at\s+|\s+#\d+\s+pc\s+)/.test(line.trim()) ||
|
|
15
|
+
/^\S.*AndroidRuntime:\s+at\s+/.test(line.trim()) ||
|
|
16
|
+
/^\S.*AndroidRuntime:\s+Caused by:/.test(line.trim()));
|
|
17
|
+
return frames.length > 0 ? frames : undefined;
|
|
18
|
+
};
|
|
19
|
+
export const androidCrashParser = {
|
|
20
|
+
parse({ contents, bundleId, pid, }) {
|
|
21
|
+
const rawLines = contents.split(/\r?\n/);
|
|
22
|
+
const processPattern = new RegExp(`Process:\\s*${escapeRegExp(bundleId)},\\s*PID:\\s*(\\d+)`);
|
|
23
|
+
const fatalExceptionMatch = contents.match(/FATAL EXCEPTION:\s*(.+)$/im);
|
|
24
|
+
const processMatch = contents.match(processPattern);
|
|
25
|
+
const runtimeExceptionLine = rawLines.find((line) => /AndroidRuntime: (?:java\.|kotlin\.|[\w$.]+(?:Exception|Error):)/.test(line));
|
|
26
|
+
const exceptionType = fatalExceptionMatch?.[1]?.trim() ??
|
|
27
|
+
runtimeExceptionLine?.match(/AndroidRuntime:\s+(.+)$/)?.[1]?.trim();
|
|
28
|
+
return {
|
|
29
|
+
source: 'logs',
|
|
30
|
+
summary: contents.trim(),
|
|
31
|
+
signal: getSignal(contents),
|
|
32
|
+
exceptionType,
|
|
33
|
+
processName: processMatch ? bundleId : contents.includes(bundleId) ? bundleId : undefined,
|
|
34
|
+
pid: pid ?? (processMatch ? Number(processMatch[1]) : undefined),
|
|
35
|
+
rawLines,
|
|
36
|
+
stackTrace: getStackTrace(rawLines),
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
};
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,qBAAqB,EACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,aAAa,CAAC;AAMrB,QAAA,MAAM,gBAAgB,GACpB,QAAQ,qBAAqB,EAC7B,eAAe,MAAM,KACpB,OAAO,CAAC,qBAAqB,CA+D/B,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
package/dist/runner.js
CHANGED
|
@@ -3,6 +3,7 @@ import { AndroidPlatformConfigSchema, } from './config.js';
|
|
|
3
3
|
import { getAdbId } from './adb-id.js';
|
|
4
4
|
import * as adb from './adb.js';
|
|
5
5
|
import { getDeviceName } from './utils.js';
|
|
6
|
+
import { createAndroidAppMonitor } from './app-monitor.js';
|
|
6
7
|
const getAndroidRunner = async (config, harnessConfig) => {
|
|
7
8
|
const parsedConfig = AndroidPlatformConfigSchema.parse(config);
|
|
8
9
|
const adbId = await getAdbId(parsedConfig.device);
|
|
@@ -17,24 +18,35 @@ const getAndroidRunner = async (config, harnessConfig) => {
|
|
|
17
18
|
adb.reversePort(adbId, 8081),
|
|
18
19
|
adb.reversePort(adbId, 8080),
|
|
19
20
|
adb.reversePort(adbId, harnessConfig.webSocketPort),
|
|
21
|
+
adb.setHideErrorDialogs(adbId, true),
|
|
20
22
|
]);
|
|
23
|
+
const appUid = await adb.getAppUid(adbId, parsedConfig.bundleId);
|
|
21
24
|
return {
|
|
22
|
-
startApp: async () => {
|
|
23
|
-
await adb.startApp(adbId, parsedConfig.bundleId, parsedConfig.activityName
|
|
25
|
+
startApp: async (options) => {
|
|
26
|
+
await adb.startApp(adbId, parsedConfig.bundleId, parsedConfig.activityName, options ??
|
|
27
|
+
parsedConfig.appLaunchOptions);
|
|
24
28
|
},
|
|
25
|
-
restartApp: async () => {
|
|
29
|
+
restartApp: async (options) => {
|
|
26
30
|
await adb.stopApp(adbId, parsedConfig.bundleId);
|
|
27
|
-
await adb.startApp(adbId, parsedConfig.bundleId, parsedConfig.activityName
|
|
31
|
+
await adb.startApp(adbId, parsedConfig.bundleId, parsedConfig.activityName, options ??
|
|
32
|
+
parsedConfig.appLaunchOptions);
|
|
28
33
|
},
|
|
29
34
|
stopApp: async () => {
|
|
30
35
|
await adb.stopApp(adbId, parsedConfig.bundleId);
|
|
31
36
|
},
|
|
32
37
|
dispose: async () => {
|
|
33
38
|
await adb.stopApp(adbId, parsedConfig.bundleId);
|
|
39
|
+
await adb.setHideErrorDialogs(adbId, false);
|
|
34
40
|
},
|
|
35
41
|
isAppRunning: async () => {
|
|
36
42
|
return await adb.isAppRunning(adbId, parsedConfig.bundleId);
|
|
37
43
|
},
|
|
44
|
+
createAppMonitor: (options) => createAndroidAppMonitor({
|
|
45
|
+
adbId,
|
|
46
|
+
bundleId: parsedConfig.bundleId,
|
|
47
|
+
appUid,
|
|
48
|
+
crashArtifactWriter: options?.crashArtifactWriter,
|
|
49
|
+
}),
|
|
38
50
|
};
|
|
39
51
|
};
|
|
40
52
|
export default getAndroidRunner;
|