Skip to content

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

TypeScript

test(interaction-harness): an armed hold names the motion it judges (#10386)

Cindy Zhang28270c1439b6
diff --git a/docs/architecture/component-test-sufficiency.md b/docs/architecture/component-test-sufficiency.md
index 6ff46334ab..2c64aeead5 100644
--- a/docs/architecture/component-test-sufficiency.md
+++ b/docs/architecture/component-test-sufficiency.md
@@ -16,6 +16,7 @@ applies_to:
packages/charts/src/,
packages/richtext/src/,
packages/vega/src/,
+ internal/interaction-harness/,
]
verified_by: [component verification maps and their linked test evidence]
deciding_specs: []
@@ -119,7 +120,10 @@ rows, or inventory entries.
when its promised behavior is removed, inverted, routed to the wrong owner, or
otherwise materially broken. An assertion that recomputes the implementation,
repeats a type/source declaration, checks a constant against itself, or snapshots
- unrelated output does not prove the promise.
+ unrelated output does not prove the promise. A motion judgement holds and
+ asserts the judged motion itself, named by its target element and animated
+ property; a held count alone does not prove it, since other animations can fill
+ the count.
- **INV7 — Coverage remains bounded and intentional.** Test volume has a named
behavioral, evidence-layer, or risk reason. Multiple evidence layers are not
duplicates when each observes a distinct required contract boundary, such as
@@ -348,7 +352,7 @@ behavior.
| INV2–INV3 | Critical-promise, behavior-defect, documentation-correction, and historical-regression fixtures | A primary, accessibility, callback, compatibility, composition, or previously fixed behavior defect loses its only mutation-sensitive evidence and still passes, or an unchanged prose-only documentation correction is required to add a regression test |
| INV4 | Rational-partition fixtures | Proven-equivalent values require duplicate tests, private implementation identity is required to establish equivalence, or behaviorally different states collapse into one case |
| INV5 | Public/runtime/compile-time seam replacement fixtures | Incidental private assertions pass while the promised user or consumer outcome is broken, contractual DOM/type/class/target evidence is incorrectly rejected, a DOM/class assertion is credited for pixels it cannot observe, or selector/state behavior is misclassified as a value-only visual change |
-| INV6 | Tautology, declaration-copy, snapshot-noise, and behavior mutations | An insensitive assertion receives credit, or a meaningful behavior mutation leaves the credited test green |
+| INV6 | Tautology, declaration-copy, snapshot-noise, and behavior mutations; a held set missing the named motion | An insensitive assertion receives credit, a meaningful behavior mutation leaves the credited test green, or a motion judgement passes on unrelated animations |
| INV7 | Same-partition duplicates, justified multi-layer evidence, exhaustive Cartesian, and broad defensive matrix fixtures | Distinct required evidence layers are collapsed as duplicates, or volume without a named distinct risk is credited as sufficiency |
| INV8 | Verification-map relationship fixtures | Every audit row mechanically becomes a test, evidence cannot be traced to authority, or one test cannot satisfy inseparable requirements |
| INV9 | Pull-request and audit-run red/green trace fixtures | Audit-authored remediation lacks a failing pre-change case, production remediation precedes the new case, or horizontal test generation replaces one observable vertical slice |
diff --git a/internal/interaction-harness/README.md b/internal/interaction-harness/README.md
index 3f16c3271d..b78cb5535b 100644
--- a/internal/interaction-harness/README.md
+++ b/internal/interaction-harness/README.md
@@ -105,13 +105,20 @@ animations, ones the page paused and ones on a scroll or view timeline are left
alone; held animations keep their offsets from the first hold's earliest start, and release
resumes only them. A hold sent from the test reaches the page after a round
trip, and on a loaded runner a short animation can end first: for one that an
-action starts, `await armHold(page, scope)` before the action arms the page
+action starts, `await armHold(page, scope, {judges})` before the action arms the page
itself: it looks on every frame and every 4 ms between frames (WebKit can go
about 70 ms without a frame while it first composites a layer),
holds everything running under the scope as soon as one of them runs (or
`count` of them, for parts that start apart; with `newOnly`, only what starts
after the arm, for a turn that starts mid-motion), and `held()` after the
-action returns that held set. Compare it with an
+action returns that held set. Other animations under the scope (a press, a
+colour change) can meet that count before the motion a test judges starts,
+and a hold that took only them proves nothing about it. So every armed hold
+names the motion it judges, `{judges: {target, property}}` (a list for
+several; `pseudoElement` for a `::before` or `::after`), and `held()` rejects
+when 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.
+Compare it with an
oracle from `math.ts` through `compareCurve`; a tolerance states the error
budget (for a spring baked into `linear()` stops of `h` ms, chords err by up to
`h² / 8 · |x''|`). A seek past an animation's end lands half a millisecond
diff --git a/internal/interaction-harness/src/curves.ts b/internal/interaction-harness/src/curves.ts
index ec8b17c793..cf227f471b 100644
--- a/internal/interaction-harness/src/curves.ts
+++ b/internal/interaction-harness/src/curves.ts
@@ -6,7 +6,8 @@
* the Web Animations API in the page (CSS transitions and CSS animations are
* Web Animations too)
* @output `holdAnimations` (pause every running animation and describe it),
- * `armHold` (the page holds what an action starts, as soon as it runs),
+ * `armHold` (the page holds what an action starts, as soon as it runs,
+ * and checks that it took the motion the test judges),
* `seekAnimations` (move them to t ms from the held origin, each keeping
* its offset), `sampleCurve` (the presented
* transform/opacity at each t, with the individual `translate`, `rotate` and
@@ -677,10 +678,43 @@ export async function holdAnimations(
/** An armed hold (`armHold`): the page holds on its own; read what it held. */
export interface ArmedHold {
- /** What the page held, once an animation under the scope ran. */
+ /**
+ * What the page held, once an animation under the scope ran. Rejects when
+ * the hold took no animation of a judged motion.
+ */
held(): Promise<HeldAnimation[]>;
}
+/**
+ * A motion that a test judges from an armed hold: an animation of `property`
+ * on `target`.
+ */
+export interface JudgedMotion {
+ readonly target: Locator;
+ /**
+ * The animated property, as CSS names it (`translate`, `background-color`,
+ * `--press-strength`).
+ */
+ readonly property: string;
+ /** The pseudo-element that runs the motion, when the target's own does. */
+ readonly pseudoElement?: '::before' | '::after';
+}
+
+/**
+ * The motions an armed hold must take. `'count-only'` checks none: it marks a
+ * call site whose hold does not yet take the motion that the test judges.
+ */
+export type HoldJudges = JudgedMotion | readonly JudgedMotion[] | 'count-only';
+
+/** How an armed hold waits (`armHold`), and what it must take. */
+export interface ArmHoldOptions {
+ readonly judges: HoldJudges;
+ readonly count?: number;
+ readonly minProgressMs?: number;
+ readonly newOnly?: boolean;
+ readonly timeout?: number;
+}
+
let armedHolds = 0;
/**
@@ -705,28 +739,40 @@ let armedHolds = 0;
* `held()` rejects when nothing under the scope runs within `timeout` ms of
* arming.
*
+ * `judges` names the motion that the test reads from the hold. Other
+ * animations under the scope (a press, a colour change) can meet the count
+ * before that motion starts, and a hold that took only them proves nothing
+ * about it. So `held()` also rejects when the hold took no animation of
+ * each judged motion.
+ *
* @example
* ```
- * const hold = await armHold(page, row);
+ * const hold = await armHold(page, row, {
+ * judges: {target: row, property: 'opacity'},
+ * });
* await driver.play(tap(center, {holdMs: 400}));
* const [release] = await hold.held();
* ```
*/
export async function armHold(
page: Page,
- scope?: Locator,
- {
+ scope: Locator | undefined,
+ options: ArmHoldOptions,
+): Promise<ArmedHold> {
+ const {
+ judges,
count = 1,
minProgressMs = 0,
newOnly = false,
timeout = 5_000,
- }: {
- count?: number;
- minProgressMs?: number;
- newOnly?: boolean;
- timeout?: number;
- } = {},
-): Promise<ArmedHold> {
+ } = 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 scopeHandle = scope ? await scope.elementHandle() : null;
await installCurveEnd(page);
armedHolds += 1;
@@ -738,12 +784,14 @@ export async function armHold(
root: Element | null,
skip?: ReadonlySet<Animation>,
) => unknown[];
+ __harnessHeld?: Animation[];
__harnessTimerGate?: {
frame?: typeof requestAnimationFrame;
now?: () => number;
timeout?: typeof setTimeout;
};
__harnessArmed?: Record<number, Promise<unknown[]>>;
+ __harnessArmedTook?: Record<number, Animation[]>;
};
// The harness's own waits run on the real timers: a frozen timer gate
// (story.ts) holds only the page's.
@@ -803,7 +851,17 @@ export async function armHold(
if (document.getAnimations().filter(counts).length >= needed) {
done = true;
try {
- resolve(w.__harnessHold(root, before));
+ 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),
+ };
+ resolve(took);
} catch (error) {
reject(error);
}
@@ -834,21 +892,126 @@ export async function armHold(
] as const,
);
return {
- held: () =>
- page.evaluate(key => {
+ held: async () => {
+ const held = await page.evaluate(key => {
const w = window as unknown as {
__harnessArmed?: Record<number, Promise<HeldAnimation[]>>;
};
- const held = w.__harnessArmed?.[key];
- if (held == null) {
+ const armed = w.__harnessArmed?.[key];
+ if (armed == null) {
throw new Error('armHold: this hold was never armed on this page');
}
delete w.__harnessArmed?.[key];
- return held;
- }, id),
+ return armed;
+ }, id);
+ await expectJudgedMotionsHeld(page, id, motions, count);
+ 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.
+ */
+async function expectJudgedMotionsHeld(
+ page: Page,
+ key: number,
+ motions: readonly JudgedMotion[],
+ count: number,
+): Promise<void> {
+ 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`,
+ );
+ }),
+ ),
+ );
+ const {missing, took} = await page.evaluate(
+ ([armed, elements, wanted]) => {
+ const w = window as unknown as {
+ __harnessArmedTook?: Record<number, Animation[]>;
+ };
+ const animations = w.__harnessArmedTook?.[armed] ?? [];
+ delete w.__harnessArmedTook?.[armed];
+ // `getKeyframes()` names a property in camel case, except a custom
+ // property.
+ const keyframeName = (property: string) =>
+ property.startsWith('--')
+ ? property
+ : property.replace(/-([a-z])/g, (_, letter: string) =>
+ letter.toUpperCase(),
+ );
+ const properties = (animation: Animation) => [
+ ...new Set(
+ ((animation.effect as KeyframeEffect | null)?.getKeyframes() ?? [])
+ .flatMap(keyframe => Object.keys(keyframe))
+ .filter(
+ name =>
+ !['offset', 'computedOffset', 'easing', 'composite'].includes(
+ name,
+ ),
+ ),
+ ),
+ ];
+ const describe = (animation: Animation) => {
+ const effect = animation.effect as KeyframeEffect | null;
+ const target = effect?.target ?? null;
+ const name =
+ target == null
+ ? 'no target'
+ : target.tagName.toLowerCase() +
+ (target.id ? `#${target.id}` : '') +
+ (target.classList.length
+ ? `.${[...target.classList].slice(0, 2).join('.')}`
+ : '');
+ return `${name}${effect?.pseudoElement ?? ''} ${properties(animation).join(' ')}`;
+ };
+ return {
+ missing: wanted.flatMap((motion, index) =>
+ animations.some(animation => {
+ const effect = animation.effect as KeyframeEffect | null;
+ return (
+ effect != null &&
+ effect.target === elements[index] &&
+ (effect.pseudoElement ?? null) === motion.pseudoElement &&
+ properties(animation).includes(keyframeName(motion.property))
+ );
+ })
+ ? []
+ : [index],
+ ),
+ took: animations.map(describe),
+ };
+ },
+ [
+ key,
+ targets,
+ motions.map(motion => ({
+ property: motion.property,
+ pseudoElement: motion.pseudoElement ?? null,
+ })),
+ ] as const,
+ );
+ if (missing.length > 0) {
+ const judged = missing
+ .map(index => {
+ const motion = motions[index];
+ return `${motion.property} on ${motion.target.toString()}${motion.pseudoElement ?? ''}`;
+ })
+ .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: ` +
+ `${took.length > 0 ? took.join('; ') : 'nothing'}. ` +
+ 'Arm the hold so that it waits for the judged motion (count, newOnly, minProgressMs, scope).',
+ );
+ }
+}
+
/**
* Moves every held animation to `timeMs` from the held origin (delay
* included): each to its own `timeMs - offsetMs`. A time at or past an
diff --git a/internal/interaction-harness/src/harness.interaction.browser.spec.ts b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
index 9913a2c410..9ebfef041b 100644
--- a/internal/interaction-harness/src/harness.interaction.browser.spec.ts
+++ b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
@@ -2702,7 +2702,9 @@ test.describe('curve sampling', () => {
const box = page.locator('#box');
// Armed before the 400 ms transition starts, so a busy runner cannot end
// it before the hold.
- const hold = await armHold(page, box);
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'transform'},
+ });
await box.evaluate(el => {
el.style.transition = 'transform 400ms cubic-bezier(0.24, 1, 0.4, 1)';
void (el as HTMLElement).offsetWidth;
@@ -2731,7 +2733,9 @@ test.describe('curve sampling', () => {
const duration = 1200;
// Armed before the run starts, so a busy runner cannot end it before the
// hold.
- const hold = await armHold(page, box);
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'transform'},
+ });
await box.evaluate(
(el, {stops, ms}) => {
el.animate(
@@ -2840,6 +2844,37 @@ test.describe('pseudo-element animations', () => {
});
});
+/**
+ * Adds a thumb inside the fixture's box: the box presses, the thumb travels,
+ * as in a switch.
+ */
+async function pressAndTravelFixture(page: Page) {
+ await page.locator('#box').evaluate(el => {
+ const thumb = document.createElement('div');
+ thumb.id = 'thumb';
+ thumb.style.cssText = 'width:20px;height:20px;background:#fff';
+ el.append(thumb);
+ });
+ return {box: page.locator('#box'), thumb: page.locator('#thumb')};
+}
+
+/**
+ * Starts the box's press fade, then the thumb's 2 s travel 150 ms later. The
+ * travel is a new animation then, as a release starts its own.
+ */
+async function startPressThenTravel(page: Page) {
+ await page.evaluate(() => {
+ document
+ .getElementById('box')
+ ?.animate([{opacity: 1}, {opacity: 0.6}], {duration: 2_000});
+ setTimeout(() => {
+ document
+ .getElementById('thumb')
+ ?.animate([{translate: '0px'}, {translate: '20px'}], {duration: 2_000});
+ }, 150);
+ });
+}
+
test.describe('holding', () => {
test('an armed hold takes a short animation on its first frames, from the page itself', async ({
page,
@@ -2849,7 +2884,9 @@ test.describe('holding', () => {
// Armed before the animation starts: the page holds it on the first frame
// it has run, however late a busy runner would have delivered a hold sent
// after it (a 120 ms run can end first).
- const hold = await armHold(page, box);
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'transform'},
+ });
await box.evaluate(el =>
el.animate(
[{transform: 'translateY(0px)'}, {transform: 'translateY(200px)'}],
@@ -2887,7 +2924,10 @@ test.describe('holding', () => {
{duration: 10_000, easing: 'linear'},
),
);
- const hold = await armHold(page, box, {newOnly: true});
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'opacity'},
+ newOnly: true,
+ });
await box.evaluate(el =>
el.animate([{opacity: 1}, {opacity: 0}], {
duration: 120,
@@ -2913,18 +2953,81 @@ test.describe('holding', () => {
page,
}) => {
await fixture(page);
- const hold = await armHold(page, page.locator('#box'), {timeout: 200});
+ const box = page.locator('#box');
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'transform'},
+ timeout: 200,
+ });
await expect(hold.held()).rejects.toThrow(
/no animation under the scope ran/,
);
});
+ test('an armed hold rejects when other animations meet its count before the judged motion starts', async ({
+ page,
+ }) => {
+ await fixture(page);
+ const {box, thumb} = await pressAndTravelFixture(page);
+ const hold = await armHold(page, box, {
+ judges: {target: thumb, property: 'translate'},
+ });
+ await startPressThenTravel(page);
+ await expect(hold.held()).rejects.toThrow(
+ /took no animation of the judged motion \(translate on .*#thumb.*\)\. Other animations met its count of 1 first; 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('an armed hold whose count waits for the judged motion returns it', async ({
+ page,
+ }) => {
+ await fixture(page);
+ const {box, thumb} = await pressAndTravelFixture(page);
+ const hold = await armHold(page, box, {
+ judges: {target: thumb, property: 'translate'},
+ count: 2,
+ });
+ await startPressThenTravel(page);
+ const held = await hold.held();
+ expect(held.map(a => a.target)).toEqual(['div#box', 'div#thumb']);
+ await releaseAnimations(page, {finish: true});
+ });
+
+ test("an armed hold with judges: 'count-only' checks what it took against nothing", async ({
+ page,
+ }) => {
+ await fixture(page);
+ const {box} = await pressAndTravelFixture(page);
+ const hold = await armHold(page, box, {judges: 'count-only'});
+ await startPressThenTravel(page);
+ expect((await hold.held()).map(a => a.target)).toEqual(['div#box']);
+ await releaseAnimations(page, {finish: true});
+ });
+
+ test('an armed hold refuses to arm without the motion it judges', async ({
+ page,
+ }) => {
+ await fixture(page);
+ await expect(
+ // @ts-expect-error -- a caller without types can omit `judges`.
+ armHold(page, page.locator('#box'), {count: 1}),
+ ).rejects.toThrow(/armHold: 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');
// Armed before the 300 ms run starts, so a busy runner cannot end it
// before the hold.
- const hold = await armHold(page, box);
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'transform'},
+ });
await box.evaluate(el =>
el.animate(
[{transform: 'translateY(0px)'}, {transform: 'translateY(200px)'}],
@@ -3050,7 +3153,12 @@ test.describe('holding', () => {
// #box moves for 300 ms and fades for 400 ms; another element runs longer.
// Armed before they start (all in one task), so a busy runner cannot end
// the move before the hold.
- const hold = await armHold(page);
+ const hold = await armHold(page, undefined, {
+ judges: [
+ {target: page.locator('#box'), property: 'transform'},
+ {target: page.locator('#box'), property: 'opacity'},
+ ],
+ });
await page.evaluate(() => {
const box = document.getElementById('box');
box?.animate(
@@ -3093,7 +3201,16 @@ test.describe('holding', () => {
await fixture(page);
// #box moves for 300 ms; its ::after fades for 600 ms. Armed before they
// start, so a busy runner cannot end the move before the hold.
- const hold = await armHold(page);
+ const hold = await armHold(page, undefined, {
+ judges: [
+ {target: page.locator('#box'), property: 'transform'},
+ {
+ target: page.locator('#box'),
+ property: 'opacity',
+ pseudoElement: '::after',
+ },
+ ],
+ });
await page.evaluate(() => {
const style = document.createElement('style');
style.textContent = "#box::after { content: ''; display: block; }";
@@ -3122,7 +3239,9 @@ test.describe('holding', () => {
const box = page.locator('#box');
// Each hold is armed before its 300 ms run starts, so a busy runner
// cannot end the run before the hold.
- const hold = await armHold(page, box);
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'translate'},
+ });
await box.evaluate(el => {
el.style.width = '80.6px';
el.style.height = '40.4px';
@@ -3139,7 +3258,9 @@ test.describe('holding', () => {
// animation with the first one still running.
await releaseAnimations(page, {finish: true});
- const second = await armHold(page, box);
+ const second = await armHold(page, box, {
+ judges: {target: box, property: 'translate'},
+ });
await box.evaluate(el => {
el.animate(
[
@@ -3457,8 +3578,13 @@ test.describe('holding', () => {
const box = page.locator('#box');
// Both holds are armed before the 300 ms runs start, so a busy runner
// cannot end either before its hold; each adds to the held set.
- const first = await armHold(page, box);
- const second = await armHold(page, page.locator('#other'));
+ const other = page.locator('#other');
+ const first = await armHold(page, box, {
+ judges: {target: box, property: 'transform'},
+ });
+ const second = await armHold(page, other, {
+ judges: {target: other, property: 'opacity'},
+ });
await page.evaluate(() => {
document
.getElementById('box')
@@ -3550,7 +3676,9 @@ test.describe('holding', () => {
const box = page.locator('#box');
// Armed before the 300 ms transition starts, so a busy runner cannot end
// it before the hold.
- const hold = await armHold(page, box);
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'transform'},
+ });
await box.evaluate(el => {
el.style.transition = 'transform 300ms linear';
el.getBoundingClientRect();
@@ -3591,7 +3719,12 @@ test.describe('holding', () => {
await fixture(page);
// Armed before the 300 ms fade starts, so a busy runner cannot end it
// before the hold.
- const hold = await armHold(page);
+ const hold = await armHold(page, undefined, {
+ judges: [
+ {target: page.locator('#box'), property: 'rotate'},
+ {target: page.locator('#fade'), property: 'opacity'},
+ ],
+ });
await page.evaluate(() => {
const box = document.getElementById('box');
box?.animate([{rotate: '0deg'}, {rotate: '360deg'}], {
@@ -4867,7 +5000,9 @@ test.describe('storyboards', {tag: '@storyboard'}, () => {
const box = page.locator('#box');
// Armed before the 200 ms run starts, so a busy runner cannot end it
// before the film holds it.
- const hold = await armHold(page, box);
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'transform'},
+ });
await box.evaluate(el =>
el.animate(
[{transform: 'translateX(0)'}, {transform: 'translateX(240px)'}],
@@ -5143,7 +5278,9 @@ test.describe('storyboards', {tag: '@storyboard'}, () => {
// set and its 300 ms run starts, so on a busy runner neither the timer
// nor the run's end can come before them.
await freezeTimers(page);
- const hold = await armHold(page, box);
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'transform'},
+ });
// A component that ends its own animation from a timer (a transitionend
// backstop): without the gate it would finish behind the held storyboard.
await box.evaluate(el => {
@@ -5186,7 +5323,9 @@ test.describe('storyboards', {tag: '@storyboard'}, () => {
await fixture(page);
// Armed before the 200 ms fade starts, so a busy runner cannot end it
// before the film holds it.
- const hold = await armHold(page, page.locator('#box'));
+ const hold = await armHold(page, page.locator('#box'), {
+ judges: {target: page.locator('#box'), property: 'rotate'},
+ });
await page.locator('#box').evaluate(el => {
el.animate([{rotate: '0deg'}, {rotate: '360deg'}], {
duration: 800,
@@ -5214,7 +5353,13 @@ test.describe('storyboards', {tag: '@storyboard'}, () => {
// move that starts 83 ms after it. The page holds all three once the
// second move runs, so a busy runner cannot end the first move before the
// film holds it.
- const hold = await armHold(page, undefined, {count: 3});
+ const hold = await armHold(page, undefined, {
+ judges: [
+ {target: page.locator('#first'), property: 'transform'},
+ {target: page.locator('#second'), property: 'transform'},
+ ],
+ count: 3,
+ });
await page.evaluate(async () => {
const make = (id: string, top: number) => {
const el = document.createElement('div');
@@ -5713,7 +5858,10 @@ test.describe('page freeze', () => {
const box = page.locator('#box');
const samples = await sampleRects(box, 200);
expect(samples.length).toBeGreaterThan(3);
- const hold = await armHold(page, box, {timeout: 300});
+ const hold = await armHold(page, box, {
+ judges: {target: box, property: 'transform'},
+ timeout: 300,
+ });
await expect(hold.held()).rejects.toThrow(
'armHold: no animation under the scope ran within 300 ms',
);
diff --git a/packages/core/src/CheckboxList/__tests__/CheckboxListPress.a11y.chromium.spec.ts b/packages/core/src/CheckboxList/__tests__/CheckboxListPress.a11y.chromium.spec.ts
index e8c3c65029..d2b03104aa 100644
--- a/packages/core/src/CheckboxList/__tests__/CheckboxListPress.a11y.chromium.spec.ts
+++ b/packages/core/src/CheckboxList/__tests__/CheckboxListPress.a11y.chromium.spec.ts
@@ -560,7 +560,14 @@ test.describe('CheckboxList row press', () => {
// The page holds the release itself as soon as it runs. A hold the test
// sends after the lift arrives later on a busy machine, and the release
// can end first.
- const hold = await armHold(page, page.locator('li[data-astryx-press]'));
+ const pressed = page.locator('li[data-astryx-press]');
+ const hold = await armHold(page, pressed, {
+ judges: {
+ target: pressed,
+ property: 'opacity',
+ pseudoElement: '::before',
+ },
+ });
await row.lift(row.label);
await freezeTimers(page);
expect(await rowPress(page)).toBe('fading');
diff --git a/packages/core/src/Lightbox/LightboxFinePointer.a11y.browser.spec.ts b/packages/core/src/Lightbox/LightboxFinePointer.a11y.browser.spec.ts
index a20f6b65c1..914b66651d 100644
--- a/packages/core/src/Lightbox/LightboxFinePointer.a11y.browser.spec.ts
+++ b/packages/core/src/Lightbox/LightboxFinePointer.a11y.browser.spec.ts
@@ -246,7 +246,10 @@ async function expectSpringZoom(
// The page holds the zoom itself as it starts: a hold sent from the test
// would reach a busy page late. Runs that an earlier zoom left in their end
// hold are not this zoom.
- const hold = await armHold(page, img, {newOnly: true});
+ const hold = await armHold(page, img, {
+ judges: {target: img, property: 'scale'},
+ newOnly: true,
+ });
await act();
const held = await hold.held();
expect(
diff --git a/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts b/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts
index 7e5c2646b1..8945b3c0bc 100644
--- a/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts
+++ b/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts
@@ -258,7 +258,9 @@ test('a held row paints the pressed token and its release follows the exit easin
// The page holds the release itself as soon as it runs. A hold the test
// sends after the lift arrives later on a busy machine, and the release
// can end first.
- const hold = await armHold(page, row);
+ const hold = await armHold(page, row, {
+ judges: {target: row, property: 'opacity', pseudoElement: '::before'},
+ });
await driver.play(tap(center, {holdMs: HOLD_MS}));
expect(await pressState(row)).toBe('fading');
await freezeTimers(page);
diff --git a/packages/core/src/Popover/__tests__/PopoverTouchMotion.interaction.browser.spec.ts b/packages/core/src/Popover/__tests__/PopoverTouchMotion.interaction.browser.spec.ts
index 4941db5c17..b91717f089 100644
--- a/packages/core/src/Popover/__tests__/PopoverTouchMotion.interaction.browser.spec.ts
+++ b/packages/core/src/Popover/__tests__/PopoverTouchMotion.interaction.browser.spec.ts
@@ -936,7 +936,7 @@ test('Reduce Motion: the popover cross-fades in at its size and out where it sta
}) => {
await page.emulateMedia({reducedMotion: 'reduce'});
const story = await openDefault(page);
- await openHeldWhileGrowing(page, story);
+ await openHeldWhileGrowing(page, story, 'opacity');
const unit = {x: 0, y: 0, width: 100, height: 100};
// design:reduced-motion DR2: opacity only, 200 ms or less, here on
// UIKit's cross-fade curve.
@@ -968,7 +968,7 @@ test('Reduce Motion: the popover cross-fades in at its size and out where it sta
expect(sample.opacity).toBeCloseTo(1, 3);
}
// The dismissal fades out where the popover stands, on the same curve.
- const dismissal = await armExitCopyHold(story);
+ const dismissal = await armExitCopyHold(story, 'opacity');
await page.keyboard.press('Escape');
await dismissal.held();
const copy = exitCopyOf(page);
@@ -1141,11 +1141,16 @@ async function holdsOn(target: Locator): Promise<boolean> {
* Arms a hold for the exit copy before the action that closes the popover.
* The copy does not exist yet, so the hold arms on the layer's parent. The
* dismissal places it there for a popover in no other layer. Only motions
- * that start after arming count, and the held motion must be the copy's.
+ * that start after arming count, and the held motion must be the copy's:
+ * its `scale`, or its `opacity` under Reduce Motion.
*/
-async function armExitCopyHold(story: OpenStory) {
+async function armExitCopyHold(
+ story: OpenStory,
+ property: 'scale' | 'opacity' = 'scale',
+) {
const page = story.layer.page();
const armed = await armHold(page, story.layer.locator('xpath=..'), {
+ judges: {target: exitCopyOf(page), property},
newOnly: true,
});
return {
@@ -1162,10 +1167,17 @@ async function armExitCopyHold(story: OpenStory) {
/**
* Opens the popover with a tap and holds its presentation where it starts, so
* the next press lands while it grows. Under Reduce Motion it holds the
- * cross-fade. Returns the held motion; release it with `releaseAnimations`.
+ * cross-fade (`property: 'opacity'`). Returns the held motion; release it
+ * with `releaseAnimations`.
*/
-async function openHeldWhileGrowing(page: Page, story: OpenStory) {
- const armed = await armHold(page, story.layer);
+async function openHeldWhileGrowing(
+ page: Page,
+ story: OpenStory,
+ property: 'scale' | 'opacity' = 'scale',
+) {
+ const armed = await armHold(page, story.layer, {
+ judges: {target: story.layer, property},
+ });
await openWithTap(story);
const held = await armed.held();
expect(await holdsOn(story.layer), 'held on the popover').toBe(true);
diff --git a/packages/core/src/ProgressBar/__tests__/ProgressBarMotion.a11y.chromium.spec.ts b/packages/core/src/ProgressBar/__tests__/ProgressBarMotion.a11y.chromium.spec.ts
index 1b20cd7d64..58dab733c7 100644
--- a/packages/core/src/ProgressBar/__tests__/ProgressBarMotion.a11y.chromium.spec.ts
+++ b/packages/core/src/ProgressBar/__tests__/ProgressBarMotion.a11y.chromium.spec.ts
@@ -1019,7 +1019,10 @@ test('storyboard: the fill moving from 20% to 80% @storyboard', async ({
// frame interval at a time through its end. A screencast of the change
// shows only the frames a loaded runner gets to capture, and one it misses
// doubles the step between the two around it.
- const hold = await armHold(page, page.getByRole('progressbar'));
+ const bar = page.getByRole('progressbar');
+ const hold = await armHold(page, bar, {
+ judges: {target: bar.locator(':scope > *').first(), property: 'transform'},
+ });
await setValue(page, 80);
const {storyboard} = await animationStoryboard(page, {
name: 'progress-bar-fill-move',
diff --git a/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts b/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts
index aca0cd4eb9..297f6f0906 100644
--- a/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts
+++ b/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts
@@ -357,31 +357,45 @@ test.afterEach(async ({page}, testInfo) => {
* the input, so it holds the motion at its first frame. A long input can
* outlast the hold's own 5 s. The driver paces its events on the wall clock,
* and on a loaded runner they play much longer than scripted. Then the hold
- * is armed again for what is left of 5 s from the input's end.
+ * is armed again for what is left of 5 s from the input's end. `property` is
+ * the track's judged motion: `translate`, or `opacity` for a cross-fade.
*/
async function playHeld(
page: Page,
track: Locator,
driver: TouchDriver,
script: TouchScript,
+ property: 'translate' | 'opacity' = 'translate',
): Promise<ArmedHold> {
- const first = await armHold(page, track);
+ const judges = {target: track, property};
+ const first = await armHold(page, track, {judges});
const caught = first.held().then(
held => ({held}),
- () => null,
+ (error: unknown) => ({error}),
);
await driver.play(script);
const inputEnd = Date.now();
return {
held: async () => {
const outcome = await caught;
- if (outcome != null) {
+ if ('held' in outcome) {
return outcome.held;
}
+ // Only a hold that ran out of time is armed again. A hold that took
+ // the wrong motion fails with its own error.
+ const timedOut = (error: unknown) =>
+ String(error).includes('no animation under the scope ran');
+ if (!timedOut(outcome.error)) {
+ throw outcome.error;
+ }
const again = await armHold(page, track, {
+ judges,
timeout: Math.max(0, inputEnd + 5_000 - Date.now()),
});
- return again.held().catch(() => {
+ return again.held().catch((error: unknown) => {
+ if (!timedOut(error)) {
+ throw error;
+ }
throw new Error(
'no motion under the track started within 5 s of the input ending',
);
@@ -390,9 +404,19 @@ async function playHeld(
};
}
-/** Calls `goTo(index)` with the motion it starts held at its first frame. */
-const goToHeld = async (page: Page, track: Locator, index: number) => {
- const hold = await armHold(page, track);
+/**
+ * Calls `goTo(index)` with the motion it starts held at its first frame.
+ * `property` is the track's judged motion, as for `playHeld`.
+ */
+const goToHeld = async (
+ page: Page,
+ track: Locator,
+ index: number,
+ property: 'translate' | 'opacity' = 'translate',
+) => {
+ const hold = await armHold(page, track, {
+ judges: {target: track, property},
+ });
await page.evaluate(next => {
window.armFrames();
window.pager.goTo(next);
@@ -922,7 +946,7 @@ test('under Reduce Motion the settle and goTo do not travel: an opacity cross-fa
{x: 320, y: 200},
{velocity: {x: -1500, y: 0}, durationMs: 80},
);
- const hold = await playHeld(page, track, driver, throwScript);
+ const hold = await playHeld(page, track, driver, throwScript, 'opacity');
crossFadesOnly(await hold.held());
await releaseAnimations(page);
await expect
@@ -930,7 +954,7 @@ test('under Reduce Motion the settle and goTo do not travel: an opacity cross-fa
.toBe(false);
expect(await page.evaluate(() => window.pager.index)).toBe(2);
// goTo cross-fades too.
- crossFadesOnly(await goToHeld(page, track, 4));
+ crossFadesOnly(await goToHeld(page, track, 4, 'opacity'));
await releaseAnimations(page);
await expect
.poll(async () => page.evaluate(() => window.pager.isSettling))
diff --git a/packages/lab/src/PageControl/__tests__/PageControl.interaction.browser.spec.ts b/packages/lab/src/PageControl/__tests__/PageControl.interaction.browser.spec.ts
index cb1a41f651..f74cef14fa 100644
--- a/packages/lab/src/PageControl/__tests__/PageControl.interaction.browser.spec.ts
+++ b/packages/lab/src/PageControl/__tests__/PageControl.interaction.browser.spec.ts
@@ -837,7 +837,10 @@ test('under Reduce Motion nothing slides or scales, the current indicator and a
// holds every animation under the control once one has run 60 ms, past the
// window's 50 ms delay.
const current = await indicatorCenter(slider, 25);
- const hold = await armHold(page, slider, {minProgressMs: 60});
+ const hold = await armHold(page, slider, {
+ judges: {target: slider.locator(':scope > *').first(), property: 'opacity'},
+ minProgressMs: 60,
+ });
await driver.tap({x: current.x + 12, y: current.y});
await expect.poll(async () => valueNow(slider)).toBe(27);
// Every animation is an opacity fade of at most 200 ms. No translate or
@@ -1328,7 +1331,12 @@ test('storyboard: the window slides one slot @storyboard', async ({page}) => {
// Armed before the tap, the page holds the change's motion as it starts,
// however late the test reads it. That motion is the old indicator's fade
// and the slide, which starts 50 ms after the change.
- const hold = await armHold(page, slider);
+ const hold = await armHold(page, slider, {
+ judges: [
+ {target: slider.locator(':scope > *').first(), property: 'translate'},
+ {target: slider.locator('[data-page="26"]'), property: 'scale'},
+ ],
+ });
await driver.tap({x: current.x + 12, y: current.y});
const held = await hold.held();
const {storyboard} = await animationStoryboard(page, {