From fa1ac235424c6257eedb19ef4636aa862744d86e Mon Sep 17 00:00:00 2001 From: onmax Date: Wed, 18 Nov 2026 10:14:10 +0100 Subject: [PATCH 1/3] test(annotate): check the tour's bracket edge in the frame, not through a spy on draw() --- packages/annotate/test/tour.test.ts | 52 ++++++++++++++++++----------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/packages/annotate/test/tour.test.ts b/packages/annotate/test/tour.test.ts index 3e3e0452..060e911a 100644 --- a/packages/annotate/test/tour.test.ts +++ b/packages/annotate/test/tour.test.ts @@ -4,9 +4,8 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { promisify } from "node:util"; import { createCanvas, loadImage } from "@napi-rs/canvas"; -import { describe, expect, it, vi } from "vite-plus/test"; +import { describe, expect, it } from "vite-plus/test"; import { plan, toScreen, cameraAt, type TourNote } from "../src/tour/plan.ts"; -import * as marks from "../src/marks.ts"; import { tour } from "../src/tour.ts"; // A light page with a dark bar where the change is, as a data URI. @@ -70,23 +69,38 @@ describe("tour", () => { expect(video.duration).toBeGreaterThan(video.shots.at(-1)!.end); }); - it.each([ - ['x=10 y=20 w=70 h=5 side="top"', "top"], - ['x=10 y=20 w=70 h=5 side="left" at=80', "bottom"], - ])("preserves bracket orientation: %s", async (attributes, edge) => { - const source = page({ x: 90, y: 72 }); - const annotation = `::::annotation{${attributes} mark="bracket"}\nBracket\n::::`; - const screenshot = `:::screenshot{src="${source}" alt="Page" viewport="900x360"}\n${annotation}\n:::`; - const video = await tour(`::compare\n${screenshot}\n${screenshot}\n::`); - const draw = vi.spyOn(marks, "draw"); - try { - for (const shot of video.shots) await video.frame(shot.end - 0.1); - await video.frame(video.duration - 1); - expect(draw.mock.calls.length).toBeGreaterThanOrEqual(3); - expect(draw.mock.calls.every((call) => call[4] === edge)).toBe(true); - } finally { - draw.mockRestore(); - } + it("draws a bracket across the edge that faces its note, as the page does", async () => { + const canvas = createCanvas(900, 360); + const context = canvas.getContext("2d"); + context.fillStyle = "#fff"; + context.fillRect(0, 0, 900, 360); + const source = canvas.toDataURL(); + // The rows of each shot's last frame that the bracket's spine crosses: blue for more than half the width. + const spines = async (attributes: string) => { + const annotation = `::::annotation{x=10 y=20 w=70 h=5 ${attributes} mark="bracket" color="#0000ff"}\nBracket\n::::`; + const screenshot = `:::screenshot{src="${source}" alt="Page" viewport="900x360"}\n${annotation}\n:::`; + const video = await tour(`::compare\n${screenshot}\n${screenshot}\n::`); + const rows: number[] = []; + for (const shot of video.shots) { + const frame = await loadImage(await video.frame(shot.end - 0.1)); + const canvas = createCanvas(frame.width, frame.height); + const context = canvas.getContext("2d"); + context.drawImage(frame, 0, 0); + const { data, width, height } = context.getImageData(0, 0, frame.width, frame.height); + for (let y = 0; y < height; y++) { + let blue = 0; + for (let i = y * width * 4; i < (y + 1) * width * 4; i += 4) + if (data[i + 2]! - Math.max(data[i]!, data[i + 1]!) > 60) blue++; + if (blue > width / 2) rows.push(y); + } + } + return rows; + }; + const top = await spines('side="top"'); + const bottom = await spines('side="left" at=80'); + expect(top).not.toEqual([]); + expect(bottom).not.toEqual([]); + expect(Math.max(...top)).toBeLessThan(Math.min(...bottom)); }); it.each(["before", "after"])("shows both states for %s-only changes", async (side) => { From 4f2cb3fabe4221477b936a5f78a489ba92575ec9 Mon Sep 17 00:00:00 2001 From: onmax Date: Wed, 18 Nov 2026 10:14:10 +0100 Subject: [PATCH 2/3] test(ui): wait for real before checking the file input stays attached --- packages/ui/test/editor-upload.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/ui/test/editor-upload.test.ts b/packages/ui/test/editor-upload.test.ts index 7f07c386..f53d18ca 100644 --- a/packages/ui/test/editor-upload.test.ts +++ b/packages/ui/test/editor-upload.test.ts @@ -192,7 +192,8 @@ describe("chooseFiles", () => { multiple: true, accept: "image/*,video/*,audio/*", }); - await Promise.resolve(); + // WebKit needs the input attached for as long as the picker is open, not just for a microtask. + await new Promise((resolve) => setTimeout(resolve, 20)); expect(input.isConnected).toBe(true); input.dispatchEvent(new Event("change")); expect(input.isConnected).toBe(false); From 160a06e38ac6fb2e86b7758e559f29a108573afc Mon Sep 17 00:00:00 2001 From: onmax Date: Wed, 18 Nov 2026 10:57:46 +0100 Subject: [PATCH 3/3] test: assert behavior, not internal names or docs wording These tests went red on refactors that kept behavior: the name of an inlined script's function, which property a crashing lint rule read first, the number of .svelte files in a folder, and an import path in two Doctor pages. Each now checks what a page or caller sees, and the docs-wording lines are gone. --- packages/annotate/test/annotate.test.ts | 10 ++++-- packages/links/test/frameworks.test.ts | 11 ++++-- packages/lint/test/lint.test.ts | 39 ++++++++------------- packages/lint/test/mermaid.test.ts | 7 ---- packages/mark/test/frameworks.test.ts | 11 ++++-- packages/outline/test/toc.test.ts | 3 +- packages/properties/test/properties.test.ts | 6 ++-- packages/ui/test/ui.test.ts | 2 +- 8 files changed, 46 insertions(+), 43 deletions(-) diff --git a/packages/annotate/test/annotate.test.ts b/packages/annotate/test/annotate.test.ts index b7218f88..627b9b3c 100644 --- a/packages/annotate/test/annotate.test.ts +++ b/packages/annotate/test/annotate.test.ts @@ -5,9 +5,10 @@ import { join } from "node:path"; import { promisify } from "node:util"; import { renderHtmlFromDocument } from "@comark/html"; import { parseMarkdown } from "comark"; +import { scripts as carouselScripts } from "comark-carousel/html"; import security from "comark/plugins/security"; import { afterEach, describe, expect, it, vi } from "vite-plus/test"; -import annotate, { components } from "../src/html.ts"; +import annotate, { components, scripts } from "../src/html.ts"; import xref from "../../xref/src/index.ts"; async function run(markdown: string, options?: Parameters[0]) { @@ -21,6 +22,9 @@ async function run(markdown: string, options?: Parameters[0]) { // The stylesheet the renderer inlines, so the tests read the CSS a reader's browser gets. const styles = (html: string) => /