Skip to content

Inline the plugin's own modules so its setup file hooks into the vitest running the tests, fixing "Vitest failed to find the current suite" under pnpm workspaces with two vitest copies - #19

Merged
max-blacksmith merged 1 commit into
mainfrom
devin/1794517412-inline-plugin
Nov 12, 2026

Conversation

@max-blacksmith

@max-blacksmith max-blacksmith commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Bug fix + tests — a project whose vitest differs from the one @useblacksmith/vitest@0.5.0 resolves beside itself in node_modules no longer fails every test file with Vitest failed to find the current suite. Nothing changes for a project where the two resolve to the same copy.

Problem

0.5.0's setup file record-reads.js does import { afterAll } from 'vitest' (#12). Vitest externalizes modules under node_modules, so Node resolves that vitest from the plugin's directory. In a pnpm workspace where two packages depend on the plugin with different peer sets (different @types/node majors was enough), pnpm keeps one @useblacksmith/vitest@0.5.0(vitest@5.1.0) instance whose vitest symlink points at one package's copy. The other package's tests then call a second vitest instance's afterAll, outside any suite, and every test file fails before it runs:

Error: Vitest failed to find the current suite. One of the following is possible:
- "vitest" is imported directly without running "vitest" command
...

0.4.0's setup file imported nothing from vitest, so it was unaffected. --pool=forks does not help; server.deps.inline: [/@useblacksmith\/vitest/] in the consumer's config does.

Fix

The plugin's config() hook adds its own package to test.server.deps.inline, so Vite transforms record-reads.js and resolves its vitest import the same way it does for the test files: to the copy running them.

...(inlineAll ? {} : { server: { deps: { inline: ['@useblacksmith/vitest'] } } }),

inlineAll guards a consumer with inline: true, where merging a list would produce [true, '@useblacksmith/vitest'].

Evidence

New test installed under node_modules copies dist/ and package.json into the fixture's node_modules/@useblacksmith/vitest, places a second copy of vitest under it, and loads the plugin as '@useblacksmith/vitest'. Without the fix it fails with the error above (15 of 16 test files not recorded); with it the full run passes and a changed fixture reruns only its test, so reads are still recorded through the inlined setup file.

Risks

  • Inlining means Vite transforms the plugin's two runtime modules (record-reads.js, its vitest import) once per worker instead of Node loading them natively; they are small and have no other dependencies.
  • A consumer who already lists other packages in server.deps.inline gets ours appended by Vite's config merge; one who sets inline: true is left alone.

Link to Devin session: https://app.devin.ai/sessions/908e16d5e5d54e2c968498f368f535d8
Open in Devin Desktop: https://app.devin.ai/desktop/session/908e16d5e5d54e2c968498f368f535d8?variant=devin
Requested by: @max-blacksmith


View full Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need. (Staging)


View full Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


🟢 Devin Review found nothing to fix · View findings

Devin Review

…with the vitest running the tests, not a second copy resolved from node_modules

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@blacksmith-staging

blacksmith-staging Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Matches Two vitest copies in a pnpm workspace

In a pnpm workspace where the plugin's vitest is the other package's copy, every test file failed with "failed to find the current suite" before; after, all pass and editing one fixture reruns only its test.

Two vitest copies

Merge-base

Every file fails

This PR 31613ce5

Passes, reruns one

Proof on 31613ce5 · Did Proof get it right? Yes · No

View full Proof report · React 👎 or comment @codesmith dismiss this proof to dismiss

@blacksmith-sh

blacksmith-sh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Matches Plugin under a pnpm workspace with two vitest copies

In a real pnpm workspace sharing one plugin copy, the package with the other vitest went from every file failing with "failed to find the current suite" to passing, and --changed then reran only the test whose input changed. The package on the same copy passed on both.

Shared plugin, two vitests

Merge-base

Second vitest package

This PR 31613ce5

Second vitest package

Proof on 31613ce5 · Did Proof get it right? Yes · No

View full Proof report · React 👎 or comment @codesmith dismiss this proof to dismiss

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