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
17 changes: 9 additions & 8 deletions packages/studio/tests/e2e/edit-accuracy/case.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ export const nextFrame = (page, n = 1) =>
n,
);

/** One nudge burst of `count` right-arrow presses, then a frame. Back to back: Studio saves a burst once it has had no
* key for CANVAS_NUDGE_COMMIT_DEBOUNCE_MS, and a frame wait between keys made one slow frame that pause. */
export async function pressNudges(page, count) {
for (let i = 0; i < count; i++) await page.keyboard.press("ArrowRight");
await nextFrame(page);
}

export function readFiles(dir, files) {
return Object.fromEntries(files.map((f) => [f, readFileSync(join(dir, f), "utf8")]));
}
Expand Down Expand Up @@ -868,10 +875,7 @@ async function measureControl(browser, gesture) {
const read = () => readQuads(ctx);
if (gesture === "nudge") {
await recording(page, true);
for (let i = 0; i < NUDGES; i++) {
await page.keyboard.press("ArrowRight");
await nextFrame(page);
}
await pressNudges(page, NUDGES);
await nextFrame(page, 2);
return smoothness(await recording(page, false));
}
Expand Down Expand Up @@ -980,10 +984,7 @@ export async function pointerGesture(ctx, gesture, pre, route) {

async function nudgeGesture(ctx, pre) {
await recording(ctx.page, true);
for (let i = 0; i < NUDGES; i++) {
await ctx.page.keyboard.press("ArrowRight");
await nextFrame(ctx.page);
}
await pressNudges(ctx.page, NUDGES);
await nextFrame(ctx.page, 2);
const smooth = smoothness(await recording(ctx.page, false));
const m = await measure(ctx);
Expand Down
26 changes: 24 additions & 2 deletions packages/studio/tests/e2e/edit-accuracy/saves.test.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { saveFault, timedWrite } from "./case.mjs";
import { describe, expect, it, vi } from "vitest";
import { CANVAS_NUDGE_COMMIT_DEBOUNCE_MS } from "../../../src/components/editor/domEditNudge";
import { pressNudges, saveFault, timedWrite } from "./case.mjs";
import { slowest } from "./sequences.mjs";
import { score, UNDO_WRITE_MAX_MS } from "./report.mjs";

Expand Down Expand Up @@ -63,3 +64,24 @@ describe("undo and redo saves", () => {
expect(score({}, measured(null, slowest(walk.slice(0, 1)))).checks.undo).toBe(true);
});
});

describe("a nudge burst", () => {
it("presses every key inside Studio's burst window, however slow a frame is", async () => {
vi.useFakeTimers();
try {
const pressedAt = [];
const page = {
keyboard: { press: async () => void pressedAt.push(Date.now()) },
// A frame longer than the burst window, as the GPU stall after a rotate gave on CI.
evaluate: () => new Promise((r) => setTimeout(r, CANVAS_NUDGE_COMMIT_DEBOUNCE_MS + 50)),
};
const pressed = pressNudges(page, 3);
await vi.runAllTimersAsync();
await pressed;
expect(pressedAt).toHaveLength(3);
expect(pressedAt.at(-1) - pressedAt[0]).toBeLessThan(CANVAS_NUDGE_COMMIT_DEBOUNCE_MS);
} finally {
vi.useRealTimers();
}
});
});
8 changes: 3 additions & 5 deletions packages/studio/tests/e2e/edit-accuracy/sequences.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
nextFrame,
openStudio,
pointerGesture,
pressNudges,
readFiles,
recording,
sameFiles,
Expand Down Expand Up @@ -263,10 +264,7 @@ async function driveStep(ctx, step, state) {
}
if (step.do === "nudge") {
await recording(page, true);
for (let i = 0; i < step.count; i++) {
await page.keyboard.press("ArrowRight");
await nextFrame(page);
}
await pressNudges(page, step.count);
state.smooth.push(smoothness(await recording(page, false)));
state.depth += 1;
state.intended = (await measure(ctx.A)).visible;
Expand Down Expand Up @@ -383,7 +381,7 @@ async function editText(c, step, state) {
}
// Typing with no session open would land on Studio's shortcuts, so a failed open types nothing.
if (opened) {
// One key per frame, as the nudges press theirs: a whole word in one frame is no typist's pace.
// One key per frame: a whole word in one frame is no typist's pace.
for (const key of step.word) {
await page.keyboard.type(key);
await nextFrame(page);
Expand Down
Loading