An open source design system that's fully customizable and agent ready
TypeScript
fix(interaction-harness): evidence reaches the report without a file copy inside the test (#9066)
Christopher Chedeaue03042b58b44
diff --git a/internal/interaction-harness/src/harness.interaction.browser.spec.ts b/internal/interaction-harness/src/harness.interaction.browser.spec.tsindex 2c5bd9f7ad..298f999fe0 100644--- a/internal/interaction-harness/src/harness.interaction.browser.spec.ts+++ b/internal/interaction-harness/src/harness.interaction.browser.spec.ts@@ -34,6 +34,8 @@* instruments; this file is why it may.*/+import fs from 'node:fs';+import {expect, test, type Page} from '@playwright/test';import type {CastFrame, TrackedFrame} from './frames';import {@@ -86,6 +88,7 @@ import {PEN_SKIP,WHEEL_SKIP,withFinger,+ writeEvidence,} from './index';const FIXTURE = `<!doctype html><meta name=viewport content="width=device-width,initial-scale=1">@@ -2641,6 +2644,41 @@ test.describe('animation state', () => {});});+test.describe('evidence files', () => {+ test('evidence reaches the report with no file copy inside the test', async ({+ browserName: _,+ }, testInfo) => {+ // A file copy that never returns, as one on a loaded runner has waited+ // past a test's whole budget: the evidence must not wait on one inside+ // the test's own time.+ test.setTimeout(15_000);+ const promises = fs.promises as unknown as {copyFile: unknown};+ const copyFile = promises.copyFile;+ let copies = 0;+ promises.copyFile = async () => {+ copies += 1;+ await new Promise(() => {});+ };+ try {+ const written = await writeEvidence(+ 'harness-self-test/evidence',+ {'a.json': '{"ok":true}'},+ testInfo,+ );+ expect(copies).toBe(0);+ // The file stays for local paths, and the report has its bytes.+ expect(fs.readFileSync(written['a.json'], 'utf8')).toBe('{"ok":true}');+ const attachment = testInfo.attachments.find(+ a => a.name === 'harness-self-test/evidence/a.json',+ );+ expect(attachment?.contentType).toBe('application/json');+ expect(String(attachment?.body)).toBe('{"ok":true}');+ } finally {+ promises.copyFile = copyFile;+ }+ });+});+test.describe('storyboards', {tag: '@storyboard'}, () => {test('an animation filmstrip records every frame and its trace follows the curve', async ({page,diff --git a/internal/interaction-harness/src/output.ts b/internal/interaction-harness/src/output.tsindex 59926b82c9..9f33213fb1 100644--- a/internal/interaction-harness/src/output.ts+++ b/internal/interaction-harness/src/output.ts@@ -52,8 +52,13 @@ export async function writeEvidence(fs.writeFileSync(file, contents);written[name] = file;if (testInfo != null) {+ // By body, not path: Playwright copies a path attachment into the+ // test's output folder with file calls inside the test, and on a loaded+ // runner that copy has waited past the test's whole budget. A body goes+ // to the reporter, which stores it outside the test's time; the file+ // above stays for local paths.await testInfo.attach(`${group}/${safeName(name)}`, {- path: file,+ body: contents,contentType: name.endsWith('.png')? 'image/png': name.endsWith('.json')