Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(interaction-harness): a storyboard capture is taken once (#10579)

Christopher Chedeaue171d97c0e75
diff --git a/internal/interaction-harness/README.md b/internal/interaction-harness/README.md
index 4cce8060a7..345e162be9 100644
--- a/internal/interaction-harness/README.md
+++ b/internal/interaction-harness/README.md
@@ -556,10 +556,8 @@ event `timeStamp`s (Chromium), but a handler that reads `performance.now()` or
`Date.now()` sees one event per photograph, about 100 ms apart, so a
clock-timed release flings slower when filmed than when played: a storyboard
cannot show such a gesture; record it in real time instead, with
-`startScreencast` and `castStoryboard`. Chromium can return an empty copy of
-the page's surface right after it changes ("Unable to capture screenshot"); a
-storyboard takes that photograph again two frames later, up to three attempts
-in all, and lists each retake under `recaptures` in the trace.
+`startScreencast` and `castStoryboard`. A photograph the engine fails
+throws the engine's error; a storyboard never takes it again.
## Page freeze
diff --git a/internal/interaction-harness/src/harness.interaction.browser.spec.ts b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
index f97f277dde..2752f37d32 100644
--- a/internal/interaction-harness/src/harness.interaction.browser.spec.ts
+++ b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
@@ -30,8 +30,8 @@
* after it;
* storyboards write a
* sheet and a trace that follows the curve, an endless animation does not
- * set their length, and a photograph Chromium returns empty is taken again
- * two frames later; a touch filmstrip keeps scripted event times while a
+ * set their length, and a photograph the engine fails throws its error and
+ * records no frame; a touch filmstrip keeps scripted event times while a
* handler clock sees its pacing; the timer gate holds a component timer
* until the filmstrip is done, drops callbacks the page cancels, stamps held
* frames with the time they run, and leaves the harness its own frames; a
@@ -6704,54 +6704,28 @@ test.describe('storyboards', {tag: '@storyboard'}, () => {
expect(files['sheet.png']).toMatch(/sheet\.png$/);
});
- test('a capture Chromium returns empty is taken again two frames later', async ({
+ test('a capture the engine fails throws its error and records no frame', async ({
page,
}) => {
await fixture(page);
- // Counts the page's frames, so the wait before the second capture shows.
- await page.evaluate(() => {
- const w = window as unknown as {__frames: number};
- w.__frames = 0;
- const tick = () => {
- w.__frames += 1;
- requestAnimationFrame(tick);
- };
- requestAnimationFrame(tick);
- });
- const screenshot = page.screenshot.bind(page);
- const calledAt: number[] = [];
- let failures = 1;
// What Chromium answers when its surface copy comes back empty.
- page.screenshot = (async (options?: Parameters<Page['screenshot']>[0]) => {
- calledAt.push(
- await page.evaluate(
- () => (window as unknown as {__frames: number}).__frames,
- ),
+ let photographs = 0;
+ page.screenshot = (async () => {
+ photographs += 1;
+ throw new Error(
+ 'page.screenshot: Protocol error (Page.captureScreenshot): Unable to capture screenshot',
);
- if (failures-- > 0) {
- throw new Error(
- 'page.screenshot: Protocol error (Page.captureScreenshot): Unable to capture screenshot',
- );
- }
- return screenshot(options);
}) as Page['screenshot'];
const storyboard = new Storyboard(page, {
- name: 'harness-self-test-recapture',
+ name: 'harness-self-test-capture-error',
clip: {x: 0, y: 340, width: 402, height: 120},
});
- await storyboard.capture('t=0 ms', 0);
- expect(storyboard.frames).toHaveLength(1);
- expect(calledAt).toHaveLength(2);
- expect(calledAt[1] - calledAt[0]).toBeGreaterThanOrEqual(2);
- expect(storyboard.trace().recaptures).toEqual([
- {label: 't=0 ms', error: expect.stringContaining('Unable to capture')},
- ]);
- // Captures that keep failing still fail, with Chromium's error.
- failures = Infinity;
- await expect(storyboard.capture('t=1 ms', 1)).rejects.toThrow(
+ await expect(storyboard.capture('t=0 ms', 0)).rejects.toThrow(
/Unable to capture screenshot/,
);
- expect(storyboard.frames).toHaveLength(1);
+ expect(photographs).toBe(1);
+ expect(storyboard.frames).toHaveLength(0);
+ expect(storyboard.trace()).not.toHaveProperty('recaptures');
});
test('a touch filmstrip photographs every scripted event', async ({
diff --git a/internal/interaction-harness/src/storyboard.ts b/internal/interaction-harness/src/storyboard.ts
index 7f0c32769a..7473ed8801 100644
--- a/internal/interaction-harness/src/storyboard.ts
+++ b/internal/interaction-harness/src/storyboard.ts
@@ -60,21 +60,8 @@ export interface StoryboardOptions {
readonly cellScale?: number;
}
-/**
- * Chromium photographs the page by copying its compositor surface. Right after
- * the page's surface changes (a navigation, a resize) the copy can come back
- * empty, and Chromium answers "Unable to capture screenshot" once its own five
- * retries, issued without waiting for a new frame, have all found no surface.
- * A capture that fails that way is taken again after the page has presented
- * two more frames, at most this many attempts in all.
- */
-const CAPTURE_ATTEMPTS = 3;
-const EMPTY_SURFACE_COPY = /Unable to capture screenshot/;
-
export class Storyboard {
readonly frames: StoryboardFrame[] = [];
- /** Captures Chromium returned empty and that were taken again two frames later. */
- readonly recaptures: {label: string; error: string}[] = [];
private clipBox: ClipBox | undefined;
constructor(
@@ -83,9 +70,8 @@ export class Storyboard {
) {}
/**
- * Photographs the clip now and records `data` with it. An empty surface
- * copy (see CAPTURE_ATTEMPTS) is taken again once the page has presented two
- * more frames; any other failure, or a third empty copy, throws.
+ * Photographs the clip now and records `data` with it. A capture that
+ * fails throws the engine's error.
*/
async capture(
label: string,
@@ -93,25 +79,13 @@ export class Storyboard {
data: Readonly<Record<string, unknown>> = {},
): Promise<void> {
const clip = await this.resolveClip();
- for (let attempt = 1; ; attempt += 1) {
- try {
- const png = await this.page.screenshot({
- clip,
- scale: 'css',
- animations: 'allow',
- caret: 'hide',
- });
- this.frames.push({label, t, data, png});
- return;
- } catch (error) {
- const message = error instanceof Error ? error.message : String(error);
- if (attempt >= CAPTURE_ATTEMPTS || !EMPTY_SURFACE_COPY.test(message)) {
- throw error;
- }
- this.recaptures.push({label, error: message.split('\n')[0]});
- await frames(this.page, 2);
- }
- }
+ const png = await this.page.screenshot({
+ clip,
+ scale: 'css',
+ animations: 'allow',
+ caret: 'hide',
+ });
+ this.frames.push({label, t, data, png});
}
private async resolveClip(): Promise<ClipBox | undefined> {
@@ -157,7 +131,6 @@ export class Storyboard {
browser: this.page.context().browser()?.browserType().name() ?? null,
viewport: this.page.viewportSize(),
clip: this.clipBox ?? null,
- ...(this.recaptures.length > 0 ? {recaptures: this.recaptures} : {}),
...extra,
frames: this.frames.map(({label, t, data}) => ({label, t, data})),
};