|
1 | | -// jest.config.js |
2 | | -module.exports = { |
3 | | - collectCoverage: true, |
4 | | - // on node 14.x coverage provider v8 offers good speed and more or less good report |
5 | | - coverageProvider: "v8", |
6 | | - collectCoverageFrom: [ |
7 | | - "**/*.{js,jsx,ts,tsx}", |
8 | | - "!**/e2e/**", |
9 | | - "!**/*.d.ts", |
10 | | - "!**/node_modules/**", |
11 | | - "!<rootDir>/out/**", |
12 | | - "!<rootDir>/.next/**", |
13 | | - "!<rootDir>/*.config.js", |
14 | | - "!<rootDir>/*.config.ts", |
15 | | - "!<rootDir>/*rc.js", |
16 | | - "!<rootDir>/coverage/**", |
17 | | - ], |
18 | | - moduleNameMapper: { |
19 | | - // Handle CSS imports (with CSS modules) |
20 | | - // https://jestjs.io/docs/webpack#mocking-css-modules |
21 | | - "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy", |
22 | | - |
23 | | - // Handle CSS imports (without CSS modules) |
24 | | - "^.+\\.(css|sass|scss)$": "<rootDir>/__mocks__/styleMock.js", |
25 | | - |
26 | | - // Handle image imports |
27 | | - // https://jestjs.io/docs/webpack#handling-static-assets |
28 | | - "^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i": `<rootDir>/__mocks__/fileMock.js`, |
29 | | - |
30 | | - // Handle module aliases |
31 | | - "^@/components/(.*)$": "<rootDir>/components/$1", |
32 | | - }, |
33 | | - // Add more setup options before each test is run |
34 | | - // setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], |
35 | | - testPathIgnorePatterns: [ |
36 | | - "<rootDir>/node_modules/", |
37 | | - "<rootDir>/.next/", |
38 | | - "<rootDir>/e2e/", |
39 | | - ], |
40 | | - transform: { |
41 | | - // Use babel-jest to transpile tests with the next/babel preset |
42 | | - // https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object |
43 | | - "^.+\\.(js|jsx|ts|tsx)$": ["babel-jest", { presets: ["next/babel"] }], |
44 | | - }, |
45 | | - transformIgnorePatterns: [ |
46 | | - "/node_modules/", |
47 | | - "^.+\\.module\\.(css|sass|scss)$", |
48 | | - ], |
| 1 | +const nextJest = require("next/jest"); |
| 2 | +const createJestConfig = nextJest({ |
| 3 | + dir: "./", |
| 4 | +}); |
| 5 | +const customJestConfig = { |
| 6 | + setupFilesAfterEnv: ["<rootDir>/setupTests.ts"], |
| 7 | + moduleDirectories: ["node_modules", "<rootDir>/"], |
| 8 | + testEnvironment: "jest-environment-jsdom", |
49 | 9 | }; |
| 10 | +module.exports = createJestConfig(customJestConfig); |
0 commit comments