Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR fixes Jest build compatibility issues when using Payload CMS 3.76.1 with SWC transformation. The fix addresses module interop problems where certain CommonJS packages with non-standard ESM compatibility markers fail to load in Jest's testing environment.
Changes:
- Added
moduleNameMapperconfiguration tojest.config.tsto route@next/envandprettierimports to test mocks - Created
__tests__/mocks/next-env.tsto provide a working default export for the @next/env package which has CJS/__esModule interop issues with SWC - Created
__tests__/mocks/prettier.jsto stub prettier functionality that fails due to dynamic ESM imports in Jest's VM context
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| jest.config.ts | Added moduleNameMapper to redirect problematic dependencies to test mocks |
| tests/mocks/prettier.js | No-op stub for prettier to avoid dynamic import failures in Jest VM context |
| tests/mocks/next-env.ts | Mock implementation providing expected default export shape for @next/env |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3c2aaad to
128472d
Compare
128472d to
1805df2
Compare
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.
Voilà le bilan de mon agent mais je suis ni convaincu ni heureux. Mais les tests passent
Two mocks were added to jest.config.ts via moduleNameMapper to fix payload 3.76.1 compatibility with Jest + SWC:
Payload's loadEnv.js does import nextEnvImport from '@next/env'; const { loadEnvConfig } = nextEnvImport;. The @next/env package is CJS but sets __esModule: true without a proper default export. When SWC transforms this to CJS interop, nextEnvImport resolves to undefined, causing the Cannot destructure property 'loadEnvConfig' error. The mock provides the expected default export shape.
The import chain @payloadcms/db-sqlite → @payloadcms/drizzle → payload/node → generateTypes → json-schema-to-typescript → prettier causes prettier/index.cjs to execute import("./index.mjs") at module load time. This dynamic import fails in Jest's VM context with A dynamic import callback was invoked without --experimental-vm-modules. Since prettier is only used for code formatting in generateTypes (not exercised in tests), a no-op stub is safe.