Skip to content

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

TypeScript

test(core): the busy glide proof reads each glide on its own timeline (#10396)

Christopher Chedeau27aba94e88a9
diff --git a/internal/interaction-harness/src/busy.ts b/internal/interaction-harness/src/busy.ts
index c6c0f72734..2f39f16550 100644
--- a/internal/interaction-harness/src/busy.ts
+++ b/internal/interaction-harness/src/busy.ts
@@ -623,10 +623,11 @@ export interface BusyProof extends FrameStats {
*/
readonly judged: {readonly from: number; readonly to: number};
/**
- * When the tracked value was seen at rest before the judged part (a frame
- * there, no change in the 250 ms before it: a just-started animation not on
- * screen yet), ms after the window's start of its first presented change
- * inside the block, where judging starts; null otherwise.
+ * The ms after the window's start of the tracked value's first presented
+ * change inside the block, where judging starts. It is set when the value
+ * was seen at rest before the judged part: a frame there, and no change in
+ * the `BUSY_PROOF_LOOKAROUND_MS` before it. That is a just-started animation
+ * not on screen yet. Otherwise it is null.
*/
readonly onScreenFromMs: number | null;
/**
@@ -798,10 +799,10 @@ function motionStepPx(values: readonly number[]): number {
* judge, and that fails rather than passes.
*
* A just-started animation can reach the screen after the block began (its
- * hand-off to the compositor lags under load: 50–100 ms in WebKit). When the
- * tracked value was seen at rest before the judged part (a frame there, and no
- * change in the 250 ms before it), judging starts at its first presented
- * change inside the block, which the
+ * hand-off to the compositor lags under load: 50–100 ms in WebKit). The
+ * tracked value may be seen at rest before the judged part: a frame there, and
+ * no change in the `BUSY_PROOF_LOOKAROUND_MS` before it. Judging then starts at
+ * its first presented change inside the block, which the
* proof reports as `onScreenFromMs`. So does a hold that starts before the
* block (two frames at least at one position, the first before it) and ends
* at the first presented change inside it: WebKit presents a just-started
@@ -1049,10 +1050,10 @@ export function busyWindowProof(
previous = v.value;
}
}
- // Seen at rest before the judged part (a frame there, and no change in the
- // 250 ms before it): the first presented change is the animation's on-screen
- // start, and judging starts there. With no frame before, nothing is known,
- // and the window is judged from its start.
+ // Seen at rest before the judged part: a frame there, and no change in the
+ // `BUSY_PROOF_LOOKAROUND_MS` before it. The first presented change is then
+ // the animation's on-screen start, and judging starts there. With no frame
+ // before, nothing is known, and the window is judged from its start.
const prior = tracked.filter(f => f.box != null && f.t < inner.from);
let leadFrom = 0;
prior.forEach((f, i) => {
diff --git a/internal/interaction-harness/src/frames.ts b/internal/interaction-harness/src/frames.ts
index 2569f02ef0..f6d1b4fdc3 100644
--- a/internal/interaction-harness/src/frames.ts
+++ b/internal/interaction-harness/src/frames.ts
@@ -6,10 +6,10 @@
* the engine's screencast (Chromium CDP `Page.startScreencast`; WebKit's
* `Screencast` domain)
* @output `startScreencast` (timestamped composited frames), `markElement`
- * (a marker outline the frames can find), `trackMarker` (per-frame marker
- * box and the cast's position step), `trackMarkers` (several colors from
- * one decode of each frame), `colorBlockPx` (a frame's color
- * resolution), `sampleRects` (per-rAF rect sampling), `frameStats`.
+ * (a marker outline the frames can find) and `trackMarker` (per-frame
+ * marker box and the cast's position step). `trackMarkers` tracks several
+ * colors from one decode of each frame. Also `colorBlockPx` (a frame's color
+ * resolution), `sampleRects` (per-rAF rect sampling) and `frameStats`.
* @position Frame evidence for motion proofs. The screencast is captured off
* the page's main thread, from what the compositor presents, so it keeps
* delivering frames while a script blocks the main thread: that is what makes
@@ -379,7 +379,7 @@ export async function trackMarker(
}
/**
- * `trackMarker` for several colors at once: each frame is decoded once and
+ * `trackMarker` for several colors at once. Each frame is decoded once and
* searched for every color, so a proof that tracks a marker and a control
* decodes each frame once. Returns one track per color, in order.
*/
diff --git a/packages/core/src/motion/__tests__/animatedLayoutBusy.interaction.browser.spec.ts b/packages/core/src/motion/__tests__/animatedLayoutBusy.interaction.browser.spec.ts
index 4185f1b5f4..e2be60f72e 100644
--- a/packages/core/src/motion/__tests__/animatedLayoutBusy.interaction.browser.spec.ts
+++ b/packages/core/src/motion/__tests__/animatedLayoutBusy.interaction.browser.spec.ts
@@ -21,6 +21,7 @@ import {
type BlockedWindow,
BUSY_PROOF_LOOKAROUND_MS,
busyWindowProof,
+ BusyWindowTooLateError,
castStep,
CONTROL_RGB,
MARKER_RGB,
@@ -64,9 +65,8 @@ test.afterAll(async () => {
const BLOCK_MS = 700;
/**
- * The glide's length here, ms. `--duration-medium-min` and `--duration-medium`
- * are both set to it, whichever the module plays. It is longer than the
- * theme's, so the judged part spans about 20 frames. The length changes
+ * The glide's length here, ms, set as `--duration-medium`. It is longer than
+ * the theme's, so the judged part spans about 20 frames. The length changes
* nothing the proof judges.
*/
const GLIDE_MS = 1000;
@@ -85,7 +85,7 @@ interface GlideRead {
delayMs: number;
/** The animation's own time, ms, at `at`. */
local: number;
- /** Epoch ms on the page clock when `local` was read. */
+ /** The document timeline's time `local` was read at, in epoch ms. */
at: number;
}
@@ -99,7 +99,7 @@ async function openStory(page: Page, story: string): Promise<void> {
.first()
.waitFor({state: 'attached'});
await page.addStyleTag({
- content: `* { --duration-medium-min: ${GLIDE_MS}ms !important; --duration-medium: ${GLIDE_MS}ms !important; }`,
+ content: `* { --duration-medium: ${GLIDE_MS}ms !important; }`,
});
await page.evaluate(async () => {
await document.fonts.ready;
@@ -161,7 +161,11 @@ async function clickThenBlock(
durationMs: Number(effect.getComputedTiming().duration),
delayMs: effect.getTiming().delay ?? 0,
local: Number(animation.currentTime ?? 0),
- at: performance.timeOrigin + performance.now(),
+ // The animation's time is on the document timeline, which
+ // holds the frame's time through the task.
+ at:
+ performance.timeOrigin +
+ Number(document.timeline.currentTime ?? performance.now()),
});
}
}
@@ -244,24 +248,28 @@ async function busyGlide(
await startBusyControl(page);
const cast = await startScreencast(page);
const {busy, glides} = await clickThenBlock(page, trigger, follower, axis);
- // Until every animation but the control's has ended.
- await expect
- .poll(async () =>
- page.evaluate(
- () =>
- document
- .getAnimations()
- .filter(
- a =>
- !(
- (a.effect as KeyframeEffect | null)?.target?.closest(
- '[data-harness-control]',
- ) ?? false
- ),
- ).length,
- ),
- )
- .toBe(0);
+ expect(glides.length, 'a glide carries the follower').toBeGreaterThan(0);
+ // Until every animation but the control's has ended. A count polled
+ // against a fixed 5 s measured the starved main thread, not the glide.
+ await page.evaluate(async () => {
+ for (;;) {
+ const left = document
+ .getAnimations()
+ .filter(
+ a =>
+ a.playState !== 'finished' &&
+ !(
+ (a.effect as KeyframeEffect | null)?.target?.closest(
+ '[data-harness-control]',
+ ) ?? false
+ ),
+ );
+ if (left.length === 0) {
+ break;
+ }
+ await Promise.allSettled(left.map(async a => a.finished));
+ }
+ });
// Where the marker rests, read from the page. A glide frozen through the
// block stays far from it, and a frame after the block can still be stale.
const settledAt = await follower.evaluate((el, along) => {
@@ -292,6 +300,21 @@ async function busyGlide(
) {
readable += 1;
}
+ // Too little of the glide moves a cast step a frame inside the block,
+ // because the block began too late. That is when the block ran, not how the
+ // glide moved. So it fails under that name, with the numbers.
+ if (readable - busy.from < MIN_JUDGED_FRAMES * FRAME_MS) {
+ const [glide] = glides;
+ const startedMs = glide.local + (busy.from - glide.at) - glide.delayMs;
+ throw new BusyWindowTooLateError(
+ `${name}: the block began ${startedMs.toFixed(0)} ms into the ${glide.durationMs.toFixed(0)} ms glide, which moves the follower a cast step a frame for only ${(readable - busy.from).toFixed(0)} ms of the block, under the ${MIN_JUDGED_FRAMES} frames the proof judges: the block started too late for the glide. Start the block earlier.`,
+ {
+ readableMs: readable - busy.from,
+ glideStartedMs: startedMs,
+ glideDurationMs: glide.durationMs,
+ },
+ );
+ }
// The part of the block the judgment reads ends there.
const judgedWindow = {...busy, to: Math.min(busy.to, readable)};
// Only the frames the proof reads are decoded, each once for both colors.
@@ -353,7 +376,6 @@ async function markAppDiv(page: Page, text: string): Promise<Locator> {
function expectKeptAdvancing(run: Awaited<ReturnType<typeof busyGlide>>) {
expect(run.busy.spanMs).toBeGreaterThanOrEqual(BLOCK_MS);
- expect(run.glides.length, 'a glide carries the follower').toBeGreaterThan(0);
expect(run.proof.verdict.failures, run.summary).toEqual([]);
expect(run.proof.monotonic, run.summary).toBe(true);
}