Skip to content

Commit

Permalink
fix(playwright): fix screenshot metadata in reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Nov 8, 2023
1 parent 47a9394 commit f8a6552
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 13 additions & 0 deletions packages/playwright/src/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export type Attachment = TestResult["attachments"][number];
export type ArgosScreenshotAttachment = Attachment & {
body: Buffer;
};
export type ArgosMetadataAttachment = Attachment & {
body: Buffer;
};
export type AutomaticScreenshotAttachment = Attachment & {
name: "screenshot";
path: string;
Expand Down Expand Up @@ -51,6 +54,16 @@ export function checkIsArgosScreenshot(
);
}

export function checkIsArgosScreenshotMetadata(
attachment: Attachment,
): attachment is ArgosMetadataAttachment {
return (
attachment.name.startsWith("argos/") &&
attachment.contentType === "application/json" &&
Boolean(attachment.body)
);
}

export function checkIsAutomaticScreenshot(
attachment: Attachment,
): attachment is AutomaticScreenshotAttachment {
Expand Down
9 changes: 5 additions & 4 deletions packages/playwright/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import {
checkIsArgosScreenshot,
checkIsArgosScreenshotMetadata,
checkIsAutomaticScreenshot,
checkIsTrace,
getAttachementFilename,
Expand Down Expand Up @@ -80,10 +81,10 @@ class ArgosReporter implements Reporter {
async onTestEnd(test: TestCase, result: TestResult) {
await Promise.all(
result.attachments.map(async (attachment) => {
if (checkIsArgosScreenshot(attachment)) {
if (!attachment.body) {
throw new Error("Missing attachment body");
}
if (
checkIsArgosScreenshot(attachment) ||
checkIsArgosScreenshotMetadata(attachment)
) {
const path = join(
this.uploadDir,
getAttachementFilename(attachment.name),
Expand Down

0 comments on commit f8a6552

Please sign in to comment.