Unverified Commit e05a95a8 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update moduleNameMapper jest config and remove extra deps (#36787)

* Update moduleNameMapper jest config and remove extra deps

* move svg mock to its own entry for easier overriding

* remove package script
parent fdc071c5
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev",
"lint": "next lint",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
"test": "jest --watch", "test": "jest --watch",
...@@ -18,10 +17,6 @@ ...@@ -18,10 +17,6 @@
"@testing-library/react": "12.1.2", "@testing-library/react": "12.1.2",
"@testing-library/user-event": "13.5.0", "@testing-library/user-event": "13.5.0",
"@types/react": "17.0.38", "@types/react": "17.0.38",
"babel-jest": "27.4.5",
"eslint": "8.5.0",
"eslint-config-next": "latest",
"eslint-plugin-testing-library": "5.0.1",
"jest": "27.4.5", "jest": "27.4.5",
"typescript": "4.5.4" "typescript": "4.5.4"
} }
......
...@@ -76,10 +76,6 @@ export default function nextJest(options: { dir?: string } = {}) { ...@@ -76,10 +76,6 @@ export default function nextJest(options: { dir?: string } = {}) {
...resolvedJestConfig, ...resolvedJestConfig,
moduleNameMapper: { 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) // Handle CSS imports (with CSS modules)
// https://jestjs.io/docs/webpack#mocking-css-modules // https://jestjs.io/docs/webpack#mocking-css-modules
'^.+\\.module\\.(css|sass|scss)$': '^.+\\.module\\.(css|sass|scss)$':
...@@ -89,9 +85,17 @@ export default function nextJest(options: { dir?: string } = {}) { ...@@ -89,9 +85,17 @@ export default function nextJest(options: { dir?: string } = {}) {
'^.+\\.(css|sass|scss)$': require.resolve('./__mocks__/styleMock.js'), '^.+\\.(css|sass|scss)$': require.resolve('./__mocks__/styleMock.js'),
// Handle image imports // Handle image imports
'^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$': require.resolve( '^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp)$': require.resolve(
`./__mocks__/fileMock.js` `./__mocks__/fileMock.js`
), ),
// Keep .svg to it's own rule to make overriding easy
'^.+\\.(svg)$': require.resolve(`./__mocks__/fileMock.js`),
// custom config comes last to ensure the above rules are matched,
// fixes the case where @pages/(.*) -> src/pages/$! doesn't break
// CSS/image mocks
...(resolvedJestConfig.moduleNameMapper || {}),
}, },
testPathIgnorePatterns: [ testPathIgnorePatterns: [
// Don't look for tests in node_modules // Don't look for tests in node_modules
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment