← snapshot
2053 bytes
import { chromium } from "@playwright/test";
const [from, into, paths] = process.argv.slice(2);
const b = await chromium.launch();
const p = await b.newPage({ viewport: { width: 1500, height: 1000 }, colorScheme: "dark" });
const errs = [];
p.on("pageerror", e => errs.push(e.message));
await p.goto(`http://localhost:3000/lab/diff?from=${from}&into=${into}&paths=${encodeURIComponent(paths)}`, { waitUntil: "networkidle" });
await p.waitForSelector(".jac-diffm", { timeout: 20000 });
await p.waitForFunction(() => !document.body.innerText.includes("reading "), { timeout: 30000 });
await p.waitForTimeout(600);
const cursorAt = () => p.evaluate(() => {
const el = document.querySelector('[data-cursor="true"]');
return el ? Number(el.dataset.row) : null;
});
console.log("cursor before any key:", await cursorAt());
await p.keyboard.press("n");
await p.waitForTimeout(350);
const h1 = await cursorAt();
await p.keyboard.press("n");
await p.waitForTimeout(350);
const h2 = await cursorAt();
console.log("n, n ->", h1, h2, h2 !== null && h1 !== null && h2 > h1 ? "advances ✓" : "(single hunk or wrapped)");
await p.keyboard.press("j"); await p.waitForTimeout(200);
const j = await cursorAt();
await p.keyboard.press("k"); await p.waitForTimeout(200);
const k = await cursorAt();
console.log("j then k ->", j, k, k === h2 ? "returns ✓" : "moved");
await p.keyboard.press("G"); await p.waitForTimeout(300);
console.log("G -> last row:", await cursorAt());
await p.keyboard.press("g"); await p.waitForTimeout(300);
console.log("g -> first row:", await cursorAt());
await p.keyboard.press("?"); await p.waitForTimeout(400);
console.log("? overlay:", await p.locator(".jac-diffm-keys").count() > 0);
await p.screenshot({ path: "tour/lab/diff-keys.png" });
await p.keyboard.press("?"); await p.waitForTimeout(300);
await p.keyboard.press("]"); await p.waitForTimeout(500);
console.log("] changed file:", (await p.locator(".jac-diffm-path").textContent())?.trim());
console.log("errors:", errs.length ? errs.slice(0,2) : "none");
await b.close();