Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next/jest: Allow moduleNameMapper to match before Next.js internal mappings #36312

Merged
merged 1 commit into from Apr 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/next/build/jest/jest.ts
Expand Up @@ -72,6 +72,10 @@ export default function nextJest(options: { dir?: string } = {}) {
...resolvedJestConfig,

moduleNameMapper: {
// Custom config will be able to override the default mappings
// moduleNameMapper is matched top to bottom hence why this has to be before Next.js internal rules
...(resolvedJestConfig.moduleNameMapper || {}),

// Handle CSS imports (with CSS modules)
// https://jestjs.io/docs/webpack#mocking-css-modules
'^.+\\.module\\.(css|sass|scss)$':
Expand All @@ -84,9 +88,6 @@ export default function nextJest(options: { dir?: string } = {}) {
'^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$': require.resolve(
`./__mocks__/fileMock.js`
),

// Custom config will be able to override the default mappings
...(resolvedJestConfig.moduleNameMapper || {}),
},
testPathIgnorePatterns: [
// Don't look for tests in node_modules
Expand Down