Skip to content

Commit cbd2f75

Browse files
authored
feat: support step-level attachments (#21)
1 parent 442b8f6 commit cbd2f75

4 files changed

Lines changed: 36 additions & 16 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"node": "^20.17.0 || >=22.9.0"
3535
},
3636
"devDependencies": {
37-
"@flakiness/flakiness-report": "^0.28.0",
37+
"@flakiness/flakiness-report": "^0.31.0",
3838
"@flakiness/playwright": "^1.3.3",
3939
"@playwright/test": "^1.58.2",
4040
"@types/debug": "^4.1.12",

pnpm-lock.yaml

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/normalizeReport.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function normalizeReport(report: FlakinessReport.Report): FlakinessReport
5454
return {
5555
...step,
5656
duration: step.duration === 0 ? undefined : step.duration,
57+
attachments: step.attachments && step.attachments.length ? step.attachments : undefined,
5758
steps: step.steps && step.steps.length ? step.steps.map(cleanupTestStep) : undefined,
5859
}
5960
}

src/readReport.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,31 @@ export async function readReport(reportFolder: string): Promise<{
6969
const filenameToPath = new Map(attachmentFiles.map(file => [path.basename(file), file]));
7070
const attachmentIdToPath = new Map<FlakinessReport.AttachmentId, FileAttachment>();
7171
const missingAttachments = new Map<FlakinessReport.AttachmentId, FlakinessReport.Attachment>();
72+
const visitAttachment = (attachment: FlakinessReport.Attachment) => {
73+
const attachmentPath = filenameToPath.get(attachment.id);
74+
if (!attachmentPath) {
75+
missingAttachments.set(attachment.id, attachment);
76+
} else {
77+
attachmentIdToPath.set(attachment.id, {
78+
contentType: attachment.contentType,
79+
id: attachment.id,
80+
path: attachmentPath,
81+
type: 'file',
82+
});
83+
}
84+
};
85+
const visitStep = (step: FlakinessReport.TestStep) => {
86+
for (const attachment of step.attachments ?? [])
87+
visitAttachment(attachment);
88+
for (const childStep of step.steps ?? [])
89+
visitStep(childStep);
90+
};
7291
visitTests(report, (test) => {
7392
for (const attempt of test.attempts) {
74-
for (const attachment of attempt.attachments ?? []) {
75-
const attachmentPath = filenameToPath.get(attachment.id);
76-
if (!attachmentPath) {
77-
missingAttachments.set(attachment.id, attachment);
78-
} else {
79-
attachmentIdToPath.set(attachment.id, {
80-
contentType: attachment.contentType,
81-
id: attachment.id,
82-
path: attachmentPath,
83-
type: 'file',
84-
});
85-
}
86-
}
93+
for (const attachment of attempt.attachments ?? [])
94+
visitAttachment(attachment);
95+
for (const step of attempt.steps ?? [])
96+
visitStep(step);
8797
}
8898
});
8999
return {

0 commit comments

Comments
 (0)