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 (#36312)

Fixes #35634

This change doesn't require tests as importing svgs is not a supported feature, this just makes it slightly more ergonomic to override the matchers. 



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
  • Loading branch information
timneutkens committed Apr 20, 2022
1 parent 073a05a commit 23c82e4
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit 23c82e4

Please sign in to comment.