fix: vitest compatibility — ESM entrypoint and framework-agnostic matcher#460
Merged
Conversation
🦋 Changeset detectedLatest commit: 92a015e The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
1d9f0fd to
e90e50e
Compare
This was referenced Mar 23, 2026
vitest entrypoint fails: jest-styled-components/vitest uses require('vitest') which is ESM-only
#458
Closed
Add pnpm workspace at test/vitest with Vitest 4 running globals:false to verify the /vitest entrypoint works end-to-end. Covers matcher (basic, regex, asymmetric matchers, negation, media, modifiers, theming) and snapshot serializer. Suppress expected React dev warnings and jsdom CSS parse noise in test setup.
- Update .nvmrc from v20 to v24 (current LTS) - Add jest-environment-jsdom@27 for explicit jsdom version control - Pin http-proxy-agent override to ^7.0.0 (v8 is ESM-only, breaks CJS) - Add test:vitest script and exclude vitest tests from Jest config - Add vitest workspace to pnpm lockfile
e90e50e to
f5753b9
Compare
pull_request_target checks out the base branch by default, so CI was never actually testing PR changes.
Contributor
Author
|
Testable via |
There was a problem hiding this comment.
Pull request overview
Fixes Vitest v4 integration by making the /vitest entrypoint ESM-compatible and removing hard dependency on a global expect inside matcher logic, plus adds a pnpm workspace-based Vitest test suite to validate behavior with globals: false.
Changes:
- Convert
vitest/index.jsto ESM (scoped"type": "module") while bridging to existing CJS source viacreateRequire. - Refactor
matcherTestto use framework-agnostic matching (RegExp/asymmetricMatch/strict equality) instead ofexpect.*. - Add a pnpm workspace + Vitest tests (and snapshots) to exercise matcher/serializer under Vitest without globals; adjust tooling deps/overrides for Node 24 + Jest 27.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
vitest/package.json |
Marks the /vitest entrypoint directory as ESM via "type": "module". |
vitest/index.js |
Switches Vitest entrypoint to ESM imports and re-exports utilities for Vitest setup. |
src/utils.js |
Makes matcherTest independent of framework expect, enabling Vitest without globals. |
test/vitest/vitest.config.js |
Adds Vitest config (jsdom, globals: false) for the new test workspace. |
test/vitest/toHaveStyleRule.test.jsx |
Adds Vitest coverage for toHaveStyleRule across common cases (regex/asymmetric/etc.). |
test/vitest/styleSheetSerializer.test.jsx |
Adds Vitest coverage for serializer snapshot output. |
test/vitest/__snapshots__/styleSheetSerializer.test.jsx.snap |
Commits Vitest snapshot outputs for serializer tests. |
test/vitest/package.json |
Defines a workspace package to run Vitest tests against the local workspace build. |
pnpm-workspace.yaml |
Declares the test/vitest workspace package for pnpm. |
package.json |
Adds test:vitest, ignores Vitest tests in Jest, adds jest-environment-jsdom, updates override, bumps version. |
pnpm-lock.yaml |
Locks new workspace deps and adjusts http-proxy-agent override + jest-environment-jsdom. |
test/setup.js |
Suppresses some console.error noise during Jest tests. |
.nvmrc |
Bumps CI/local Node version target to v24. |
.changeset/vitest-compat.md |
Adds changeset describing Vitest compatibility fix. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Clone RegExp in matcherTest to prevent lastIndex mutation with g/y flags - Add missing enableCSSCache/disableCSSCache types to vitest/index.d.ts - Revert prerelease version bump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vitest/index.jsto ESM via scopedvitest/package.jsonwith"type": "module", usingcreateRequireto bridge to CJS source modules. The previous CJSrequire('vitest')threw because Vitest v4 is ESM-only.expectinmatcherTestbreaks under Vitest without injected globals #459: Replaceexpect.stringMatching()/expect().toEqual()inmatcherTestwith plain JS —RegExp.test(),asymmetricMatch()protocol, and strict equality. This removes the dependency on any test framework's globalexpect, sotoHaveStyleRuleworks in Vitest withoutglobals: true.jest-environment-jsdom@27as explicit dev dep for Node 24 compatibilityhttp-proxy-agentoverride to^7.0.0(v8 is ESM-only, breaks Jest 27's CJS require)globals: false) covering matcher and serializer