Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/studio/tests/e2e/edit-accuracy/sequences.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ export async function restedFor(
throw new Error("an edit was still waiting or saving");
}

/** The box once Studio says the preview is done, and the ms until it said so: an undo's reload shows only then. */
export async function shownOnceRested(busy, frame, settle, options) {
const shownMs = await restedFor(busy, frame, options);
return { box: await settle(), shownMs };
}

// A sealed press waits for the previous save, then replays, and a sealed undo shows only once the preview applies it.
const studioBusy = (page) =>
page.evaluate(
Expand Down Expand Up @@ -610,7 +616,14 @@ async function measureSequence({ spec, dir, files, evidence }, session, control,
);
// The file the steps should have left: the last surviving save's, or the original when all were undone.
const expected = spec.settle ? (stack.at(-1)?.after ?? versions[0]) : versions.at(-1);
const undone = await settled(ctx.A);
const rested = () =>
shownOnceRested(
() => studioBusy(page),
() => nextFrame(page),
() => settled(ctx.A),
);
const undoneAt = await rested();
const undone = undoneAt.box;
await shoot("undone");
const redo = undo.ok
? await walk(
Expand All @@ -624,7 +637,8 @@ async function measureSequence({ spec, dir, files, evidence }, session, control,
history,
)
: { ok: false, landed: [] };
const redone = undo.ok ? await settled(ctx.A) : null;
const redoneAt = undo.ok ? await rested() : null;
const redone = redoneAt?.box ?? null;
// A late write must not land under the reload.
await waitForFiles(ctx.A, { timeout: 15_000 });

Expand Down Expand Up @@ -691,6 +705,8 @@ async function measureSequence({ spec, dir, files, evidence }, session, control,
// The slowest write of each walk, judged by the single-case undo rule.
ms: slowest(undo.writes),
redoMs: slowest(redo.writes),
shownMs: undoneAt.shownMs,
redoShownMs: redoneAt?.shownMs ?? null,
},
undoTimeout: saveFault([
...undo.writes.map((w) => ["undo", w]),
Expand Down
12 changes: 11 additions & 1 deletion packages/studio/tests/e2e/edit-accuracy/settle.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
swapPending,
unsettledBy,
} from "./case.mjs";
import { heldSize, keyedBy, restedFor } from "./sequences.mjs";
import { heldSize, keyedBy, restedFor, shownOnceRested } from "./sequences.mjs";

describe("settling on the shown preview", () => {
const read = (pending, x = 0, frames = "a") => ({
Expand Down Expand Up @@ -315,6 +315,16 @@ describe("the end of a sequence", () => {
expect(await restedFor(busy, frame, { now })).toBe(20);
});

// fails without the fix: the undo was read while its reload was on the way, 240-329 px from where it landed.
it("reads an undo's box once Studio says its reload is done, and how long that took", async () => {
const { busy, frame, now, read } = reads([true, true, true, false, false]);
const settle = async () => (read() > 3 ? "undone" : "before");
expect(await shownOnceRested(busy, frame, settle, { now })).toEqual({
box: "undone",
shownMs: 30,
});
});

it("gives up with a reason when an edit never stops saving", async () => {
const { busy, frame, now } = reads([true]);
await expect(restedFor(busy, frame, { now, timeout: 30 })).rejects.toThrow(
Expand Down
Loading