From 5a715acb852358b0bfdfd814728bf6e03f11510a Mon Sep 17 00:00:00 2001 From: figmar Date: Sun, 11 Oct 2026 20:01:21 +0800 Subject: [PATCH] fix(test): remove jsdom pragma + add window stub DOM surface A/B fix per WorkBuddy review: - browser-globals.ts: add addEventListener/removeEventListener/dispatchEvent to window stub, add compatMode to document stub - Remove // @vitest-environment jsdom from 5 specs that only use renderToString/createElement (SSR, no DOM needed) Test Files 131 passed (131), Tests 1367 passed, EXIT=0 --- tests/apes-tabs.spec.ts | 1 - tests/browser-globals.ts | 6 ++++++ tests/builtins.spec.ts | 1 - tests/markdown-copy-labels.spec.tsx | 1 - tests/markdown-frontmatter.spec.tsx | 1 - tests/sandbox-views.spec.tsx | 1 - 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/apes-tabs.spec.ts b/tests/apes-tabs.spec.ts index e5e7a51..547cc5a 100644 --- a/tests/apes-tabs.spec.ts +++ b/tests/apes-tabs.spec.ts @@ -1,4 +1,3 @@ -// @vitest-environment jsdom /** * apes:* tab registration tests (Phase 1/1b, C6: 3 tabs). The fork registers * its three information-layer tabs (agents / apps / profile) through the same diff --git a/tests/browser-globals.ts b/tests/browser-globals.ts index 8310670..af9bfa6 100644 --- a/tests/browser-globals.ts +++ b/tests/browser-globals.ts @@ -41,6 +41,9 @@ if (g.document === undefined) { querySelector: () => null, querySelectorAll: () => [], styleSheets: [], + // KaTeX probes compatMode at module load; without it it warns + // "doesn't work in quirks mode" and some layout paths no-op. + compatMode: 'CSS1Compat', } } @@ -50,6 +53,9 @@ if (g.navigator === undefined) { if (g.window === undefined) { g.window = { + addEventListener: () => {}, + removeEventListener: () => {}, + dispatchEvent: () => true, clearTimeout: () => {}, setTimeout: (_fn: () => void) => 0, innerWidth: 1024, diff --git a/tests/builtins.spec.ts b/tests/builtins.spec.ts index aeaae2e..1a26e51 100644 --- a/tests/builtins.spec.ts +++ b/tests/builtins.spec.ts @@ -1,4 +1,3 @@ -// @vitest-environment jsdom /** * Built-in registration tests: the plugin registers 7 tabs and 6 file * viewers through the same service external plugins use (dogfooding); diff --git a/tests/markdown-copy-labels.spec.tsx b/tests/markdown-copy-labels.spec.tsx index decb695..fc57ddb 100644 --- a/tests/markdown-copy-labels.spec.tsx +++ b/tests/markdown-copy-labels.spec.tsx @@ -1,4 +1,3 @@ -// @vitest-environment jsdom /** * Markdown preview copy-label spec: the fence copy buttons ("复制" / "Copy") * must follow the DSH locale service through `codeLabels` — the DSH diff --git a/tests/markdown-frontmatter.spec.tsx b/tests/markdown-frontmatter.spec.tsx index 45b8aad..7ac43e2 100644 --- a/tests/markdown-frontmatter.spec.tsx +++ b/tests/markdown-frontmatter.spec.tsx @@ -1,4 +1,3 @@ -// @vitest-environment jsdom /** * Markdown frontmatter preview regression (#251): a leading, closed YAML * metadata block must not reach the shared MarkdownText parser, where its diff --git a/tests/sandbox-views.spec.tsx b/tests/sandbox-views.spec.tsx index 01ce168..ee5ab9a 100644 --- a/tests/sandbox-views.spec.tsx +++ b/tests/sandbox-views.spec.tsx @@ -1,4 +1,3 @@ -// @vitest-environment jsdom /** * Sandbox-contract tests for the two built-in web surfaces (HTML preview * iframe and the browser tab iframe). The iframe sandbox — opaque origin,