@andrii_kremlovskyi/playwright-traces-reader 4.1.1 → 4.2.2
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/README.md +98 -92
- package/dist/digestTrace.d.ts +2 -2
- package/dist/digestTrace.d.ts.map +1 -1
- package/dist/digestTrace.js +74 -49
- package/dist/digestTrace.js.map +1 -1
- package/dist/extractors.d.ts +16 -13
- package/dist/extractors.d.ts.map +1 -1
- package/dist/extractors.js +274 -172
- package/dist/extractors.js.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/parseTrace.d.ts +8 -5
- package/dist/parseTrace.d.ts.map +1 -1
- package/dist/parseTrace.js +83 -33
- package/dist/parseTrace.js.map +1 -1
- package/dist/traceCompatibility.d.ts +2 -2
- package/dist/traceCompatibility.d.ts.map +1 -1
- package/dist/traceCompatibility.js +69 -37
- package/dist/traceCompatibility.js.map +1 -1
- package/package.json +1 -1
package/dist/extractors.js
CHANGED
|
@@ -58,11 +58,11 @@ const parseTrace_1 = require("./parseTrace");
|
|
|
58
58
|
* Returns top-level steps (roots), each with nested children.
|
|
59
59
|
*/
|
|
60
60
|
async function getTestSteps(traceContext) {
|
|
61
|
-
const testTracePath = path.join(traceContext.traceDir,
|
|
61
|
+
const testTracePath = path.join(traceContext.traceDir, "test.trace");
|
|
62
62
|
const stepMap = new Map();
|
|
63
63
|
const roots = [];
|
|
64
64
|
for await (const event of (0, parseTrace_1.readNdjson)(testTracePath)) {
|
|
65
|
-
if (event.type ===
|
|
65
|
+
if (event.type === "before") {
|
|
66
66
|
const step = {
|
|
67
67
|
callId: event.callId,
|
|
68
68
|
parentId: event.parentId ?? null,
|
|
@@ -89,7 +89,7 @@ async function getTestSteps(traceContext) {
|
|
|
89
89
|
roots.push(step);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
else if (event.type ===
|
|
92
|
+
else if (event.type === "after") {
|
|
93
93
|
const step = stepMap.get(event.callId);
|
|
94
94
|
if (step) {
|
|
95
95
|
step.endTime = event.endTime;
|
|
@@ -116,28 +116,28 @@ async function getTestSteps(traceContext) {
|
|
|
116
116
|
*/
|
|
117
117
|
async function getTopLevelFailures(traceContext) {
|
|
118
118
|
const roots = await getTestSteps(traceContext);
|
|
119
|
-
return roots.filter(step => step.error !== null);
|
|
119
|
+
return roots.filter((step) => step.error !== null);
|
|
120
120
|
}
|
|
121
121
|
// ---------- getNetworkTraffic ----------
|
|
122
122
|
/**
|
|
123
123
|
* Reads all *.network files in the trace directory and returns structured
|
|
124
124
|
* network entries. Each entry is tagged as 'browser' (has pageref) or
|
|
125
|
-
* 'api' (has
|
|
125
|
+
* 'api' (has no pageref). Response and request bodies are
|
|
126
126
|
* resolved from the resources/ directory when a _sha1 reference exists.
|
|
127
127
|
*/
|
|
128
128
|
async function getNetworkTraffic(traceContext, options) {
|
|
129
129
|
const entries = [];
|
|
130
130
|
const actions = await getBrowserActions(traceContext);
|
|
131
131
|
const files = await fs.promises.readdir(traceContext.traceDir);
|
|
132
|
-
const networkFiles = files.filter(f => f.endsWith(
|
|
132
|
+
const networkFiles = files.filter((f) => f.endsWith(".network")).sort();
|
|
133
133
|
for (const networkFile of networkFiles) {
|
|
134
134
|
const filePath = path.join(traceContext.traceDir, networkFile);
|
|
135
135
|
for await (const event of (0, parseTrace_1.readNdjson)(filePath)) {
|
|
136
|
-
if (event.type !==
|
|
136
|
+
if (event.type !== "resource-snapshot")
|
|
137
137
|
continue;
|
|
138
138
|
const snap = event.snapshot;
|
|
139
139
|
const isBrowser = Boolean(snap.pageref);
|
|
140
|
-
const source = isBrowser ?
|
|
140
|
+
const source = isBrowser ? "browser" : "api";
|
|
141
141
|
// Resolve request body
|
|
142
142
|
let requestBody = null;
|
|
143
143
|
const postData = snap.request.postData;
|
|
@@ -145,13 +145,19 @@ async function getNetworkTraffic(traceContext, options) {
|
|
|
145
145
|
if (postData.text) {
|
|
146
146
|
requestBody = postData.text;
|
|
147
147
|
}
|
|
148
|
-
else
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
|
|
148
|
+
else {
|
|
149
|
+
const resourceFile = (0, parseTrace_1.normalizeTraceResourceReference)(postData._file, postData._sha1);
|
|
150
|
+
const legacyFallback = postData._sha1?.replace(/\.bin$/, "");
|
|
151
|
+
const buf = resourceFile
|
|
152
|
+
? ((await (0, parseTrace_1.getResourceBuffer)(traceContext, resourceFile)) ??
|
|
153
|
+
(legacyFallback
|
|
154
|
+
? await (0, parseTrace_1.getResourceBuffer)(traceContext, legacyFallback)
|
|
155
|
+
: null))
|
|
156
|
+
: null;
|
|
152
157
|
if (buf) {
|
|
153
|
-
if (postData.mimeType.includes(
|
|
154
|
-
|
|
158
|
+
if (postData.mimeType.includes("json") ||
|
|
159
|
+
postData.mimeType.includes("text")) {
|
|
160
|
+
requestBody = buf.toString("utf8");
|
|
155
161
|
}
|
|
156
162
|
else {
|
|
157
163
|
requestBody = `[binary: ${postData.mimeType}, ${buf.length} bytes]`;
|
|
@@ -162,11 +168,13 @@ async function getNetworkTraffic(traceContext, options) {
|
|
|
162
168
|
// Resolve response body
|
|
163
169
|
let responseBody = null;
|
|
164
170
|
const content = snap.response.content;
|
|
165
|
-
|
|
166
|
-
|
|
171
|
+
const responseResourceFile = (0, parseTrace_1.normalizeTraceResourceReference)(content._file, content._sha1);
|
|
172
|
+
if (responseResourceFile) {
|
|
173
|
+
const buf = await (0, parseTrace_1.getResourceBuffer)(traceContext, responseResourceFile);
|
|
167
174
|
if (buf) {
|
|
168
|
-
if (content.mimeType.includes(
|
|
169
|
-
|
|
175
|
+
if (content.mimeType.includes("json") ||
|
|
176
|
+
content.mimeType.includes("text")) {
|
|
177
|
+
responseBody = buf.toString("utf8");
|
|
170
178
|
}
|
|
171
179
|
else {
|
|
172
180
|
responseBody = `[binary: ${content.mimeType}, ${buf.length} bytes]`;
|
|
@@ -200,7 +208,7 @@ async function getNetworkTraffic(traceContext, options) {
|
|
|
200
208
|
}
|
|
201
209
|
async function getNetworkRequest(traceContext, requestId) {
|
|
202
210
|
const entries = await getNetworkTraffic(traceContext);
|
|
203
|
-
const entry = entries.find(candidate => candidate.id === requestId);
|
|
211
|
+
const entry = entries.find((candidate) => candidate.id === requestId);
|
|
204
212
|
if (!entry)
|
|
205
213
|
throw new Error(`Request '${requestId}' not found.`);
|
|
206
214
|
return entry;
|
|
@@ -209,13 +217,13 @@ async function getNetworkRequest(traceContext, requestId) {
|
|
|
209
217
|
async function getConsoleEntries(traceContext) {
|
|
210
218
|
const entries = [];
|
|
211
219
|
const files = await fs.promises.readdir(traceContext.traceDir);
|
|
212
|
-
const traceFiles = files.filter(f => f.endsWith(
|
|
220
|
+
const traceFiles = files.filter((f) => f.endsWith(".trace")).sort();
|
|
213
221
|
for (const traceFile of traceFiles) {
|
|
214
222
|
const filePath = path.join(traceContext.traceDir, traceFile);
|
|
215
223
|
for await (const event of (0, parseTrace_1.readNdjson)(filePath)) {
|
|
216
|
-
if (event.type ===
|
|
224
|
+
if (event.type === "console") {
|
|
217
225
|
entries.push({
|
|
218
|
-
source:
|
|
226
|
+
source: "browser",
|
|
219
227
|
level: event.messageType,
|
|
220
228
|
text: event.text,
|
|
221
229
|
timestamp: event.time,
|
|
@@ -224,13 +232,14 @@ async function getConsoleEntries(traceContext) {
|
|
|
224
232
|
});
|
|
225
233
|
continue;
|
|
226
234
|
}
|
|
227
|
-
if (event.type ===
|
|
228
|
-
const text = event.params.error?.error?.message ??
|
|
235
|
+
if (event.type === "event" && event.method === "pageError") {
|
|
236
|
+
const text = event.params.error?.error?.message ??
|
|
237
|
+
String(event.params.error?.value ?? "");
|
|
229
238
|
if (!text)
|
|
230
239
|
continue;
|
|
231
240
|
entries.push({
|
|
232
|
-
source:
|
|
233
|
-
level:
|
|
241
|
+
source: "browser",
|
|
242
|
+
level: "error",
|
|
234
243
|
text,
|
|
235
244
|
timestamp: event.time,
|
|
236
245
|
pageId: event.pageId ?? null,
|
|
@@ -238,15 +247,15 @@ async function getConsoleEntries(traceContext) {
|
|
|
238
247
|
});
|
|
239
248
|
continue;
|
|
240
249
|
}
|
|
241
|
-
if (event.type ===
|
|
242
|
-
let text = event.text?.trim() ??
|
|
250
|
+
if (event.type === "stdout" || event.type === "stderr") {
|
|
251
|
+
let text = event.text?.trim() ?? "";
|
|
243
252
|
if (!text && event.base64)
|
|
244
|
-
text = Buffer.from(event.base64,
|
|
253
|
+
text = Buffer.from(event.base64, "base64").toString("utf8").trim();
|
|
245
254
|
if (!text)
|
|
246
255
|
continue;
|
|
247
256
|
entries.push({
|
|
248
257
|
source: event.type,
|
|
249
|
-
level: event.type ===
|
|
258
|
+
level: event.type === "stderr" ? "error" : "info",
|
|
250
259
|
text,
|
|
251
260
|
timestamp: event.timestamp,
|
|
252
261
|
pageId: null,
|
|
@@ -267,7 +276,7 @@ async function getTraceIssues(traceContext) {
|
|
|
267
276
|
if (!step.error)
|
|
268
277
|
continue;
|
|
269
278
|
issues.push({
|
|
270
|
-
source:
|
|
279
|
+
source: "step",
|
|
271
280
|
message: step.error.message,
|
|
272
281
|
name: step.error.name,
|
|
273
282
|
stack: step.error.stack ?? null,
|
|
@@ -279,34 +288,40 @@ async function getTraceIssues(traceContext) {
|
|
|
279
288
|
});
|
|
280
289
|
}
|
|
281
290
|
const files = await fs.promises.readdir(traceContext.traceDir);
|
|
282
|
-
const traceFiles = files.filter(f => f.endsWith(
|
|
291
|
+
const traceFiles = files.filter((f) => f.endsWith(".trace")).sort();
|
|
283
292
|
for (const traceFile of traceFiles) {
|
|
284
293
|
const filePath = path.join(traceContext.traceDir, traceFile);
|
|
285
294
|
for await (const event of (0, parseTrace_1.readNdjson)(filePath)) {
|
|
286
|
-
if (event.type ===
|
|
295
|
+
if (event.type === "error") {
|
|
287
296
|
const firstFrame = event.stack?.[0];
|
|
288
297
|
issues.push({
|
|
289
|
-
source:
|
|
298
|
+
source: "trace",
|
|
290
299
|
message: event.message,
|
|
291
|
-
name:
|
|
300
|
+
name: "TraceError",
|
|
292
301
|
stack: formatStackFrames(event.stack),
|
|
293
302
|
timestamp: null,
|
|
294
303
|
callId: null,
|
|
295
304
|
title: null,
|
|
296
|
-
location: firstFrame
|
|
305
|
+
location: firstFrame
|
|
306
|
+
? {
|
|
307
|
+
file: firstFrame.file,
|
|
308
|
+
line: firstFrame.line,
|
|
309
|
+
column: firstFrame.column,
|
|
310
|
+
}
|
|
311
|
+
: null,
|
|
297
312
|
relatedAction: null,
|
|
298
313
|
});
|
|
299
314
|
continue;
|
|
300
315
|
}
|
|
301
|
-
if (event.type ===
|
|
316
|
+
if (event.type === "event" && event.method === "pageError") {
|
|
302
317
|
const pageError = event.params.error?.error;
|
|
303
|
-
const message = pageError?.message ?? String(event.params.error?.value ??
|
|
318
|
+
const message = pageError?.message ?? String(event.params.error?.value ?? "");
|
|
304
319
|
if (!message)
|
|
305
320
|
continue;
|
|
306
321
|
issues.push({
|
|
307
|
-
source:
|
|
322
|
+
source: "page",
|
|
308
323
|
message,
|
|
309
|
-
name: pageError?.name ??
|
|
324
|
+
name: pageError?.name ?? "PageError",
|
|
310
325
|
stack: pageError?.stack ?? null,
|
|
311
326
|
timestamp: event.time,
|
|
312
327
|
callId: null,
|
|
@@ -331,19 +346,20 @@ async function getTraceIssues(traceContext) {
|
|
|
331
346
|
// ---------- getAttachments ----------
|
|
332
347
|
async function getAttachments(traceContext) {
|
|
333
348
|
const files = await fs.promises.readdir(traceContext.traceDir);
|
|
334
|
-
const traceFiles = files.filter(f => f.endsWith(
|
|
349
|
+
const traceFiles = files.filter((f) => f.endsWith(".trace")).sort();
|
|
335
350
|
const actionTitleByCallId = new Map();
|
|
336
351
|
const attachments = [];
|
|
337
352
|
for (const traceFile of traceFiles) {
|
|
338
353
|
const filePath = path.join(traceContext.traceDir, traceFile);
|
|
339
354
|
for await (const event of (0, parseTrace_1.readNdjson)(filePath)) {
|
|
340
|
-
if (event.type ===
|
|
355
|
+
if (event.type === "before") {
|
|
341
356
|
actionTitleByCallId.set(event.callId, event.title);
|
|
342
357
|
continue;
|
|
343
358
|
}
|
|
344
|
-
if (event.type !==
|
|
359
|
+
if (event.type !== "after" || !event.attachments?.length)
|
|
345
360
|
continue;
|
|
346
361
|
for (const attachment of event.attachments) {
|
|
362
|
+
const resourceFile = (0, parseTrace_1.normalizeTraceResourceReference)(attachment.file, attachment.sha1);
|
|
347
363
|
attachments.push({
|
|
348
364
|
id: attachments.length + 1,
|
|
349
365
|
callId: event.callId,
|
|
@@ -352,8 +368,12 @@ async function getAttachments(traceContext) {
|
|
|
352
368
|
contentType: attachment.contentType,
|
|
353
369
|
path: attachment.path ?? null,
|
|
354
370
|
sha1: attachment.sha1 ?? null,
|
|
371
|
+
file: resourceFile,
|
|
355
372
|
base64: attachment.base64 ?? null,
|
|
356
|
-
size: await attachmentSize(traceContext,
|
|
373
|
+
size: await attachmentSize(traceContext, {
|
|
374
|
+
...attachment,
|
|
375
|
+
...(resourceFile ? { file: resourceFile } : {}),
|
|
376
|
+
}),
|
|
357
377
|
});
|
|
358
378
|
}
|
|
359
379
|
}
|
|
@@ -362,7 +382,7 @@ async function getAttachments(traceContext) {
|
|
|
362
382
|
}
|
|
363
383
|
async function extractAttachment(traceContext, attachmentId, outputPath) {
|
|
364
384
|
const attachments = await getAttachments(traceContext);
|
|
365
|
-
const attachment = attachments.find(entry => entry.id === attachmentId);
|
|
385
|
+
const attachment = attachments.find((entry) => entry.id === attachmentId);
|
|
366
386
|
if (!attachment)
|
|
367
387
|
throw new Error(`Attachment '${attachmentId}' not found.`);
|
|
368
388
|
const content = await attachmentContent(traceContext, attachment);
|
|
@@ -386,22 +406,28 @@ async function extractScreenshots(traceContext, outDir) {
|
|
|
386
406
|
const screenshots = [];
|
|
387
407
|
await fs.promises.mkdir(outDir, { recursive: true });
|
|
388
408
|
const files = await fs.promises.readdir(traceContext.traceDir);
|
|
389
|
-
const traceFiles = files
|
|
409
|
+
const traceFiles = files
|
|
410
|
+
.filter((f) => f.endsWith(".trace") && f !== "test.trace")
|
|
411
|
+
.sort();
|
|
390
412
|
let index = 0;
|
|
391
413
|
for (const traceFile of traceFiles) {
|
|
392
414
|
const filePath = path.join(traceContext.traceDir, traceFile);
|
|
393
415
|
for await (const event of (0, parseTrace_1.readNdjson)(filePath)) {
|
|
394
|
-
if (event.type !==
|
|
416
|
+
if (event.type !== "screencast-frame")
|
|
395
417
|
continue;
|
|
396
|
-
const
|
|
418
|
+
const resourceFile = (0, parseTrace_1.normalizeTraceResourceReference)(event.file, event.sha1);
|
|
419
|
+
if (!resourceFile)
|
|
420
|
+
continue;
|
|
421
|
+
const buf = await (0, parseTrace_1.getResourceBuffer)(traceContext, resourceFile);
|
|
397
422
|
if (!buf)
|
|
398
423
|
continue;
|
|
399
|
-
const ext =
|
|
400
|
-
const outFileName = `screenshot-${String(index).padStart(4,
|
|
424
|
+
const ext = resourceFile.endsWith(".jpeg") ? "jpeg" : "png";
|
|
425
|
+
const outFileName = `screenshot-${String(index).padStart(4, "0")}.${ext}`;
|
|
401
426
|
const savedPath = path.join(outDir, outFileName);
|
|
402
427
|
await fs.promises.writeFile(savedPath, buf);
|
|
403
428
|
screenshots.push({
|
|
404
|
-
sha1: event.sha1,
|
|
429
|
+
sha1: event.sha1 ?? resourceFile,
|
|
430
|
+
file: resourceFile,
|
|
405
431
|
timestamp: event.timestamp,
|
|
406
432
|
pageId: event.pageId,
|
|
407
433
|
width: event.width,
|
|
@@ -429,23 +455,27 @@ async function extractFailureScreenshots(traceContext, anchors, outDir) {
|
|
|
429
455
|
return [];
|
|
430
456
|
frames.sort((a, b) => a.timestamp - b.timestamp);
|
|
431
457
|
await fs.promises.mkdir(outDir, { recursive: true });
|
|
432
|
-
//
|
|
433
|
-
const
|
|
434
|
-
const ensureWritten = async (
|
|
435
|
-
const cached =
|
|
458
|
+
// Trace resource reference → relative file name (written once, referenced many times).
|
|
459
|
+
const writtenByResource = new Map();
|
|
460
|
+
const ensureWritten = async (resourceFile) => {
|
|
461
|
+
const cached = writtenByResource.get(resourceFile);
|
|
436
462
|
if (cached !== undefined)
|
|
437
463
|
return cached;
|
|
438
|
-
const buf = await (0, parseTrace_1.getResourceBuffer)(traceContext,
|
|
464
|
+
const buf = await (0, parseTrace_1.getResourceBuffer)(traceContext, resourceFile);
|
|
439
465
|
if (!buf)
|
|
440
466
|
return null;
|
|
441
|
-
const ext =
|
|
467
|
+
const ext = resourceFile.endsWith(".jpeg") ? "jpeg" : "png";
|
|
442
468
|
// The frame sha1 has the form `page@<pageId>-<wallMs>.<ext>`, so a fixed-prefix
|
|
443
469
|
// slice collides for every frame of the same page. Sanitize the full sha1 to a
|
|
444
470
|
// filesystem-safe stem so each distinct frame writes to a distinct file.
|
|
445
|
-
const safeStem =
|
|
471
|
+
const safeStem = path.posix
|
|
472
|
+
.basename(resourceFile)
|
|
473
|
+
.replace(/\.(jpeg|png)$/, "")
|
|
474
|
+
.replace(/[^a-zA-Z0-9]+/g, "-")
|
|
475
|
+
.replace(/^-|-$/g, "");
|
|
446
476
|
const fileName = `frame-${safeStem}.${ext}`;
|
|
447
477
|
await fs.promises.writeFile(path.join(outDir, fileName), buf);
|
|
448
|
-
|
|
478
|
+
writtenByResource.set(resourceFile, fileName);
|
|
449
479
|
return fileName;
|
|
450
480
|
};
|
|
451
481
|
const sets = [];
|
|
@@ -469,9 +499,9 @@ async function extractFailureScreenshots(traceContext, anchors, outDir) {
|
|
|
469
499
|
anchorCallId: anchor.callId,
|
|
470
500
|
anchorTitle: anchor.title,
|
|
471
501
|
anchorTimestamp: anchor.timestamp,
|
|
472
|
-
before: before ? await ensureWritten(before.
|
|
473
|
-
action: action ? await ensureWritten(action.
|
|
474
|
-
after: after ? await ensureWritten(after.
|
|
502
|
+
before: before ? await ensureWritten(before.file) : null,
|
|
503
|
+
action: action ? await ensureWritten(action.file) : null,
|
|
504
|
+
after: after ? await ensureWritten(after.file) : null,
|
|
475
505
|
});
|
|
476
506
|
}
|
|
477
507
|
return sets;
|
|
@@ -492,7 +522,7 @@ function buildSnapshotNodeList(html, cache) {
|
|
|
492
522
|
return cached;
|
|
493
523
|
const nodes = [];
|
|
494
524
|
function visit(n) {
|
|
495
|
-
if (typeof n ===
|
|
525
|
+
if (typeof n === "string") {
|
|
496
526
|
nodes.push(n);
|
|
497
527
|
return;
|
|
498
528
|
}
|
|
@@ -512,8 +542,22 @@ function buildSnapshotNodeList(html, cache) {
|
|
|
512
542
|
return nodes;
|
|
513
543
|
}
|
|
514
544
|
const VOID_TAGS = new Set([
|
|
515
|
-
|
|
516
|
-
|
|
545
|
+
"area",
|
|
546
|
+
"base",
|
|
547
|
+
"br",
|
|
548
|
+
"col",
|
|
549
|
+
"embed",
|
|
550
|
+
"hr",
|
|
551
|
+
"img",
|
|
552
|
+
"input",
|
|
553
|
+
"keygen",
|
|
554
|
+
"link",
|
|
555
|
+
"menuitem",
|
|
556
|
+
"meta",
|
|
557
|
+
"param",
|
|
558
|
+
"source",
|
|
559
|
+
"track",
|
|
560
|
+
"wbr",
|
|
517
561
|
]);
|
|
518
562
|
/** Maximum iframe nesting depth to inline before bailing out (cycle/runaway guard). */
|
|
519
563
|
const MAX_IFRAME_DEPTH = 10;
|
|
@@ -534,16 +578,16 @@ const MAX_IFRAME_DEPTH = 10;
|
|
|
534
578
|
*/
|
|
535
579
|
function resolveSnapshotNode(node, snapshotIndex, frameId, ctx) {
|
|
536
580
|
const frameHistory = ctx.frameHistory.get(frameId) ?? [];
|
|
537
|
-
if (typeof node ===
|
|
581
|
+
if (typeof node === "string") {
|
|
538
582
|
return escapeHtml(node);
|
|
539
583
|
}
|
|
540
584
|
if (!Array.isArray(node))
|
|
541
|
-
return
|
|
585
|
+
return "";
|
|
542
586
|
// Subtree reference: [[offset, nodeIdx]]
|
|
543
587
|
if (Array.isArray(node[0]) &&
|
|
544
588
|
node[0].length === 2 &&
|
|
545
|
-
typeof node[0][0] ===
|
|
546
|
-
typeof node[0][1] ===
|
|
589
|
+
typeof node[0][0] === "number" &&
|
|
590
|
+
typeof node[0][1] === "number") {
|
|
547
591
|
const [offset, nodeIdx] = node[0];
|
|
548
592
|
const refIndex = snapshotIndex - offset;
|
|
549
593
|
if (refIndex >= 0 && refIndex < frameHistory.length) {
|
|
@@ -557,21 +601,23 @@ function resolveSnapshotNode(node, snapshotIndex, frameId, ctx) {
|
|
|
557
601
|
}
|
|
558
602
|
// Element node: [tagName, attrs, ...children]
|
|
559
603
|
const [tagName, attrs, ...children] = node;
|
|
560
|
-
if (typeof tagName !==
|
|
561
|
-
return
|
|
604
|
+
if (typeof tagName !== "string")
|
|
605
|
+
return "";
|
|
562
606
|
const tag = tagName.toLowerCase();
|
|
563
|
-
if (tag ===
|
|
564
|
-
return
|
|
565
|
-
const safeAttrs = attrs && typeof attrs ===
|
|
607
|
+
if (tag === "script")
|
|
608
|
+
return ""; // not useful for AI analysis
|
|
609
|
+
const safeAttrs = attrs && typeof attrs === "object" && !Array.isArray(attrs)
|
|
566
610
|
? attrs
|
|
567
611
|
: {};
|
|
568
612
|
// Inline child frames: <iframe>/<frame> with src="/snapshot/<frameId>".
|
|
569
|
-
if (tag ===
|
|
570
|
-
const childFrameId = parseSnapshotFrameId(safeAttrs[
|
|
613
|
+
if (tag === "iframe" || tag === "frame") {
|
|
614
|
+
const childFrameId = parseSnapshotFrameId(safeAttrs["src"]);
|
|
571
615
|
const baseAttrs = Object.entries(safeAttrs)
|
|
572
|
-
.filter(([k]) => !k.startsWith(
|
|
616
|
+
.filter(([k]) => !k.startsWith("__playwright") &&
|
|
617
|
+
k.toLowerCase() !== "src" &&
|
|
618
|
+
k.toLowerCase() !== "srcdoc")
|
|
573
619
|
.map(([k, v]) => ` ${k}="${escapeAttr(String(v))}"`)
|
|
574
|
-
.join(
|
|
620
|
+
.join("");
|
|
575
621
|
if (childFrameId) {
|
|
576
622
|
const childHtml = renderChildFrame(childFrameId, ctx);
|
|
577
623
|
if (childHtml !== null) {
|
|
@@ -582,13 +628,15 @@ function resolveSnapshotNode(node, snapshotIndex, frameId, ctx) {
|
|
|
582
628
|
return `<${tag}${baseAttrs}></${tag}>`;
|
|
583
629
|
}
|
|
584
630
|
const attrStr = Object.entries(safeAttrs)
|
|
585
|
-
.filter(([k]) => !k.startsWith(
|
|
631
|
+
.filter(([k]) => !k.startsWith("__playwright"))
|
|
586
632
|
.map(([k, v]) => ` ${k}="${escapeAttr(String(v))}"`)
|
|
587
|
-
.join(
|
|
633
|
+
.join("");
|
|
588
634
|
if (VOID_TAGS.has(tag)) {
|
|
589
635
|
return `<${tag}${attrStr}>`;
|
|
590
636
|
}
|
|
591
|
-
const inner = children
|
|
637
|
+
const inner = children
|
|
638
|
+
.map((c) => resolveSnapshotNode(c, snapshotIndex, frameId, ctx))
|
|
639
|
+
.join("");
|
|
592
640
|
return `<${tag}${attrStr}>${inner}</${tag}>`;
|
|
593
641
|
}
|
|
594
642
|
/**
|
|
@@ -599,7 +647,7 @@ function resolveSnapshotNode(node, snapshotIndex, frameId, ctx) {
|
|
|
599
647
|
function parseSnapshotFrameId(src) {
|
|
600
648
|
if (!src)
|
|
601
649
|
return null;
|
|
602
|
-
const prefix =
|
|
650
|
+
const prefix = "/snapshot/";
|
|
603
651
|
if (!src.startsWith(prefix))
|
|
604
652
|
return null;
|
|
605
653
|
const id = src.substring(prefix.length).trim();
|
|
@@ -615,7 +663,9 @@ function renderChildFrame(childFrameId, ctx) {
|
|
|
615
663
|
return null; // cycle guard
|
|
616
664
|
if (ctx.stack.size >= MAX_IFRAME_DEPTH)
|
|
617
665
|
return null; // runaway depth guard
|
|
618
|
-
const entry = ctx.frameSnapshotsByName
|
|
666
|
+
const entry = ctx.frameSnapshotsByName
|
|
667
|
+
.get(childFrameId)
|
|
668
|
+
?.get(ctx.snapshotName);
|
|
619
669
|
if (!entry)
|
|
620
670
|
return null;
|
|
621
671
|
ctx.stack.add(childFrameId);
|
|
@@ -627,10 +677,10 @@ function renderChildFrame(childFrameId, ctx) {
|
|
|
627
677
|
}
|
|
628
678
|
}
|
|
629
679
|
function escapeHtml(s) {
|
|
630
|
-
return s.replace(/&/g,
|
|
680
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
631
681
|
}
|
|
632
682
|
function escapeAttr(s) {
|
|
633
|
-
return s.replace(/&/g,
|
|
683
|
+
return s.replace(/&/g, "&").replace(/"/g, """);
|
|
634
684
|
}
|
|
635
685
|
/**
|
|
636
686
|
* Extracts DOM snapshots from all browser context trace files (`[N]-trace.trace`
|
|
@@ -646,7 +696,9 @@ function escapeAttr(s) {
|
|
|
646
696
|
*/
|
|
647
697
|
async function getDomSnapshots(traceContext, options) {
|
|
648
698
|
const files = await fs.promises.readdir(traceContext.traceDir);
|
|
649
|
-
const traceFiles = files
|
|
699
|
+
const traceFiles = files
|
|
700
|
+
.filter((f) => f.endsWith(".trace") && f !== "test.trace")
|
|
701
|
+
.sort();
|
|
650
702
|
// Per-frame snapshot history: frameId → ordered list of raw html nodes (for back-refs).
|
|
651
703
|
const frameHistory = new Map();
|
|
652
704
|
// Per-frame snapshot lookup: frameId → snapshotName → entry (for inlining child frames).
|
|
@@ -658,10 +710,10 @@ async function getDomSnapshots(traceContext, options) {
|
|
|
658
710
|
for (const traceFile of traceFiles) {
|
|
659
711
|
const filePath = path.join(traceContext.traceDir, traceFile);
|
|
660
712
|
for await (const event of (0, parseTrace_1.readNdjson)(filePath)) {
|
|
661
|
-
if (event.type !==
|
|
713
|
+
if (event.type !== "frame-snapshot")
|
|
662
714
|
continue;
|
|
663
715
|
const snap = event.snapshot;
|
|
664
|
-
const { snapshotName, callId, frameId, frameUrl, pageId, viewport, timestamp, html, isMainFrame } = snap;
|
|
716
|
+
const { snapshotName, callId, frameId, frameUrl, pageId, viewport, timestamp, html, isMainFrame, } = snap;
|
|
665
717
|
// Append to per-frame history BEFORE anything else (so refs can point back to it)
|
|
666
718
|
if (!frameHistory.has(frameId))
|
|
667
719
|
frameHistory.set(frameId, []);
|
|
@@ -671,25 +723,36 @@ async function getDomSnapshots(traceContext, options) {
|
|
|
671
723
|
// Index by snapshotName so parent frames can inline this child by name.
|
|
672
724
|
if (!frameSnapshotsByName.has(frameId))
|
|
673
725
|
frameSnapshotsByName.set(frameId, new Map());
|
|
674
|
-
frameSnapshotsByName
|
|
726
|
+
frameSnapshotsByName
|
|
727
|
+
.get(frameId)
|
|
728
|
+
.set(snapshotName, { html, historyIndex: snapshotIndex });
|
|
675
729
|
if (!isMainFrame)
|
|
676
730
|
continue; // child frames are only inlined, never top-level entries
|
|
677
731
|
// Determine phase from snapshotName prefix
|
|
678
732
|
let phase;
|
|
679
|
-
if (snapshotName.startsWith(
|
|
680
|
-
phase =
|
|
733
|
+
if (snapshotName.startsWith("before@")) {
|
|
734
|
+
phase = "before";
|
|
681
735
|
}
|
|
682
|
-
else if (snapshotName.startsWith(
|
|
683
|
-
phase =
|
|
736
|
+
else if (snapshotName.startsWith("after@")) {
|
|
737
|
+
phase = "after";
|
|
684
738
|
}
|
|
685
|
-
else if (snapshotName.startsWith(
|
|
686
|
-
phase =
|
|
739
|
+
else if (snapshotName.startsWith("input@")) {
|
|
740
|
+
phase = "action";
|
|
687
741
|
}
|
|
688
742
|
else {
|
|
689
743
|
continue; // unknown phase, skip
|
|
690
744
|
}
|
|
691
745
|
mainFrameRecords.push({
|
|
692
|
-
callId,
|
|
746
|
+
callId,
|
|
747
|
+
phase,
|
|
748
|
+
snapshotName,
|
|
749
|
+
frameId,
|
|
750
|
+
frameUrl,
|
|
751
|
+
pageId,
|
|
752
|
+
timestamp,
|
|
753
|
+
viewport,
|
|
754
|
+
html,
|
|
755
|
+
snapshotIndex,
|
|
693
756
|
});
|
|
694
757
|
}
|
|
695
758
|
}
|
|
@@ -735,9 +798,9 @@ async function getDomSnapshots(traceContext, options) {
|
|
|
735
798
|
for (const [callId, phases] of rawByCallId) {
|
|
736
799
|
result.push({
|
|
737
800
|
callId,
|
|
738
|
-
before: phases.get(
|
|
739
|
-
action: phases.get(
|
|
740
|
-
after: phases.get(
|
|
801
|
+
before: phases.get("before") ?? null,
|
|
802
|
+
action: phases.get("action") ?? null,
|
|
803
|
+
after: phases.get("after") ?? null,
|
|
741
804
|
});
|
|
742
805
|
}
|
|
743
806
|
result.sort((a, b) => {
|
|
@@ -750,20 +813,20 @@ async function getDomSnapshots(traceContext, options) {
|
|
|
750
813
|
if (options.phase) {
|
|
751
814
|
const p = options.phase;
|
|
752
815
|
result = result
|
|
753
|
-
.map(r => ({
|
|
816
|
+
.map((r) => ({
|
|
754
817
|
...r,
|
|
755
|
-
before: p ===
|
|
756
|
-
action: p ===
|
|
757
|
-
after: p ===
|
|
818
|
+
before: p === "before" ? r.before : null,
|
|
819
|
+
action: p === "action" ? r.action : null,
|
|
820
|
+
after: p === "after" ? r.after : null,
|
|
758
821
|
}))
|
|
759
|
-
.filter(r => r.before !== null || r.action !== null || r.after !== null);
|
|
822
|
+
.filter((r) => r.before !== null || r.action !== null || r.after !== null);
|
|
760
823
|
}
|
|
761
|
-
if (options.near ===
|
|
824
|
+
if (options.near === "last") {
|
|
762
825
|
const n = options.limit ?? 5;
|
|
763
826
|
result = result.slice(-n);
|
|
764
827
|
}
|
|
765
828
|
else if (options.near) {
|
|
766
|
-
const idx = result.findIndex(r => r.callId === options.near);
|
|
829
|
+
const idx = result.findIndex((r) => r.callId === options.near);
|
|
767
830
|
if (idx >= 0) {
|
|
768
831
|
const n = options.limit ?? 5;
|
|
769
832
|
const half = Math.floor(n / 2);
|
|
@@ -788,17 +851,21 @@ function findPlaywrightTarget(node, ctx, currentCallId) {
|
|
|
788
851
|
if (!Array.isArray(node) || node.length < 2)
|
|
789
852
|
return null;
|
|
790
853
|
const attrs = node[1];
|
|
791
|
-
if (attrs && typeof attrs ===
|
|
854
|
+
if (attrs && typeof attrs === "object" && !Array.isArray(attrs)) {
|
|
792
855
|
const attributes = attrs;
|
|
793
|
-
if (Object.prototype.hasOwnProperty.call(attributes,
|
|
794
|
-
return attributes[
|
|
856
|
+
if (Object.prototype.hasOwnProperty.call(attributes, "__playwright_target__"))
|
|
857
|
+
return attributes["__playwright_target__"] || currentCallId || null;
|
|
795
858
|
// Descend into child frames so targets inside iframes are still found.
|
|
796
|
-
if (ctx && typeof node[0] ===
|
|
859
|
+
if (ctx && typeof node[0] === "string") {
|
|
797
860
|
const tag = node[0].toLowerCase();
|
|
798
|
-
if (tag ===
|
|
799
|
-
const childFrameId = parseSnapshotFrameId(attrs[
|
|
800
|
-
if (childFrameId &&
|
|
801
|
-
|
|
861
|
+
if (tag === "iframe" || tag === "frame") {
|
|
862
|
+
const childFrameId = parseSnapshotFrameId(attrs["src"]);
|
|
863
|
+
if (childFrameId &&
|
|
864
|
+
!ctx.stack.has(childFrameId) &&
|
|
865
|
+
ctx.stack.size < MAX_IFRAME_DEPTH) {
|
|
866
|
+
const entry = ctx.frameSnapshotsByName
|
|
867
|
+
.get(childFrameId)
|
|
868
|
+
?.get(ctx.snapshotName);
|
|
802
869
|
if (entry) {
|
|
803
870
|
ctx.stack.add(childFrameId);
|
|
804
871
|
try {
|
|
@@ -832,14 +899,20 @@ function findPlaywrightTarget(node, ctx, currentCallId) {
|
|
|
832
899
|
async function getScreenshotMetadata(traceContext) {
|
|
833
900
|
const screenshots = [];
|
|
834
901
|
const files = await fs.promises.readdir(traceContext.traceDir);
|
|
835
|
-
const traceFiles = files
|
|
902
|
+
const traceFiles = files
|
|
903
|
+
.filter((f) => f.endsWith(".trace") && f !== "test.trace")
|
|
904
|
+
.sort();
|
|
836
905
|
for (const traceFile of traceFiles) {
|
|
837
906
|
const filePath = path.join(traceContext.traceDir, traceFile);
|
|
838
907
|
for await (const event of (0, parseTrace_1.readNdjson)(filePath)) {
|
|
839
|
-
if (event.type !==
|
|
908
|
+
if (event.type !== "screencast-frame")
|
|
909
|
+
continue;
|
|
910
|
+
const resourceFile = (0, parseTrace_1.normalizeTraceResourceReference)(event.file, event.sha1);
|
|
911
|
+
if (!resourceFile)
|
|
840
912
|
continue;
|
|
841
913
|
screenshots.push({
|
|
842
|
-
sha1: event.sha1,
|
|
914
|
+
sha1: event.sha1 ?? resourceFile,
|
|
915
|
+
file: resourceFile,
|
|
843
916
|
timestamp: event.timestamp,
|
|
844
917
|
pageId: event.pageId,
|
|
845
918
|
width: event.width,
|
|
@@ -888,19 +961,24 @@ function buildActionDiagnostics(networkCalls, issues) {
|
|
|
888
961
|
ensure(issue.relatedAction).issueCount += 1;
|
|
889
962
|
}
|
|
890
963
|
return [...byCallId.values()].sort((left, right) => {
|
|
891
|
-
const leftScore = left.failingNetworkCallCount * 10 +
|
|
892
|
-
|
|
964
|
+
const leftScore = left.failingNetworkCallCount * 10 +
|
|
965
|
+
left.issueCount * 5 +
|
|
966
|
+
left.networkCallCount;
|
|
967
|
+
const rightScore = right.failingNetworkCallCount * 10 +
|
|
968
|
+
right.issueCount * 5 +
|
|
969
|
+
right.networkCallCount;
|
|
893
970
|
return rightScore - leftScore;
|
|
894
971
|
});
|
|
895
972
|
}
|
|
896
973
|
async function attachmentSize(traceContext, attachment) {
|
|
897
|
-
|
|
898
|
-
|
|
974
|
+
const resourceFile = (0, parseTrace_1.normalizeTraceResourceReference)(attachment.file, attachment.sha1);
|
|
975
|
+
if (resourceFile) {
|
|
976
|
+
const buffer = await (0, parseTrace_1.getResourceBuffer)(traceContext, resourceFile);
|
|
899
977
|
if (buffer)
|
|
900
978
|
return buffer.length;
|
|
901
979
|
}
|
|
902
980
|
if (attachment.base64)
|
|
903
|
-
return Buffer.from(attachment.base64,
|
|
981
|
+
return Buffer.from(attachment.base64, "base64").length;
|
|
904
982
|
if (attachment.path && fs.existsSync(attachment.path)) {
|
|
905
983
|
const stat = await fs.promises.stat(attachment.path);
|
|
906
984
|
return stat.size;
|
|
@@ -908,13 +986,14 @@ async function attachmentSize(traceContext, attachment) {
|
|
|
908
986
|
return null;
|
|
909
987
|
}
|
|
910
988
|
async function attachmentContent(traceContext, attachment) {
|
|
911
|
-
|
|
912
|
-
|
|
989
|
+
const resourceFile = (0, parseTrace_1.normalizeTraceResourceReference)(attachment.file ?? undefined, attachment.sha1 ?? undefined);
|
|
990
|
+
if (resourceFile) {
|
|
991
|
+
const buffer = await (0, parseTrace_1.getResourceBuffer)(traceContext, resourceFile);
|
|
913
992
|
if (buffer)
|
|
914
993
|
return buffer;
|
|
915
994
|
}
|
|
916
995
|
if (attachment.base64)
|
|
917
|
-
return Buffer.from(attachment.base64,
|
|
996
|
+
return Buffer.from(attachment.base64, "base64");
|
|
918
997
|
if (attachment.path && fs.existsSync(attachment.path))
|
|
919
998
|
return fs.promises.readFile(attachment.path);
|
|
920
999
|
return null;
|
|
@@ -922,16 +1001,20 @@ async function attachmentContent(traceContext, attachment) {
|
|
|
922
1001
|
function formatStackFrames(stack) {
|
|
923
1002
|
if (!stack?.length)
|
|
924
1003
|
return null;
|
|
925
|
-
return stack
|
|
1004
|
+
return stack
|
|
1005
|
+
.map((frame) => `at ${frame.file}:${frame.line}:${frame.column}`)
|
|
1006
|
+
.join("\n");
|
|
926
1007
|
}
|
|
927
1008
|
async function getBrowserActions(traceContext) {
|
|
928
1009
|
const files = await fs.promises.readdir(traceContext.traceDir);
|
|
929
|
-
const traceFiles = files
|
|
1010
|
+
const traceFiles = files
|
|
1011
|
+
.filter((f) => /^\d+-trace\.trace$/.test(f))
|
|
1012
|
+
.sort((a, b) => parseInt(a, 10) - parseInt(b, 10));
|
|
930
1013
|
const actions = new Map();
|
|
931
1014
|
for (const traceFile of traceFiles) {
|
|
932
1015
|
const filePath = path.join(traceContext.traceDir, traceFile);
|
|
933
1016
|
for await (const event of (0, parseTrace_1.readNdjson)(filePath)) {
|
|
934
|
-
if (event.type ===
|
|
1017
|
+
if (event.type === "before") {
|
|
935
1018
|
actions.set(event.callId, {
|
|
936
1019
|
callId: event.callId,
|
|
937
1020
|
title: event.title ?? `${event.class}.${event.method}`,
|
|
@@ -942,7 +1025,7 @@ async function getBrowserActions(traceContext) {
|
|
|
942
1025
|
});
|
|
943
1026
|
continue;
|
|
944
1027
|
}
|
|
945
|
-
if (event.type ===
|
|
1028
|
+
if (event.type === "after") {
|
|
946
1029
|
const action = actions.get(event.callId);
|
|
947
1030
|
if (action)
|
|
948
1031
|
action.endTime = event.endTime;
|
|
@@ -959,7 +1042,9 @@ function correlateAction(actions, timestamp, pageId) {
|
|
|
959
1042
|
continue;
|
|
960
1043
|
const endTime = action.endTime ?? action.startTime;
|
|
961
1044
|
const withinWindow = timestamp >= action.startTime && timestamp <= endTime;
|
|
962
|
-
const distance = withinWindow
|
|
1045
|
+
const distance = withinWindow
|
|
1046
|
+
? 0
|
|
1047
|
+
: Math.min(Math.abs(timestamp - action.startTime), Math.abs(timestamp - endTime));
|
|
963
1048
|
if (distance < bestDistance) {
|
|
964
1049
|
best = action;
|
|
965
1050
|
bestDistance = distance;
|
|
@@ -969,7 +1054,7 @@ function correlateAction(actions, timestamp, pageId) {
|
|
|
969
1054
|
}
|
|
970
1055
|
function resolveIssueRelatedAction(actions, callId, timestamp, pageId) {
|
|
971
1056
|
if (callId) {
|
|
972
|
-
const directMatch = actions.find(action => action.callId === callId);
|
|
1057
|
+
const directMatch = actions.find((action) => action.callId === callId);
|
|
973
1058
|
if (directMatch)
|
|
974
1059
|
return directMatch;
|
|
975
1060
|
}
|
|
@@ -979,20 +1064,20 @@ function filterNetworkEntries(entries, options) {
|
|
|
979
1064
|
if (!options)
|
|
980
1065
|
return entries;
|
|
981
1066
|
let filtered = entries;
|
|
982
|
-
if (options.source && options.source !==
|
|
983
|
-
filtered = filtered.filter(entry => entry.source === options.source);
|
|
1067
|
+
if (options.source && options.source !== "all")
|
|
1068
|
+
filtered = filtered.filter((entry) => entry.source === options.source);
|
|
984
1069
|
if (options.grep) {
|
|
985
|
-
const pattern = new RegExp(options.grep,
|
|
986
|
-
filtered = filtered.filter(entry => pattern.test(entry.url));
|
|
1070
|
+
const pattern = new RegExp(options.grep, "i");
|
|
1071
|
+
filtered = filtered.filter((entry) => pattern.test(entry.url));
|
|
987
1072
|
}
|
|
988
1073
|
if (options.method)
|
|
989
|
-
filtered = filtered.filter(entry => entry.method.toLowerCase() === options.method.toLowerCase());
|
|
1074
|
+
filtered = filtered.filter((entry) => entry.method.toLowerCase() === options.method.toLowerCase());
|
|
990
1075
|
if (options.status !== undefined)
|
|
991
|
-
filtered = filtered.filter(entry => entry.status === options.status);
|
|
1076
|
+
filtered = filtered.filter((entry) => entry.status === options.status);
|
|
992
1077
|
if (options.failed)
|
|
993
|
-
filtered = filtered.filter(entry => entry.status >= 400);
|
|
1078
|
+
filtered = filtered.filter((entry) => entry.status >= 400);
|
|
994
1079
|
if (options.near)
|
|
995
|
-
filtered = filtered.filter(entry => entry.relatedAction?.callId === options.near);
|
|
1080
|
+
filtered = filtered.filter((entry) => entry.relatedAction?.callId === options.near);
|
|
996
1081
|
if (options.limit !== undefined)
|
|
997
1082
|
filtered = filtered.slice(0, options.limit);
|
|
998
1083
|
return filtered;
|
|
@@ -1017,17 +1102,21 @@ async function getTimeline(traceContext) {
|
|
|
1017
1102
|
]);
|
|
1018
1103
|
const entries = [];
|
|
1019
1104
|
for (const step of flattenSteps(steps)) {
|
|
1020
|
-
entries.push({ timestamp: step.startTime, type:
|
|
1105
|
+
entries.push({ timestamp: step.startTime, type: "step", data: step });
|
|
1021
1106
|
}
|
|
1022
1107
|
for (const shot of screenshots) {
|
|
1023
|
-
entries.push({ timestamp: shot.timestamp, type:
|
|
1108
|
+
entries.push({ timestamp: shot.timestamp, type: "screenshot", data: shot });
|
|
1024
1109
|
}
|
|
1025
1110
|
for (const dom of domSnapshots) {
|
|
1026
1111
|
const ts = (dom.before ?? dom.action ?? dom.after)?.timestamp ?? 0;
|
|
1027
|
-
entries.push({ timestamp: ts, type:
|
|
1112
|
+
entries.push({ timestamp: ts, type: "dom", data: dom });
|
|
1028
1113
|
}
|
|
1029
1114
|
for (const net of network) {
|
|
1030
|
-
entries.push({
|
|
1115
|
+
entries.push({
|
|
1116
|
+
timestamp: new Date(net.startedDateTime).getTime(),
|
|
1117
|
+
type: "network",
|
|
1118
|
+
data: net,
|
|
1119
|
+
});
|
|
1031
1120
|
}
|
|
1032
1121
|
entries.sort((a, b) => a.timestamp - b.timestamp);
|
|
1033
1122
|
return entries;
|
|
@@ -1050,12 +1139,12 @@ async function getTimeline(traceContext) {
|
|
|
1050
1139
|
async function getTestTitle(traceContext) {
|
|
1051
1140
|
const files = await fs.promises.readdir(traceContext.traceDir);
|
|
1052
1141
|
const traceFiles = files
|
|
1053
|
-
.filter(f => /^\d+-trace\.trace$/.test(f))
|
|
1142
|
+
.filter((f) => /^\d+-trace\.trace$/.test(f))
|
|
1054
1143
|
.sort((a, b) => parseInt(a) - parseInt(b));
|
|
1055
1144
|
for (const traceFile of traceFiles) {
|
|
1056
1145
|
const filePath = path.join(traceContext.traceDir, traceFile);
|
|
1057
1146
|
for await (const event of (0, parseTrace_1.readNdjson)(filePath)) {
|
|
1058
|
-
if (event.type ===
|
|
1147
|
+
if (event.type === "context-options" && event.title) {
|
|
1059
1148
|
return event.title;
|
|
1060
1149
|
}
|
|
1061
1150
|
}
|
|
@@ -1078,51 +1167,58 @@ async function getSummary(traceContext, options) {
|
|
|
1078
1167
|
]);
|
|
1079
1168
|
// Infrastructure steps injected by Playwright — not meaningful test content.
|
|
1080
1169
|
const HOOK_TITLES = new Set([
|
|
1081
|
-
|
|
1082
|
-
|
|
1170
|
+
"Before Hooks",
|
|
1171
|
+
"After Hooks",
|
|
1172
|
+
"Worker Cleanup",
|
|
1173
|
+
"Worker Cleanup Hooks",
|
|
1174
|
+
"Worker Setup",
|
|
1083
1175
|
]);
|
|
1084
1176
|
const isHook = (s) => HOOK_TITLES.has(s.title) || s.title.startsWith('Attach "');
|
|
1085
1177
|
// Test steps = non-infrastructure roots (the user-visible test.step() blocks)
|
|
1086
|
-
const testRoots = roots.filter(r => !isHook(r));
|
|
1178
|
+
const testRoots = roots.filter((r) => !isHook(r));
|
|
1087
1179
|
// Main root: the failing step if any, otherwise the longest test step
|
|
1088
|
-
const mainRoot = testRoots.find(r => r.error !== null) ??
|
|
1089
|
-
testRoots.reduce((best, r) => best === null || (r.durationMs ?? 0) > (best.durationMs ?? 0)
|
|
1180
|
+
const mainRoot = testRoots.find((r) => r.error !== null) ??
|
|
1181
|
+
testRoots.reduce((best, r) => best === null || (r.durationMs ?? 0) > (best.durationMs ?? 0)
|
|
1182
|
+
? r
|
|
1183
|
+
: best, null) ??
|
|
1090
1184
|
roots[0] ??
|
|
1091
1185
|
null;
|
|
1092
|
-
const title = mainRoot?.title ??
|
|
1093
|
-
let status = roots.some(r => r.error !== null)
|
|
1094
|
-
|
|
1186
|
+
const title = mainRoot?.title ?? "Unknown";
|
|
1187
|
+
let status = roots.some((r) => r.error !== null)
|
|
1188
|
+
? "failed"
|
|
1189
|
+
: "passed";
|
|
1190
|
+
if (status === "passed" && options.reportMetadata) {
|
|
1095
1191
|
const sha1 = path.basename(traceContext.traceDir);
|
|
1096
1192
|
const traceMaps = options.reportTraceMaps ?? (0, parseTrace_1.buildReportTraceMaps)(options.reportMetadata);
|
|
1097
1193
|
const outcome = traceMaps.outcomeByTraceSha1.get(sha1);
|
|
1098
1194
|
const retryIndex = traceMaps.retryByTraceSha1.get(sha1) ?? 0;
|
|
1099
|
-
if (outcome ===
|
|
1100
|
-
status =
|
|
1195
|
+
if (outcome === "unexpected") {
|
|
1196
|
+
status = "failed";
|
|
1101
1197
|
}
|
|
1102
|
-
else if (outcome ===
|
|
1198
|
+
else if (outcome === "flaky") {
|
|
1103
1199
|
let resultsLength = 1;
|
|
1104
1200
|
for (const file of options.reportMetadata.files) {
|
|
1105
|
-
const test = file.tests.find(t => t.testId === traceMaps.testIdByTraceSha1.get(sha1));
|
|
1201
|
+
const test = file.tests.find((t) => t.testId === traceMaps.testIdByTraceSha1.get(sha1));
|
|
1106
1202
|
if (test) {
|
|
1107
1203
|
resultsLength = test.results.length;
|
|
1108
1204
|
break;
|
|
1109
1205
|
}
|
|
1110
1206
|
}
|
|
1111
1207
|
if (retryIndex < resultsLength - 1) {
|
|
1112
|
-
status =
|
|
1208
|
+
status = "failed";
|
|
1113
1209
|
}
|
|
1114
1210
|
}
|
|
1115
|
-
else if (outcome ===
|
|
1211
|
+
else if (outcome === "expected") {
|
|
1116
1212
|
let ok = true;
|
|
1117
1213
|
for (const file of options.reportMetadata.files) {
|
|
1118
|
-
const test = file.tests.find(t => t.testId === traceMaps.testIdByTraceSha1.get(sha1));
|
|
1214
|
+
const test = file.tests.find((t) => t.testId === traceMaps.testIdByTraceSha1.get(sha1));
|
|
1119
1215
|
if (test) {
|
|
1120
1216
|
ok = test.ok;
|
|
1121
1217
|
break;
|
|
1122
1218
|
}
|
|
1123
1219
|
}
|
|
1124
1220
|
if (!ok) {
|
|
1125
|
-
status =
|
|
1221
|
+
status = "failed";
|
|
1126
1222
|
}
|
|
1127
1223
|
}
|
|
1128
1224
|
}
|
|
@@ -1132,7 +1228,7 @@ async function getSummary(traceContext, options) {
|
|
|
1132
1228
|
const topLevelSteps = testRoots;
|
|
1133
1229
|
const allSteps = flattenSteps(roots);
|
|
1134
1230
|
const slowestSteps = allSteps
|
|
1135
|
-
.filter(s => s.durationMs !== null)
|
|
1231
|
+
.filter((s) => s.durationMs !== null)
|
|
1136
1232
|
.sort((a, b) => (b.durationMs ?? 0) - (a.durationMs ?? 0))
|
|
1137
1233
|
.slice(0, 5);
|
|
1138
1234
|
const networkCalls = network;
|
|
@@ -1143,15 +1239,17 @@ async function getSummary(traceContext, options) {
|
|
|
1143
1239
|
const closest = domAll.reduce((best, current) => {
|
|
1144
1240
|
const ct = (current.before ?? current.action ?? current.after)?.timestamp ?? 0;
|
|
1145
1241
|
const cct = (best.before ?? best.action ?? best.after)?.timestamp ?? 0;
|
|
1146
|
-
return Math.abs(ct - failureTime) < Math.abs(cct - failureTime)
|
|
1242
|
+
return Math.abs(ct - failureTime) < Math.abs(cct - failureTime)
|
|
1243
|
+
? current
|
|
1244
|
+
: best;
|
|
1147
1245
|
}, domAll[0]);
|
|
1148
1246
|
const phases = [];
|
|
1149
1247
|
if (closest.before)
|
|
1150
|
-
phases.push(
|
|
1248
|
+
phases.push("before");
|
|
1151
1249
|
if (closest.action)
|
|
1152
|
-
phases.push(
|
|
1250
|
+
phases.push("action");
|
|
1153
1251
|
if (closest.after)
|
|
1154
|
-
phases.push(
|
|
1252
|
+
phases.push("after");
|
|
1155
1253
|
const primary = closest.action ?? closest.before ?? closest.after;
|
|
1156
1254
|
failureDomSnapshot = {
|
|
1157
1255
|
callId: closest.callId,
|
|
@@ -1174,7 +1272,8 @@ async function getSummary(traceContext, options) {
|
|
|
1174
1272
|
actionDiagnostics,
|
|
1175
1273
|
failureDomSnapshot,
|
|
1176
1274
|
outcome: options.reportMetadata
|
|
1177
|
-
? (options.reportTraceMaps ??
|
|
1275
|
+
? ((options.reportTraceMaps ??
|
|
1276
|
+
(0, parseTrace_1.buildReportTraceMaps)(options.reportMetadata)).outcomeByTraceSha1.get(path.basename(traceContext.traceDir)) ?? null)
|
|
1178
1277
|
: null,
|
|
1179
1278
|
};
|
|
1180
1279
|
}
|
|
@@ -1194,12 +1293,12 @@ async function getFailedTraceSelections(reportDataDir, options) {
|
|
|
1194
1293
|
if (options?.excludeSkipped) {
|
|
1195
1294
|
let isSkipped = false;
|
|
1196
1295
|
if (outcomeByTraceSha1) {
|
|
1197
|
-
if (outcome ===
|
|
1296
|
+
if (outcome === "skipped")
|
|
1198
1297
|
isSkipped = true;
|
|
1199
1298
|
}
|
|
1200
1299
|
else {
|
|
1201
|
-
isSkipped = topFailures.every(f => f.annotations.some(a => a.type ===
|
|
1202
|
-
f.error?.message?.includes(
|
|
1300
|
+
isSkipped = topFailures.every((f) => f.annotations.some((a) => a.type === "skip") ||
|
|
1301
|
+
f.error?.message?.includes("Test is skipped:"));
|
|
1203
1302
|
}
|
|
1204
1303
|
if (isSkipped)
|
|
1205
1304
|
continue;
|
|
@@ -1214,7 +1313,10 @@ async function getFailedTraceSelections(reportDataDir, options) {
|
|
|
1214
1313
|
}
|
|
1215
1314
|
const results = [];
|
|
1216
1315
|
for (const { ctx } of byKey.values()) {
|
|
1217
|
-
const summary = await getSummary(ctx, {
|
|
1316
|
+
const summary = await getSummary(ctx, {
|
|
1317
|
+
reportMetadata: meta,
|
|
1318
|
+
reportTraceMaps: traceMaps,
|
|
1319
|
+
});
|
|
1218
1320
|
results.push({
|
|
1219
1321
|
tracePath: ctx.traceDir,
|
|
1220
1322
|
traceSha1: path.basename(ctx.traceDir),
|
|
@@ -1253,6 +1355,6 @@ async function getFailedTraceSelections(reportDataDir, options) {
|
|
|
1253
1355
|
*/
|
|
1254
1356
|
async function getFailedTestSummaries(reportDataDir, options) {
|
|
1255
1357
|
const selections = await getFailedTraceSelections(reportDataDir, options);
|
|
1256
|
-
return selections.map(selection => selection.summary);
|
|
1358
|
+
return selections.map((selection) => selection.summary);
|
|
1257
1359
|
}
|
|
1258
1360
|
//# sourceMappingURL=extractors.js.map
|