Skip to content

fix: 💚 Fix build#513

Merged
adrien-may merged 1 commit intodevelopfrom
chg/mockPrettierAndFlagForPayload
Feb 17, 2026
Merged

fix: 💚 Fix build#513
adrien-may merged 1 commit intodevelopfrom
chg/mockPrettierAndFlagForPayload

Conversation

@adrien-may
Copy link
Contributor

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:

  1. @next/env mock (tests/mocks/next-env.ts)

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.

  1. prettier mock (tests/mocks/prettier.js)

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.

Copilot AI review requested due to automatic review settings February 13, 2026 15:38
@adrien-may adrien-may added the bug Something isn't working label Feb 13, 2026
@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 moduleNameMapper configuration to jest.config.ts to route @next/env and prettier imports to test mocks
  • Created __tests__/mocks/next-env.ts to provide a working default export for the @next/env package which has CJS/__esModule interop issues with SWC
  • Created __tests__/mocks/prettier.js to 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.

@adrien-may adrien-may force-pushed the chg/mockPrettierAndFlagForPayload branch from 3c2aaad to 128472d Compare February 17, 2026 13:14
@adrien-may adrien-may force-pushed the chg/mockPrettierAndFlagForPayload branch from 128472d to 1805df2 Compare February 17, 2026 13:14
@adrien-may adrien-may merged commit fb80245 into develop Feb 17, 2026
5 checks passed
@adrien-may adrien-may deleted the chg/mockPrettierAndFlagForPayload branch February 17, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants