Skip to content

Commit

Permalink
next/jest: Allow moduleNameMapper to match before Next.js internal ma…
Browse files Browse the repository at this point in the history
…ppings
  • Loading branch information
timneutkens committed Apr 20, 2022
1 parent 073a05a commit 89d53e6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/next/build/jest/jest.ts
Original file line number Diff line number Diff line change
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

0 comments on commit 89d53e6

Please sign in to comment.