An open source design system that's fully customizable and agent ready
TypeScript
test(interaction-harness): a hold sent from the test names the motion it judges (#10438)
Cindy Zhang9b7ebc461bb8
diff --git a/internal/interaction-harness/README.md b/internal/interaction-harness/README.mdindex 1cb892ed5b..0ebdad97cf 100644--- a/internal/interaction-harness/README.md+++ b/internal/interaction-harness/README.md@@ -123,6 +123,10 @@ names the motion it judges, `{judges: {target, property}}` (a list forseveral; `pseudoElement` for a `::before` or `::after`), and `held()` rejectswhen the hold took no animation of it. `judges: 'count-only'` checks nothing:it marks a call site whose hold does not take its judged motion yet.+A hold sent from the test (`holdAnimations`, and `animationStoryboard`+without `held`) takes the same `judges` and rejects the same way: it takes+what runs when it reaches the page, and on a busy runner the judged motion+can still be to come or already over.Compare it with anoracle from `math.ts` through `compareCurve`; a tolerance states the errorbudget (for a spring baked into `linear()` stops of `h` ms, chords err by up todiff --git a/internal/interaction-harness/src/curves.ts b/internal/interaction-harness/src/curves.tsindex cf227f471b..bf81f33443 100644--- a/internal/interaction-harness/src/curves.ts+++ b/internal/interaction-harness/src/curves.ts@@ -658,22 +658,51 @@ export interface HeldAnimation {* An animation the page cancels after the hold (retargeting a CSS transition* cancels it) leaves the held set: seeking, sampling and releasing skip it* rather than revive it.+ *+ * `judges` names the motion that the test reads from the hold, as for+ * `armHold`. A hold sent from the test takes what runs when it reaches the+ * page: the judged motion can still be to come, or already over on a busy+ * runner, while other animations under the scope run. So the call rejects+ * when it took no animation of each judged motion.*/export async function holdAnimations(page: Page,- scope?: Locator,+ scope: Locator | undefined,+ options: HoldOptions,): Promise<HeldAnimation[]> {+ const motions = judgedMotions('holdAnimations', options?.judges);const scopeHandle = scope ? await scope.elementHandle() : null;await installCurveEnd(page);- return page.evaluate(- root =>- (- window as unknown as {- __harnessHold: (root: Element | null) => HeldAnimation[];- }- ).__harnessHold(root),- scopeHandle,+ holdKeys += 1;+ const key = holdKeys;+ const held = await page.evaluate(+ ([root, id, judged]) => {+ const w = window as unknown as {+ __harnessHold: (root: Element | null) => HeldAnimation[];+ __harnessHeld?: Animation[];+ __harnessTook?: Record<number, Animation[]>;+ };+ const took = w.__harnessHold(root);+ // The hold appends what it took to the held set. The judged-motion+ // check reads these animations.+ if (judged && took.length > 0) {+ w.__harnessTook = {+ ...w.__harnessTook,+ [id]: (w.__harnessHeld ?? []).slice(-took.length),+ };+ }+ return took;+ },+ [scopeHandle, key, motions.length > 0] as const,);+ await expectJudgedMotionsHeld(page, key, motions, {+ caller: 'holdAnimations',+ cause:+ 'The judged motion did not run when the hold reached the page (not started yet, or already over)',+ remedy:+ 'Arm the hold before the action that starts the motion (armHold), so the page holds it as it starts.',+ });+ return held;}/** An armed hold (`armHold`): the page holds on its own; read what it held. */@@ -706,16 +735,37 @@ export interface JudgedMotion {*/export type HoldJudges = JudgedMotion | readonly JudgedMotion[] | 'count-only';-/** How an armed hold waits (`armHold`), and what it must take. */-export interface ArmHoldOptions {+/** What a hold must take (`holdAnimations`). */+export interface HoldOptions {readonly judges: HoldJudges;+}++/** How an armed hold waits (`armHold`), and what it must take. */+export interface ArmHoldOptions extends HoldOptions {readonly count?: number;readonly minProgressMs?: number;readonly newOnly?: boolean;readonly timeout?: number;}-let armedHolds = 0;+/** Keys each hold's record of what it took, for the judged-motion check. */+let holdKeys = 0;++/**+ * The judged motions as a list: empty for `'count-only'`. Throws when the+ * caller names none.+ */+function judgedMotions(+ caller: string,+ judges: HoldJudges | undefined,+): readonly JudgedMotion[] {+ if (judges == null) {+ throw new Error(+ `${caller}: name the motion that the test judges ({judges: {target, property}}). Other animations can be what the hold takes while that motion does not run. Pass 'count-only' only for a call site that does not hold its judged motion yet.`,+ );+ }+ return judges === 'count-only' ? [] : 'target' in judges ? [judges] : judges;+}/*** Arms the page to hold every running animation under `scope` (the whole@@ -766,19 +816,13 @@ export async function armHold(newOnly = false,timeout = 5_000,} = options ?? ({} as Partial<ArmHoldOptions>);- if (judges == null) {- throw new Error(- "armHold: name the motion that the test judges ({judges: {target, property}}). Other animations can meet a count of running animations before that motion starts. Pass 'count-only' only for a call site that does not hold its judged motion yet.",- );- }- const motions: readonly JudgedMotion[] =- judges === 'count-only' ? [] : 'target' in judges ? [judges] : judges;+ const motions = judgedMotions('armHold', judges);const scopeHandle = scope ? await scope.elementHandle() : null;await installCurveEnd(page);- armedHolds += 1;- const id = armedHolds;+ holdKeys += 1;+ const id = holdKeys;await page.evaluate(- ([root, needed, minProgress, fresh, wait, key]) => {+ ([root, needed, minProgress, fresh, wait, key, judged]) => {const w = window as unknown as {__harnessHold: (root: Element | null,@@ -791,7 +835,7 @@ export async function armHold(timeout?: typeof setTimeout;};__harnessArmed?: Record<number, Promise<unknown[]>>;- __harnessArmedTook?: Record<number, Animation[]>;+ __harnessTook?: Record<number, Animation[]>;};// The harness's own waits run on the real timers: a frozen timer gate// (story.ts) holds only the page's.@@ -854,13 +898,12 @@ export async function armHold(const took = w.__harnessHold(root, before);// The hold appends what it took to the held set. `held()` reads// these animations to find the judged motions.- w.__harnessArmedTook = {- ...w.__harnessArmedTook,- [key]:- took.length === 0- ? []- : (w.__harnessHeld ?? []).slice(-took.length),- };+ if (judged && took.length > 0) {+ w.__harnessTook = {+ ...w.__harnessTook,+ [key]: (w.__harnessHeld ?? []).slice(-took.length),+ };+ }resolve(took);} catch (error) {reject(error);@@ -889,6 +932,7 @@ export async function armHold(newOnly,timeout,id,+ motions.length > 0,] as const,);return {@@ -904,28 +948,36 @@ export async function armHold(delete w.__harnessArmed?.[key];return armed;}, id);- await expectJudgedMotionsHeld(page, id, motions, count);+ await expectJudgedMotionsHeld(page, id, motions, {+ caller: 'armHold',+ cause: `Other animations met its count of ${Math.max(count, 1)} first`,+ remedy:+ 'Arm the hold so that it waits for the judged motion (count, newOnly, minProgressMs, scope).',+ });return held;},};}/**- * Throws unless the armed hold `key` took an animation of each judged motion.- * The targets resolve only now: the action that the hold waits for can add- * them to the page.+ * Throws unless the hold `key` took an animation of each judged motion. The+ * targets resolve only now: the action that an armed hold waits for can add+ * them to the page. `cause` and `remedy` complete the error for the caller.*/async function expectJudgedMotionsHeld(page: Page,key: number,motions: readonly JudgedMotion[],- count: number,+ failure: {caller: string; cause: string; remedy: string},): Promise<void> {+ if (motions.length === 0) {+ return;+ }const targets = await Promise.all(motions.map(motion =>motion.target.elementHandle({timeout: 5_000}).catch(() => {throw new Error(- `armHold: the judged target ${motion.target.toString()} is not on the page`,+ `${failure.caller}: the judged target ${motion.target.toString()} is not on the page`,);}),),@@ -933,10 +985,10 @@ async function expectJudgedMotionsHeld(const {missing, took} = await page.evaluate(([armed, elements, wanted]) => {const w = window as unknown as {- __harnessArmedTook?: Record<number, Animation[]>;+ __harnessTook?: Record<number, Animation[]>;};- const animations = w.__harnessArmedTook?.[armed] ?? [];- delete w.__harnessArmedTook?.[armed];+ const animations = w.__harnessTook?.[armed] ?? [];+ delete w.__harnessTook?.[armed];// `getKeyframes()` names a property in camel case, except a custom// property.const keyframeName = (property: string) =>@@ -945,9 +997,38 @@ async function expectJudgedMotionsHeld(: property.replace(/-([a-z])/g, (_, letter: string) =>letter.toUpperCase(),);+ // Chromium's `getKeyframes()` leaves out a custom property that a CSS+ // animation animates. The `@keyframes` rule of that name lists it. The+ // rule can sit inside a grouping rule (`@layer`, `@media`).+ const keyframesRules = (rules: readonly CSSRule[]): CSSKeyframesRule[] =>+ rules.flatMap(rule =>+ rule instanceof CSSKeyframesRule+ ? [rule]+ : rule instanceof CSSGroupingRule+ ? keyframesRules([...rule.cssRules])+ : [],+ );+ const ruleProperties = (name: string) =>+ [...document.styleSheets, ...document.adoptedStyleSheets].flatMap(+ sheet => {+ let rules: CSSRule[] = [];+ try {+ rules = [...sheet.cssRules];+ } catch {+ // A cross-origin sheet does not expose its rules.+ }+ return keyframesRules(rules)+ .filter(rule => rule.name === name)+ .flatMap(rule =>+ [...rule.cssRules].flatMap(keyframe => [+ ...(keyframe as CSSKeyframeRule).style,+ ]),+ );+ },+ );const properties = (animation: Animation) => [- ...new Set(- ((animation.effect as KeyframeEffect | null)?.getKeyframes() ?? [])+ ...new Set([+ ...((animation.effect as KeyframeEffect | null)?.getKeyframes() ?? []).flatMap(keyframe => Object.keys(keyframe)).filter(name =>@@ -955,7 +1036,10 @@ async function expectJudgedMotionsHeld(name,),),- ),+ ...(animation instanceof CSSAnimation+ ? ruleProperties(animation.animationName).map(keyframeName)+ : []),+ ]),];const describe = (animation: Animation) => {const effect = animation.effect as KeyframeEffect | null;@@ -1004,10 +1088,10 @@ async function expectJudgedMotionsHeld(}).join(', ');throw new Error(- `armHold: the hold took no animation of the judged motion (${judged}). ` +- `Other animations met its count of ${Math.max(count, 1)} first; it took: ` ++ `${failure.caller}: the hold took no animation of the judged motion (${judged}). ` ++ `${failure.cause}; it took: ` +`${took.length > 0 ? took.join('; ') : 'nothing'}. ` +- 'Arm the hold so that it waits for the judged motion (count, newOnly, minProgressMs, scope).',+ failure.remedy,);}}diff --git a/internal/interaction-harness/src/harness.interaction.browser.spec.ts b/internal/interaction-harness/src/harness.interaction.browser.spec.tsindex 1e27af881c..e19a90a759 100644--- a/internal/interaction-harness/src/harness.interaction.browser.spec.ts+++ b/internal/interaction-harness/src/harness.interaction.browser.spec.ts@@ -2849,7 +2849,9 @@ test.describe('pseudo-element animations', () => {{duration: 300, easing: 'linear', pseudoElement: '::before'},);}, VEIL_STYLE);- await holdAnimations(page, box);+ await holdAnimations(page, box, {+ judges: {target: box, property: 'opacity', pseudoElement: '::before'},+ });const samples = await sampleCurve(box, [0, 75, 150, 225, 300], {pseudoElement: '::before',});@@ -3078,6 +3080,58 @@ test.describe('holding', () => {).rejects.toThrow(/armHold: name the motion that the test judges/);});+ test('a hold sent from the test rejects when the judged motion does not run yet', async ({+ page,+ }) => {+ await fixture(page);+ const {box, thumb} = await pressAndTravelFixture(page);+ await startPressThenTravel(page);+ await expect(+ holdAnimations(page, box, {+ judges: {target: thumb, property: 'translate'},+ }),+ ).rejects.toThrow(+ /holdAnimations: the hold took no animation of the judged motion \(translate on .*#thumb.*\)\. The judged motion did not run when the hold reached the page .*; it took: div#box opacity/,+ );+ // The travel was never held: a film of this hold would show the press.+ await expect+ .poll(() =>+ thumb.evaluate(el => el.getAnimations().map(a => a.playState)),+ )+ .toEqual(['running']);+ await releaseAnimations(page, {finish: true});+ });++ test('a judged custom property is found in its @keyframes rule, inside a layer', async ({+ page,+ }) => {+ await fixture(page);+ const box = page.locator('#box');+ await page.evaluate(() => {+ const style = document.createElement('style');+ style.textContent =+ "@property --harness-strength { syntax: '<number>'; inherits: false; initial-value: 0; }" ++ '@layer harness { @keyframes harness-strength { from { --harness-strength: 1; } to { --harness-strength: 0; } } }' ++ '#box { animation: harness-strength 2s linear; }';+ document.head.append(style);+ });+ const held = await holdAnimations(page, box, {+ judges: {target: box, property: '--harness-strength'},+ });+ expect(held.map(a => a.name)).toEqual(['harness-strength']);+ await releaseAnimations(page, {finish: true});+ });++ test('a film that holds now refuses to start without the motion it shows', async ({+ page,+ }) => {+ await fixture(page);+ await expect(+ // @ts-expect-error -- a caller without types can omit `judges`.+ animationStoryboard(page, {name: 'harness-self-test-no-judges'}),+ ).rejects.toThrow(/holdAnimations: name the motion that the test judges/);+ });+test('a sample at an end reports the time it was read at', async ({page}) => {await fixture(page);const box = page.locator('#box');@@ -3169,7 +3223,12 @@ test.describe('holding', () => {await later?.ready;return Number(later?.startTime) - Number(box?.startTime);});- const held = await holdAnimations(page);+ const held = await holdAnimations(page, undefined, {+ judges: [+ {target: page.locator('#box'), property: 'transform'},+ {target: page.locator('#later'), property: 'transform'},+ ],+ });expect(held.map(a => a.target)).toEqual(['div#box', 'div#later']);const [first, later] = held;expect(first.offsetMs).toBe(0);@@ -3374,7 +3433,9 @@ test.describe('holding', () => {});const [running] = await fast.started();expect(running.to - running.from).toBeCloseTo(5000, 0);- await holdAnimations(page, box);+ await holdAnimations(page, box, {+ judges: {target: box, property: 'translate'},+ });await seekAnimations(page, 125);const x = await box.evaluate(el =>@@ -3406,7 +3467,9 @@ test.describe('holding', () => {{duration, easing: 'cubic-bezier(0.42, 0, 1, 1)'},);}, RUN_MS);- const [held] = await holdAnimations(page, box);+ const [held] = await holdAnimations(page, box, {+ judges: {target: box, property: 'translate'},+ });// The keyframe offset 0.5 is progress, not half the time: the run starts// where the eased progress reaches 0.5.const ease = cubicBezier(0.42, 0, 1, 1);@@ -3436,7 +3499,9 @@ test.describe('holding', () => {{duration, easing: 'linear', direction: 'reverse'},);}, RUN_MS);- const [reversed] = await holdAnimations(page, box);+ const [reversed] = await holdAnimations(page, box, {+ judges: {target: box, property: 'translate'},+ });expect(reversed.curveEndMs).toBeCloseTo(RUN_MS, 0);await releaseAnimations(page, {finish: true});@@ -3469,7 +3534,9 @@ test.describe('holding', () => {// Both from the engine's own instants: within the timeline's rounding.expect(Math.abs(running.from - begunAt)).toBeLessThanOrEqual(1);expect(running.to - running.from).toBeCloseTo(RUN_MS, -1);- await expect(holdAnimations(page, box)).rejects.toThrow(/runs backward/);+ await expect(+ holdAnimations(page, box, {judges: 'count-only'}),+ ).rejects.toThrow(/runs backward/);await box.evaluate(el => el.getAnimations().forEach(a => a.finish()));// A property keyed only before the held run, and a last keyframe short of@@ -3492,7 +3559,9 @@ test.describe('holding', () => {},{frames: keyframes, duration: RUN_MS},);- const [moving] = await holdAnimations(page, box);+ const [moving] = await holdAnimations(page, box, {+ judges: {target: box, property: 'translate'},+ });expect(moving.curveEndMs).toBeCloseTo(RUN_MS, 0);await releaseAnimations(page, {finish: true});}@@ -3503,7 +3572,9 @@ test.describe('holding', () => {easing: 'linear',});}, RUN_MS);- await holdAnimations(page, box);+ await holdAnimations(page, box, {+ judges: {target: box, property: 'rotate'},+ });const [end] = await sampleCurve(box, [RUN_MS]);// About x, nothing turns in the plane: no z rotation, and y shrinks by// cos 60°.@@ -3525,7 +3596,9 @@ test.describe('holding', () => {});const box = page.locator('#box');await waitForAnimation(box, {minProgressMs: 50});- const [held] = await holdAnimations(page, box);+ const [held] = await holdAnimations(page, box, {+ judges: {target: box, property: 'transform'},+ });// Two frames later, the held animation is still where the hold read it.const after = await box.evaluate(el =>@@ -3607,7 +3680,12 @@ test.describe('holding', () => {},});});- const held = await holdAnimations(page);+ const held = await holdAnimations(page, undefined, {+ judges: [+ {target: page.locator('#box'), property: 'transform'},+ {target: page.locator('#faster'), property: 'transform'},+ ],+ });expect(held.map(a => a.target)).toEqual(['div#box', 'div#faster']);const [box, faster] = held;expect(faster.heldAtMs).toBe(400);@@ -3710,8 +3788,12 @@ test.describe('holding', () => {const box = page.locator('#box');await waitForAnimation(box);// The later-started element is held first.- const [first] = await holdAnimations(page, box);- const [later] = await holdAnimations(page, page.locator('#early'));+ const [first] = await holdAnimations(page, box, {+ judges: {target: box, property: 'transform'},+ });+ const [later] = await holdAnimations(page, page.locator('#early'), {+ judges: {target: page.locator('#early'), property: 'opacity'},+ });const samples = await sampleCurve(box, [0, 15_000, 30_000]);// Unrounded: at 0.005 px a ms, sampling from an origin shifted by the// start gap (over 100 ms) moves a sample by 0.5 px or more, while a seek@@ -4784,7 +4866,9 @@ test.describe('animation state', () => {);expect(changed, `${label}: changed partway`).toBe(true);if (held) {- const taken = await holdAnimations(page, box);+ const taken = await holdAnimations(page, box, {+ judges: {target: box.locator('div').first(), property: 'opacity'},+ });expect(taken.length, `${label}: held partway`).toBe(1);await page.waitForTimeout(150);if (change === 'held, then finished') {@@ -5004,7 +5088,9 @@ test.describe('animation state', () => {expect(after.at - startedAt).toBeLessThan(1_500);expect(after.translate).toBe('0px 120px');- const held = await holdAnimations(page, box);+ const held = await holdAnimations(page, box, {+ judges: {target: box, property: 'translate'},+ });expect(held[0].curveEndMs).toBeCloseTo(300, 0);const [mid, end] = await sampleCurve(box, [150, 300]);expect(mid.raw.translate).toBe('0px 60px');@@ -5534,6 +5620,7 @@ test.describe('storyboards', {tag: '@storyboard'}, () => {await expect(animationStoryboard(page, {name: 'harness-self-test-endless-only',+ judges: {target: page.locator('#box'), property: 'rotate'},clip: {x: 0, y: 340, width: 402, height: 120},}),).rejects.toThrow(/repeats forever/);diff --git a/internal/interaction-harness/src/storyboard.ts b/internal/interaction-harness/src/storyboard.tsindex 936c427138..7f0c32769a 100644--- a/internal/interaction-harness/src/storyboard.ts+++ b/internal/interaction-harness/src/storyboard.ts@@ -22,7 +22,12 @@*/import type {Locator, Page, TestInfo} from '@playwright/test';-import {holdAnimations, seekAnimations, type HeldAnimation} from './curves';+import {+ holdAnimations,+ seekAnimations,+ type HeldAnimation,+ type HoldJudges,+} from './curves';import {timeline} from './math';import {writeEvidence} from './output';import type {TouchScript} from './scripts';@@ -258,7 +263,7 @@ async function composeSheet(}}-export interface AnimationStoryboardOptions extends StoryboardOptions {+interface AnimationStoryboardBase extends StoryboardOptions {/*** Frame times, ms from the film's start: the earliest start among the held* animations that end (an animation that repeats forever, such as a@@ -269,16 +274,23 @@ export interface AnimationStoryboardOptions extends StoryboardOptions {readonly times?: readonly number[];/** Restrict to animations inside this element (when `held` is not passed). */readonly scope?: Locator;- /**- * What an armed hold already took (`armHold`'s `held()`): filmed instead of- * holding now, for an animation an action starts that a hold sent after- * the action could miss on a loaded runner.- */- readonly held?: readonly HeldAnimation[];/** Measurements per frame (runs after the seek). */readonly measure?: () => Promise<Readonly<Record<string, unknown>>>;}+/**+ * Either `held`, what an armed hold already took (`armHold`'s `held()`, which+ * checked its judged motion): filmed instead of holding now, for an animation+ * an action starts that a hold sent after the action could miss on a loaded+ * runner. Or `judges`, the motion the film shows: the film holds now, and+ * rejects as `holdAnimations` does when it took no animation of it.+ */+export type AnimationStoryboardOptions = AnimationStoryboardBase &+ (+ | {readonly held: readonly HeldAnimation[]; readonly judges?: undefined}+ | {readonly held?: undefined; readonly judges: HoldJudges}+ );+/*** Holds every running animation, then seeks them together to each time and* photographs the clip. Call it right after starting the animation under test,@@ -291,7 +303,7 @@ export async function animationStoryboard(): Promise<{storyboard: Storyboard; held: HeldAnimation[]}> {const held = options.held? [...options.held]- : await holdAnimations(page, options.scope);+ : await holdAnimations(page, options.scope, {judges: options.judges});if (held.length === 0) {throw new Error(`storyboard ${options.name}: no running animation to hold`);}diff --git a/packages/core/src/BottomSheet/__tests__/BottomSheetDetent.interaction.browser.spec.ts b/packages/core/src/BottomSheet/__tests__/BottomSheetDetent.interaction.browser.spec.tsindex 4945f088d9..885b04c609 100644--- a/packages/core/src/BottomSheet/__tests__/BottomSheetDetent.interaction.browser.spec.ts+++ b/packages/core/src/BottomSheet/__tests__/BottomSheetDetent.interaction.browser.spec.ts@@ -222,7 +222,9 @@ test('the settle lands on the detent, its curve recorded frame by frame', async// that the test sends after the lift can come after the settle ends.await freezePageOn(page, 'touchend');await driver.play(slowDragTo(handle, dy));- const held = await holdAnimations(page, sheet);+ const held = await holdAnimations(page, sheet, {+ judges: {target: sheet, property: 'transform'},+ });const transition = held.find(a => a.name === 'transform');if (transition == null) {throw new Error(`no transform transition held: ${JSON.stringify(held)}`);@@ -432,6 +434,7 @@ test(name: 'bottomsheet-settle',clip,scope: sheet,+ judges: {target: sheet, property: 'transform'},measure,columns: 7,cellScale: 0.4,diff --git a/packages/core/src/BottomSheet/__tests__/BottomSheetKeyboardInset.interaction.browser.spec.ts b/packages/core/src/BottomSheet/__tests__/BottomSheetKeyboardInset.interaction.browser.spec.tsindex 8cdceeefd1..7e9bb3458e 100644--- a/packages/core/src/BottomSheet/__tests__/BottomSheetKeyboardInset.interaction.browser.spec.ts+++ b/packages/core/src/BottomSheet/__tests__/BottomSheetKeyboardInset.interaction.browser.spec.ts@@ -333,7 +333,11 @@ test.describe('Chrome on Android, on Gboard\u2019s slides (spec:AST-099 FR8)', (expect(Math.abs(start - (reported - ANDROID_KEYBOARD.showReportLagMs)),).toBeLessThan(2);- const ride = rideOf(await holdAnimations(page, content));+ const ride = rideOf(+ await holdAnimations(page, content, {+ judges: {target: content, property: 'translate'},+ }),+ );const samples = curveOf(await sampleCurve(content, timeline(ride.offsetMs + ride.curveEndMs)),'translateY',@@ -442,7 +446,11 @@ test.describe('Chrome on Android, on Gboard\u2019s slides (spec:AST-099 FR8)', (expect(Math.abs(start - (reported - ANDROID_KEYBOARD.hideReportLagMs)),).toBeLessThan(2);- const ride = rideOf(await holdAnimations(page, content));+ const ride = rideOf(+ await holdAnimations(page, content, {+ judges: {target: content, property: 'translate'},+ }),+ );const samples = curveOf(await sampleCurve(content, timeline(ride.offsetMs + ride.curveEndMs)),'translateY',diff --git a/packages/core/src/BottomSheet/__tests__/BottomSheetNativeModal.a11y.browser.spec.ts b/packages/core/src/BottomSheet/__tests__/BottomSheetNativeModal.a11y.browser.spec.tsindex e0eaf1a99e..0bd3221a1e 100644--- a/packages/core/src/BottomSheet/__tests__/BottomSheetNativeModal.a11y.browser.spec.ts+++ b/packages/core/src/BottomSheet/__tests__/BottomSheetNativeModal.a11y.browser.spec.ts@@ -494,7 +494,9 @@ async function holdPhase(const started = await watch.started({timeout: 10_000});expect(started.map(animation => animation.name)).toContain(property);}- await holdAnimations(page);+ await holdAnimations(page, undefined, {+ judges: movers.map(mover => ({target: mover, property})),+ });await expect(page.locator('dialog[open]')).toHaveCount(2);}diff --git a/packages/core/src/Button/__tests__/ButtonPressRelease.interaction.browser.spec.ts b/packages/core/src/Button/__tests__/ButtonPressRelease.interaction.browser.spec.tsindex b2893f23cb..cb6a0f9b76 100644--- a/packages/core/src/Button/__tests__/ButtonPressRelease.interaction.browser.spec.ts+++ b/packages/core/src/Button/__tests__/ButtonPressRelease.interaction.browser.spec.ts@@ -208,7 +208,13 @@ for (const [name, story, locate] of ['fading',);await freezeTimers(page);- const held = await holdAnimations(page, opened.surface);+ const held = await holdAnimations(page, opened.surface, {+ judges: {+ target: opened.surface,+ property: 'opacity',+ pseudoElement: '::before',+ },+ });await releaseAnimations(page, {finish: true});await thawTimers(page);// One animation, of opacity alone, finished within 200 ms; nothing@@ -262,9 +268,11 @@ for (const [name, story, locate, pseudo] of ['fading',);await freezeTimers(page);- const held = (await holdAnimations(page, opened.surface)).filter(- animation => animation.kind === 'CSSAnimation',- );+ const held = (+ await holdAnimations(page, opened.surface, {+ judges: {target: opened.surface, property: '--astryx-press-alpha'},+ })+ ).filter(animation => animation.kind === 'CSSAnimation');const layer = await opened.surface.evaluate(el => getComputedStyle(el, '::before').content,);@@ -319,7 +327,13 @@ for (const [name, story, locate, pseudo] of ['fading',);await freezeTimers(page);- const held = await holdAnimations(page, opened.surface);+ const held = await holdAnimations(page, opened.surface, {+ judges: {+ target: opened.surface,+ property: 'opacity',+ pseudoElement: pseudo,+ },+ });const release = held.find(a => a.kind === 'CSSAnimation' && a.durationMs === RELEASE_MS,);@@ -741,6 +755,11 @@ test(name: 'button-press-release',clip,scope: opened.surface,+ judges: {+ target: opened.surface,+ property: 'opacity',+ pseudoElement: '::before',+ },times: timeline(RELEASE_MS),measure: async () => ({opacity: await layerOpacity(opened.surface, '::before'),diff --git a/packages/core/src/DateInput/__tests__/Wheel.interaction.browser.spec.ts b/packages/core/src/DateInput/__tests__/Wheel.interaction.browser.spec.tsindex 29481254b9..c53a31c96d 100644--- a/packages/core/src/DateInput/__tests__/Wheel.interaction.browser.spec.ts+++ b/packages/core/src/DateInput/__tests__/Wheel.interaction.browser.spec.ts@@ -770,7 +770,9 @@ test(columns: 6,cellScale: 0.5,});- const held = await holdAnimations(page, strip);+ const held = await holdAnimations(page, strip, {+ judges: {target: strip, property: 'translate'},+ });await thawPage(page);await freezeTimers(page);const {storyboard: coastBoard} = await animationStoryboard(page, {diff --git a/packages/core/src/Dialog/__tests__/DialogTouchEntrance.interaction.browser.spec.ts b/packages/core/src/Dialog/__tests__/DialogTouchEntrance.interaction.browser.spec.tsindex be1fb09e87..bdfd25ee96 100644--- a/packages/core/src/Dialog/__tests__/DialogTouchEntrance.interaction.browser.spec.ts+++ b/packages/core/src/Dialog/__tests__/DialogTouchEntrance.interaction.browser.spec.ts@@ -76,7 +76,9 @@ async function holdEntrance(page: Page): Promise<void> {?.getAnimations().some(animation => animation.playState === 'running') ?? false,);- const held = await holdAnimations(page, openDialogs(page));+ const held = await holdAnimations(page, openDialogs(page), {+ judges: {target: openDialogs(page), property: 'opacity'},+ });// Held: later transitions (an exit, the next open) keep their own timing.await page.evaluate(() =>document.getElementById('__slowEntrance')?.remove(),diff --git a/packages/core/src/Drawer/__tests__/DrawerTouchEntrance.interaction.browser.spec.ts b/packages/core/src/Drawer/__tests__/DrawerTouchEntrance.interaction.browser.spec.tsindex 56700c27a3..4b823a1ce0 100644--- a/packages/core/src/Drawer/__tests__/DrawerTouchEntrance.interaction.browser.spec.ts+++ b/packages/core/src/Drawer/__tests__/DrawerTouchEntrance.interaction.browser.spec.ts@@ -78,7 +78,9 @@ async function holdEntrance(page: Page): Promise<void> {.some(animation => animation.playState === 'running') ?? false,OPEN,);- const held = await holdAnimations(page, openDrawers(page));+ const held = await holdAnimations(page, openDrawers(page), {+ judges: {target: openDrawers(page), property: 'transform'},+ });// Held: later transitions (an exit, the next open) keep their own timing.await page.evaluate(() =>document.getElementById('__slowEntrance')?.remove(),diff --git a/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts b/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.tsindex 6a2485106b..c914f6885e 100644--- a/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts+++ b/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts@@ -583,7 +583,9 @@ test('past the minimum the zoom gives way, then springs back on springs.settle',const recognizerScale = pinchScale / (300 - 8);expect(shown).toBeCloseTo(1 / (2 - recognizerScale), 2);const [settle] = await waitForAnimation(photo);- const held = await holdAnimations(page, photo);+ const held = await holdAnimations(page, photo, {+ judges: {target: photo, property: 'scale'},+ });const duration = Math.max(...held.map(a => a.curveEndMs));const samples = curveOf(await sampleCurve(photo, timeline(duration)),@@ -681,7 +683,9 @@ test('a double tap zooms until the photo fills the screen, about the tapped poinconst tapped = photoPointAt(before, at);await driver.play(doubleTap(at));const [zoom] = await waitForAnimation(photo);- const held = await holdAnimations(page, photo);+ const held = await holdAnimations(page, photo, {+ judges: {target: photo, property: 'scale'},+ });const duration = Math.max(...held.map(a => a.curveEndMs));const samples = curveOf(await sampleCurve(photo, timeline(duration)),@@ -1370,6 +1374,7 @@ test(name: 'lightbox-return-from-past-minimum',clip,scope: photo,+ judges: {target: photo, property: 'scale'},measure,columns: 6,cellScale: 0.35,@@ -1400,6 +1405,7 @@ test(name: 'lightbox-double-tap-zoom-in',clip,scope: photo,+ judges: {target: photo, property: 'scale'},measure,columns: 6,cellScale: 0.35,diff --git a/packages/core/src/Lightbox/__tests__/LightboxZoomModes.interaction.browser.spec.ts b/packages/core/src/Lightbox/__tests__/LightboxZoomModes.interaction.browser.spec.tsindex 99224de6bb..5f75c4ec34 100644--- a/packages/core/src/Lightbox/__tests__/LightboxZoomModes.interaction.browser.spec.ts+++ b/packages/core/src/Lightbox/__tests__/LightboxZoomModes.interaction.browser.spec.ts@@ -222,7 +222,9 @@ test('under Reduce Motion a double tap cross-fades to its zoom instead of traveldoubleTap({x: rect.x + rect.width / 2, y: rect.y + rect.height / 2}),);await waitForAnimation(img);- const held = await holdAnimations(page, img);+ const held = await holdAnimations(page, img, {+ judges: {target: img, property: 'opacity'},+ });const duration = Math.max(...held.map(a => a.curveEndMs));const samples = await sampleCurve(img, timeline(duration));await releaseAnimations(page);@@ -514,7 +516,9 @@ test('under Reduce Motion a pinch released past the maximum settles in place, wi},},);- const held = await holdAnimations(page, img);+ const held = await holdAnimations(page, img, {+ judges: {target: img, property: 'opacity'},+ });expect(held.length).toBeGreaterThan(0);const duration = Math.max(...held.map(a => a.curveEndMs));const opacity = curveOf(diff --git a/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts b/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.tsindex aed3e3d326..9dee0b6099 100644--- a/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts+++ b/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts@@ -753,6 +753,7 @@ test(name: 'list-row-press-release',clip,scope: row,+ judges: {target: row, property: 'opacity', pseudoElement: '::before'},measure: async () => ({opacity: await layerOpacity(row),state: await pressState(row),diff --git a/packages/core/src/List/__tests__/ListRowPressPaths.interaction.browser.spec.ts b/packages/core/src/List/__tests__/ListRowPressPaths.interaction.browser.spec.tsindex bbe05fb86f..8bbb95567d 100644--- a/packages/core/src/List/__tests__/ListRowPressPaths.interaction.browser.spec.ts+++ b/packages/core/src/List/__tests__/ListRowPressPaths.interaction.browser.spec.ts@@ -222,7 +222,9 @@ test('Reduce Motion keeps the release fade: a fade, not a movement', async ({tap({x: box.x + box.width / 2, y: box.y + box.height / 2}, {holdMs: 300}),);const releaseMs = await exitMsOf(row);- await holdAnimations(page);+ await holdAnimations(page, undefined, {+ judges: {target: row, property: 'opacity', pseudoElement: '::before'},+ });await seekAnimations(page, 0);expect(await layerOpacity(row)).toBeCloseTo(1, 2);await seekAnimations(page, releaseMs / 2);@@ -303,7 +305,9 @@ test('under a finger, a row held and released between two divided rows keeps bot);// Released: halfway through the release fade.const releaseMs = await exitMsOf(pressed);- await holdAnimations(page);+ await holdAnimations(page, undefined, {+ judges: {target: pressed, property: 'opacity', pseudoElement: '::before'},+ });await seekAnimations(page, releaseMs / 2);expect(await pressState(pressed)).toBe('fading');await expectDividersAsAtRest('releasing');diff --git a/packages/core/src/Popover/__tests__/PopoverTouchMotion.interaction.browser.spec.ts b/packages/core/src/Popover/__tests__/PopoverTouchMotion.interaction.browser.spec.tsindex b91717f089..48ae21d26a 100644--- a/packages/core/src/Popover/__tests__/PopoverTouchMotion.interaction.browser.spec.ts+++ b/packages/core/src/Popover/__tests__/PopoverTouchMotion.interaction.browser.spec.ts@@ -460,7 +460,9 @@ test('the presentation grows out of the trigger on the theme\u2019s entrance tokawait expect(exitCopyOf(page)).toHaveCount(0);await openWithTap(story);await scaleAnimationOf(story.layer);- const held = await holdAnimations(page, story.layer);+ const held = await holdAnimations(page, story.layer, {+ judges: {target: story.layer, property: 'scale'},+ });const samples = await sampleBoxes(story.layer,final,diff --git a/packages/core/src/SegmentedControl/__tests__/SegmentedControl.interaction.browser.spec.ts b/packages/core/src/SegmentedControl/__tests__/SegmentedControl.interaction.browser.spec.tsindex 58b0bb043d..627f5ba6e0 100644--- a/packages/core/src/SegmentedControl/__tests__/SegmentedControl.interaction.browser.spec.ts+++ b/packages/core/src/SegmentedControl/__tests__/SegmentedControl.interaction.browser.spec.ts@@ -1549,7 +1549,13 @@ test(await control.tapSegment('grid');await advanceFrozenPage(page, 80);await control.tapSegment('list');- const retargetHeld = await holdAnimations(page, control.group);+ const retargetHeld = await holdAnimations(page, control.group, {+ judges: {+ target: control.group,+ property: 'translate',+ pseudoElement: '::before',+ },+ });await thawPage(page);await freezeTimers(page);const {storyboard: retargetBoard} = await animationStoryboard(page, {diff --git a/packages/core/src/Slider/__tests__/SliderTouch.interaction.browser.spec.ts b/packages/core/src/Slider/__tests__/SliderTouch.interaction.browser.spec.tsindex eeba330fb7..1ae4ef88f9 100644--- a/packages/core/src/Slider/__tests__/SliderTouch.interaction.browser.spec.ts+++ b/packages/core/src/Slider/__tests__/SliderTouch.interaction.browser.spec.ts@@ -445,9 +445,11 @@ test('a release coasts on UIKit’s spring to 0.4 of the momentum projection, th// under load. The harness counts sample times from the earliest held// start, so the samples are taken at the coast's own times: its offset// plus 0, 20, …- const coast = (await holdAnimations(page, thumb)).find(held =>- held.keyframes.some(keyframe => 'translate' in keyframe),- );+ const coast = (+ await holdAnimations(page, thumb, {+ judges: {target: thumb, property: 'translate'},+ })+ ).find(held => held.keyframes.some(keyframe => 'translate' in keyframe));expect(coast, 'the coast plays on the compositor').toBeDefined();const coastOffset = coast?.offsetMs ?? 0;const times = Array.from({length: 31}, (_, i) => coastOffset + i * 20);diff --git a/packages/core/src/Spinner/__tests__/SpinnerMotion.a11y.chromium.spec.ts b/packages/core/src/Spinner/__tests__/SpinnerMotion.a11y.chromium.spec.tsindex 57f1c81606..01c8c87ec5 100644--- a/packages/core/src/Spinner/__tests__/SpinnerMotion.a11y.chromium.spec.ts+++ b/packages/core/src/Spinner/__tests__/SpinnerMotion.a11y.chromium.spec.ts@@ -386,6 +386,7 @@ test('storyboard: one revolution, frame by frame @storyboard', async ({name: 'spinner-ring-cycle',clip: xl,scope: xl,+ judges: {target: rotor, property: 'transform'},columns: 12,cellScale: 2,times: timeline(duration - 1),diff --git a/packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.ts b/packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.tsindex d677985eeb..ca548953fa 100644--- a/packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.ts+++ b/packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.ts@@ -912,7 +912,20 @@ test.describe('Switch touch presentation (UISwitch, iOS 26.2), under a finger',await freezeTimers(page);const row = page.locator('#storybook-root [data-astryx-pressable]').first();const exit = await exitOf(row);- const held = await holdAnimations(page, row);+ const held = await holdAnimations(page, row, {+ judges: [+ {+ target: page.locator('#storybook-root .astryx-switch').first(),+ property: 'opacity',+ pseudoElement: '::before',+ },+ {+ target: page.locator('#storybook-root .astryx-switch-thumb').first(),+ property: 'opacity',+ pseudoElement: '::before',+ },+ ],+ });// One CSS animation per press layer runs the release, the track's and// the thumb's (design:user-states DR1), each its opacity on the shared// release's clock. The row's strength has no release of its own under a finger (no@@ -1009,9 +1022,24 @@ test.describe('Switch touch presentation (UISwitch, iOS 26.2), under a finger',const row = page.locator('#storybook-root [data-astryx-pressable]').first();- const css = (await holdAnimations(page, row)).filter(- a => a.kind === 'CSSAnimation',- );+ const css = (+ await holdAnimations(page, row, {+ judges: [+ {+ target: page.locator('#storybook-root .astryx-switch').first(),+ property: 'opacity',+ pseudoElement: '::before',+ },+ {+ target: page+ .locator('#storybook-root .astryx-switch-thumb')+ .first(),+ property: 'opacity',+ pseudoElement: '::before',+ },+ ],+ })+ ).filter(a => a.kind === 'CSSAnimation');// Present first: the track's layer and the thumb's.expect(css.map(a => (a.target ?? '').split('.')[1]).sort()).toEqual(['astryx-switch',diff --git a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.tsindex 9770da5380..ec9ec1112f 100644--- a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts+++ b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts@@ -456,7 +456,12 @@ test('a push follows UIKit’s push spring, the card underneath at 0.3 of its spconst watch = await watchAnimations(top);await driver.tap(await rowCenter(page, 'General'));await watch.started();- await holdAnimations(page);+ await holdAnimations(page, undefined, {+ judges: [+ {target: top, property: 'translate'},+ {target: under, property: 'translate'},+ ],+ });const times = Array.from({length: 31}, (_, i) => i * 16.667);const samples: {t: number; top: number; under: number; analytic: number}[] =@@ -793,7 +798,9 @@ test('brought back past its start, the screen follows with resistance, then spriframes.push({t: last.t + steps * 16.7 + 4, fingers: []});await driver.play(frames);// The return, held where it runs and read every 2 ms from its start.- const heldAnimations = await holdAnimations(page, top);+ const heldAnimations = await holdAnimations(page, top, {+ judges: {target: top, property: 'translate'},+ });const returnIndex = await top.evaluate(element =>((window as unknown as {__harnessHeld?: Animation[]}).__harnessHeld ?? []@@ -2348,6 +2355,10 @@ test('storyboard: a push', {tag: '@storyboard'}, async ({page}, testInfo) => {const viewport = page.viewportSize() ?? {width: 402, height: 714};const {storyboard} = await animationStoryboard(page, {name: 'navigationstack-push',+ judges: [+ {target: top, property: 'translate'},+ {target: card(page, 'root'), property: 'translate'},+ ],clip: {x: 0, y: 0, width: viewport.width, height: viewport.height},// The spring is at rest by ~0.45 s; the animator holds end states after.times: Array.from({length: 28}, (_, i) => i * 16.667),diff --git a/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.ts b/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.tsindex f785f26875..bfafd6102c 100644--- a/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.ts+++ b/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.ts@@ -318,6 +318,7 @@ test(name: 'navigation-stack-scroll-edge-appear',clip,scope: layer,+ judges: {target: layer, property: 'opacity'},measure: async () => ({opacity: await presentedOpacity(layer)}),columns: 6,cellScale: 0.5,