Files
hyperframes/packages/studio/tests/e2e/edit-accuracy/versions.test.mjs
Miguel Ángel 9c19327e38 test(studio): catch teleports and multi-step edit bugs in the edit accuracy bench (#4801)
* test(studio): catch teleports and multi-step edit bugs in the edit accuracy bench

* test(studio): share the edit accuracy case harness between single gestures and sequences

* test(studio): keep edit accuracy helpers private unless shared

* test(studio): score plain-CSS edits on pages that load GSAP for other elements

* test(studio): add an idle GSAP axis value so plain-CSS edits are scored on GSAP pages

* test(studio): report a slow undo save as late with its latency, apart from a lost one

* test(studio): sample the gap between back-to-back drags and allow one frame of lag

* test(studio): read the edge from the element's fractional size, so a crop edge is exact

* test(studio): keep waiting for a late save until an undone file stays put for 3 s

* ci(studio): run the edit accuracy grid in 12 shards to stay near 25 minutes each

* test(studio): read edit bench frames just before paint, so unpainted states never count

* test(studio): scope the edit bench frame sampler so page globals cannot clash

* test(studio): let a lagging box catch up the pointer travel it owes, so a held frame is no jump

* test(studio): record every save a sequence makes, even two that land 10 ms apart

* test(studio): end a drag's teleport scoring at its pointer-up, not at the next element's press

* test(studio): bank for each edit accuracy case a run that agrees with the gate's verdict

* test(studio): fail the edit accuracy gate on a teleport or an unmeasured drag

* test(studio): fail the edit accuracy gate when a text edit is not saved or shown

* test(studio): measure but do not gate the edit accuracy cases a known Studio race flips

* test(studio): bank the edit accuracy cases that newly pass with the teleport metric

* test(studio): quarantine the two nudge sequences whose redo write sits at the 2 s limit

* style(studio): cut three bench comments to one line each
2026-10-01 09:42:05 -07:00

28 lines
989 B
JavaScript

import { mkdtempSync, renameSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { watchVersions } from "./sequences.mjs";
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
describe("watchVersions", () => {
it("records two saves that land 10 ms apart, each as its own version", async () => {
const dir = mkdtempSync(join(tmpdir(), "edit-bench-versions-"));
const file = join(dir, "index.html");
// Studio's own write: a whole file renamed into place.
const save = (text) => {
writeFileSync(`${file}.tmp`, text);
renameSync(`${file}.tmp`, file);
};
save("start");
const watcher = watchVersions(dir, ["index.html"]);
save("nudged");
await sleep(10);
save("dragged");
await sleep(100);
watcher.stop();
expect(watcher.versions.map((v) => v["index.html"])).toEqual(["start", "nudged", "dragged"]);
});
});