`compile()` for tests
busk() only accepts steps — one script, one clock. Mock UI updates belong in { run } steps or click handlers, not parallel schedules on the routine.
compile() runs the same timeline math as busk() without mounting a show. You use it to assert glide times, loop length, and when { run } steps fire.
What you pass in
Section titled “What you pass in”steps— the routine script (Stepshapes).resolveTarget— yourResolveTargetcallback. Busker does not ship a default for tests; you decide where selectors “are” in px.motion(optional) — usuallyDEFAULT_MOTIONin app code, or a fixed config in tests so distances map to predictable ms.start(optional) — cursor start in px, default[0, 0]. (On a live routine,startis a fraction of the root;busk()converts that to px before compiling.)
Example
Section titled “Example”Stub selectors to fixed positions so assertions stay stable:
import {compile} from '@logfox/busker';import type {Point} from '@logfox/busker';
const resolveTarget = (to: string | Point, from: Point): Point | null => { if (Array.isArray(to)) { // Fractions → px the same way as a 100×100 root in tests return [to[0] * 100, to[1] * 100]; } if (to === '#save') return [200, 40]; if (to === '#cancel') return [280, 40];
return from;};
const fixedMotion = {pxPerSecond: 1e9, minMoveMs: 100, dwellMs: 50};
const {glides, duration, runs} = compile( [{wait: 100}, {click: '#save'}, {wait: 200}, {run: () => {}}, {click: '#cancel'}], resolveTarget, fixedMotion, [0, 0],);
// glides[0] → { to: '#save', from: 100, until: 200, press: 250 }// runs[0].at → 650 (after wait, click beat, and wait: 200)// duration → 1520 (includes ring after last click)Return shape and field types: Glide, ScheduledRun, and compile() in the API reference.
- Match
motionto what you care about: realDEFAULT_MOTIONfor integration-style checks, exaggeratedpxPerSecond/minMoveMsin unit tests for round numbers. - Return
nullfromresolveTargetwhen an element is hidden; compile uses a short glide. At runtime,busk()can remeasure and callstretchGlide()— seetimeline.spec.tsin the repo. - Need when each step starts (not just glides and runs)? Use
compileStepStarts().