Skip to content

Run unit and component tests as Vitest projects in one config - #23

Open
stevez wants to merge 1 commit into
mainfrom
verify/vitest-projects-merge
Open

stevez wants to merge 1 commit into
mainfrom
verify/vitest-projects-merge

Conversation

@stevez

@stevez stevez commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Summary

Vitest 5.1.1 installs @vitest/istanbul-lib-coverage@2.1.1, which fixes statements being counted twice when jsdom and browser coverage are merged (vitest-dev/vitest#12040, vitest-dev/istanbuljs#25). That lets us drop the two-config workaround:

  • vitest.config.ts now defines two projects: unit (jsdom) and component (Playwright browser). One vitest run produces the combined report in coverage/vitest.
  • vitest.component.config.ts is removed.
  • test:unit / test:component select a project with --project; lcov:unit / lcov:component are replaced by lcov:vitest.
  • coverage:merge is now nextcov merge coverage/vitest coverage/integration -o coverage/merged.
  • vitest and @vitest/* upgraded to 5.1.1. @types/node bumped to ^22 to satisfy vitest 5.1.1's peer range, so npm ci works without --legacy-peer-deps.
  • README updated.

Verification

Run locally on Windows:

Flow Statements Branches Functions
Old: separate unit + component runs, merged by nextcov 64/81 13/14 17/27
New: one vitest run with both projects 64/81 13/14 17/27
Old + integration → nextcov merge 77/81 14/14 25/27
New + integration → nextcov merge 77/81 14/14 25/27

A per-file diff of the two final merged reports shows no differences. npm ci, npm test (13 tests), npm run build:local and npm run integration-test (4 tests) all pass.

Notes

  • In this example, Vitest's own projects merge also gave correct totals with the old 2.1.0. The library bug shows up when merging the separately produced JSON reports with istanbul: 92 statements with 2.1.0, 87 with 2.1.1, versus the correct 81. The remaining duplicate is Icons.tsx, where the browser transform adds a 'use client' statement and ends ranges on different lines; the 2.1.1 fix doesn't cover that. nextcov's own merge gives 81 either way.
  • tsc --noEmit reports 3 existing type errors in src/api/__tests__/api.test.ts (HeadersInit.get). They appear with @types/node 20 as well, so this PR doesn't cause them.
  • Running test:unit or test:component alone writes only that project's coverage; use npm test for the combined report.

🤖 Generated with Claude Code

Vitest 5.1.1 installs @vitest/istanbul-lib-coverage 2.1.1, which fixes
duplicated statements when merging jsdom and browser coverage. Unit and
component tests now run as two projects in vitest.config.ts, so one
`vitest run` produces the combined report in coverage/vitest and
vitest.component.config.ts is no longer needed.

- Upgrade vitest and @vitest/* to 5.1.1
- Bump @types/node to ^22 to satisfy vitest's peer range (npm ci)
- test:unit / test:component select a project with --project
- coverage:merge now merges coverage/vitest + coverage/integration
- Update README

Final merged coverage is identical to the previous two-config flow
(77/81 statements, 14/14 branches, 25/27 functions).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant