Skip to content

test: split vitest into projects, switch DOM tests to happy-dom, drop unnecessary tests - #871

Merged
aXenDeveloper merged 5 commits into
canaryfrom
claude/optimize-unit-tests
Oct 11, 2026
Merged

aXenDeveloper merged 5 commits into
canaryfrom
claude/optimize-unit-tests

Conversation

@aXenDeveloper

Copy link
Copy Markdown
Owner
  • Core vitest config now has unit (node, isolate: false), isolated, dom
    (happy-dom), integration and types projects. Node tests share one module
    graph per worker instead of re-importing the server graph for every file.
  • The file extension picks the environment: DOM tests are *.test.tsx. The
    // @vitest-environment pragmas are gone.
  • upload.ts no longer imports the whole date-fns barrel.
  • Real 2s reconnect waits use fake timers; the package build test builds once
    for its read-only assertions.
  • Delete tests that grep source text, test AutoForm/form-field UI, Base UI
    wrappers, constants or wiring of features already covered elsewhere.
  • The blog plugin defaults to node; only its DOM test opts into jsdom.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_015x559AHZ5rNsyvKusi5pVk

… unnecessary tests

- Core vitest config now has unit (node, isolate: false), isolated, dom
  (happy-dom), integration and types projects. Node tests share one module
  graph per worker instead of re-importing the server graph for every file.
- The file extension picks the environment: DOM tests are *.test.tsx. The
  `// @vitest-environment` pragmas are gone.
- upload.ts no longer imports the whole date-fns barrel.
- Real 2s reconnect waits use fake timers; the package build test builds once
  for its read-only assertions.
- Delete tests that grep source text, test AutoForm/form-field UI, Base UI
  wrappers, constants or wiring of features already covered elsewhere.
- The blog plugin defaults to node; only its DOM test opts into jsdom.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015x559AHZ5rNsyvKusi5pVk
Remove tests that repeat coverage from a canonical file, assert Drizzle
schema details, constants, option literals or CSS classes, or grep source
text. Import-graph boundary checks, security checks (cookie scoping, passkey
ceremonies, password timing) and per-route permission coverage stay.

- Merge http-errors into error-contracts, i18n-check into the i18n command
  test and save-remount into the reducer test.
- Drop feed-boundaries and create-start, whose cases are covered elsewhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015x559AHZ5rNsyvKusi5pVk
@github-actions github-actions Bot added the 🧪 Test Adding missing tests or correcting existing tests label Oct 11, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T08:36:15.599050Z a80556a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

React Doctor found 7 issues in 6 files · 7 warnings · score 100 / 100 (Great) · vs canary

7 warnings

src/api/lib/ai/registry.test.ts

  • ⚠️ L178 JSON parse/stringify deep clone no-json-parse-stringify-clone

src/api/models/session-admin.test.ts

  • ⚠️ L116 JSON parse/stringify deep clone no-json-parse-stringify-clone

src/api/models/session-cache.test.ts

  • ⚠️ L123 JSON parse/stringify deep clone no-json-parse-stringify-clone

src/content/admin/spec.test.ts

  • ⚠️ L74 JSON parse/stringify deep clone no-json-parse-stringify-clone
  • ⚠️ L184 JSON parse/stringify deep clone no-json-parse-stringify-clone

src/content/server/live/presence.test.ts

  • ⚠️ L385 JSON parse/stringify deep clone no-json-parse-stringify-clone

src/content/server/revision-snapshot.test.ts

  • ⚠️ L79 JSON parse/stringify deep clone no-json-parse-stringify-clone
⚠️ Warning: .github/workflows/react-doctor.yml is configured incorrectly. See below to fix.

React Doctor compares against canary to report only the issues this pull request introduces. This run couldn't complete that comparison (usually a shallow CI checkout with no merge base), so it listed every issue in the changed files, including ones that already existed on canary.

Add fetch-depth: 0 to the actions/checkout step in .github/workflows/react-doctor.yml so the checkout includes the history React Doctor needs:

 jobs:
   react-doctor:
     steps:
       - uses: actions/checkout@v5
+        with:
+          fetch-depth: 0

       - uses: millionco/react-doctor@v2

To silence this warning, set silence-missing-baseline-warning: true on the React Doctor action.

Reviewed by React Doctor for commit a80556a. See inline comments for fixes.

Lists the kinds of tests removed in this branch (wiring, schema and SQL
text, config and option literals, Base UI behaviour, source greps, locale
copy, fixture checks) and adds "one behaviour, one test" rules so the same
rule is asserted once, in the layer that owns it. Security checks stay
even when they look redundant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015x559AHZ5rNsyvKusi5pVk

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb4e3c14af

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

test: {
name: "unit",
environment: "node",
isolate: false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore leaked globals before sharing test workers

With isolate: false, test files assigned to the same worker reuse its global state, but several included unit tests do not clean up their mutations. For example, src/api/lib/file-download.test.ts:38-43 replaces global fetch in every test without calling vi.unstubAllGlobals(), so whichever file follows it inherits upstreamFetch and becomes order-dependent. Keep isolation enabled, add reliable per-file cleanup, or move every such test into ISOLATED.

AGENTS.md reference: AGENTS.md:L120-L121

Useful? React with 👍 / 👎.

acquireContentFieldLock moved from the deprecated `where` to `setWhere`,
which Drizzle renders the same way. The in-memory database only read
`where`, so a held lock was overwritten and the 409 test got a 200.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015x559AHZ5rNsyvKusi5pVk

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 437ce8990d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +186 to +189
beforeAll(async () => {
createPackage();
result = await build();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the build's 60-second timeout

On slower CI runners where the tsdown/typecheck build takes more than 10 seconds, this setup now fails before any assertions run: the former build tests explicitly allowed 60 seconds, but moving the build into beforeAll drops that allowance, and Vitest documents a 10-second default hook timeout. Pass the previous timeout as the hook's second argument or configure an equivalent hookTimeout for the integration project.

Useful? React with 👍 / 👎.

- Wrap router navigations and timer-driven updates in act, use Testing
  Library's waitFor, and let the live session's HTTP reads land inside act.
- Give fakes what the code under test calls (a draft delete, a logger) and
  capture output a test deliberately triggers instead of printing it.
- permission-matrix answers a handler failure past the permission check
  with a quiet 500.
- ProcessGroup honours `capture`, so the package watch test keeps tsdown
  and tsc off the terminal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015x559AHZ5rNsyvKusi5pVk

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a80556a7a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -1,3 +1,4 @@
// @vitest-environment jsdom

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Route .test.tsx files through a DOM project

Changing the plugin's default environment to Node and restoring this test with a per-file pragma bypasses the repository's filename-based environment convention. Future .test.tsx files will silently run under Node unless every author remembers the same exception; configure a DOM project for the suffix and remove this pragma instead.

AGENTS.md reference: AGENTS.md:L132-L135

Useful? React with 👍 / 👎.

Comment on lines +128 to +130
await new Promise(resolve => {
setTimeout(resolve, 0);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Replace the real timer with deterministic settling

Every mount() now depends on a real setTimeout, making these tests sensitive to event-loop timing; it can also hang subsequent cases if a prior fake-timer test fails before restoring real timers. Wait for an observable condition or explicitly advance fake timers rather than sleeping for a turn.

AGENTS.md reference: AGENTS.md:L132-L137

Useful? React with 👍 / 👎.

@aXenDeveloper
aXenDeveloper merged commit fd2275e into canary Oct 11, 2026
7 checks passed
@aXenDeveloper
aXenDeveloper deleted the claude/optimize-unit-tests branch October 11, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🧪 Test Adding missing tests or correcting existing tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants