Isometric line figures that answer the pointer. For React and for anything with a DOM.
Skill: look hears the lap page's console under 12, and says the tour never started when the figure did not mount
Lucas Marques14c478132837
diff --git a/packages/hairline/test/browser/look.spec.ts b/packages/hairline/test/browser/look.spec.tsindex 8be9092..66eca27 100644--- a/packages/hairline/test/browser/look.spec.ts+++ b/packages/hairline/test/browser/look.spec.ts@@ -139,4 +139,33 @@ test.describe("look.mjs", () => {expect(out).toMatch(/^14 tour: fail\. Stop 0 leaves the read-out at "rest"/m);expect(code).toBe(1);});++ test("fails 12 console, naming the lap, when the figure throws as the tour moves it", async () => {+ const cwd = mkdtempSync(join(tmpdir(), "hl-look-"));+ const terrain = readFileSync(SKILL + "examples/terrain.js", "utf8");+ /* the shots each move the pointer once, so only the lap reaches the second move */+ const jumpy = terrain+ .replace(" bag.add(pointer(stage, {\n", " let moves = 0;\n bag.add(pointer(stage, {\n")+ .replace("move: (p) => { over = unproj(C, p[0], p[1], 0); retarget(); },", 'move: (p) => { if (++moves === 2) throw new Error("moved twice"); over = unproj(C, p[0], p[1], 0); retarget(); },');+ expect(jumpy).toContain("let moves = 0;");+ expect(jumpy).toContain("moved twice");+ writeFileSync(join(cwd, "terrain.js"), jumpy);+ const { code, out } = await look(cwd, "terrain.js");+ expect(out).toMatch(/^12 console: fail\. .*moved twice.* \(lap\)/m);+ expect(code).toBe(1);+ });++ test("says the tour never started when the figure throws as it mounts, without waiting out the lap", async () => {+ const cwd = mkdtempSync(join(tmpdir(), "hl-look-"));+ const src = readFileSync(SKILL + "examples/terrain.js", "utf8").replace(/^(function mount\(.*\{)$/m, '$1\n throw new Error("no drawing today");');+ expect(src).toContain("no drawing today");+ writeFileSync(join(cwd, "terrain.js"), src);+ const t0 = Date.now();+ const { code, out } = await look(cwd, "terrain.js");+ expect(out).toMatch(/^14 tour: fail\. The tour never started because the figure did not mount: .*no drawing today/m);+ expect(out).not.toContain("Does the figure call HL.pointer");+ expect(code).toBe(1);+ /* the lap alone could hold it 20 seconds */+ expect(Date.now() - t0).toBeLessThan(25_000);+ });});diff --git a/skills/hairline-create/look.mjs b/skills/hairline-create/look.mjsindex 8632cb2..733a8e2 100644--- a/skills/hairline-create/look.mjs+++ b/skills/hairline-create/look.mjs@@ -375,14 +375,16 @@ export async function look(src, given0 = {}, cwd = process.cwd()) {// the motion strip: the bench under ?play=1, a picture every EVERY ms from the first stop until stop 0 comes round againconst motion = [];- let motionOut = null, reached = [];+ let motionOut = null, reached = [], lap = null, started = false;if (decl.tour) {- const lap = await open(context, address("play=1"), true);+ lap = await open(context, address("play=1"), true);await sleep(WAIT);const box = (await lap.page.evaluate(STATE)).stage;+ /* a figure that did not mount never wired the play button: there is no lap to wait for */+ started = await lap.page.evaluate(() => !!window.hairline?.playing);const t0 = Date.now();let seen = 0, first = -1;- while (Date.now() - t0 < LAP_CAP) {+ while (started && Date.now() - t0 < LAP_CAP) {const s = await lap.page.evaluate(() => ({ stops: window.__stops.slice(), read: document.getElementById("read").textContent, svg: document.getElementById("stage").innerHTML }));const fresh = s.stops.slice(seen);seen = s.stops.length;@@ -428,8 +430,11 @@ export async function look(src, given0 = {}, cwd = process.cwd()) {// each complaint once, with the shots that made itconst noise = new Map();- for (const s of shots) for (const b of [...s.bad, ...(s.error ? [`error line under the stage: ${s.error}`] : [])]) noise.set(b, [...(noise.get(b) ?? []), s.name]);- const heard = [...noise].map(([b, where]) => `${b} (${where.length === shots.length ? "every shot" : where.join(", ")})`);+ for (const s of [...shots, ...(lap ? [{ name: "lap", bad: lap.bad }] : [])]) for (const b of [...s.bad, ...(s.error ? [`error line under the stage: ${s.error}`] : [])]) noise.set(b, [...(noise.get(b) ?? []), s.name]);+ const heard = [...noise].map(([b, where]) => {+ const shotsOnly = where.filter((n) => n !== "lap"), onLap = where.includes("lap");+ return `${b} (${shotsOnly.length === shots.length ? `every shot${onLap ? " and the lap" : ""}` : where.join(", ")})`;+ });if (heard.length) fail(`12 console: fail. ${heard.slice(0, 4).join("; ")}${heard.length > 4 ? `; and ${heard.length - 4} more` : ""}.`);else console.log("12 console: ok. No console error or warning, no page error, no error line under the stage.");@@ -449,7 +454,10 @@ export async function look(src, given0 = {}, cwd = process.cwd()) {// the lap: every point stop answers and holds stillif (!decl.tour) console.log("14 tour: not measured. The figure declares no tour.");- else {+ else if (!started) {+ const why = lap.bad.find((b) => b.startsWith("page error")) ?? lap.bad[0];+ fail(`14 tour: fail. The tour never started because the figure did not mount: ${why ?? "the play button was never wired"}. Fix that first; 12 console has it.`);+ } else {const r = tourLine(reached, decl.tour);if (r.ok) console.log(r.line); else fail(r.line);}