-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.config.js
59 lines (54 loc) · 2.06 KB
/
jest.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const nextJest = require('next/jest')
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})
// Add any custom config to be passed to Jest
const customJestConfig = {
collectCoverageFrom: [
'components/**/*.{js,jsx,ts,tsx}',
'context/**/*.{js,jsx,ts,tsx}',
'lib/helpers/**/*.{js,jsx,ts,tsx}',
'lib/getters/**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
'hooks/**/*.{js,jsx,ts,tsx}',
'src/pages/**/*.{js,jsx,ts,tsx}',
'!middleware.ts',
],
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
// Handle CSS imports (without CSS modules)
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',
// Handle image imports
// https://jestjs.io/docs/webpack#handling-static-assets
'^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$': `<rootDir>/__mocks__/fileMock.js`,
// Handle module aliases
'^@/components/(.*)$': '<rootDir>/components/$1',
// Handle Lib aliases
'^@/lib/(.*)$': '<rootDir>/lib/$1',
// Handle context aliases
'^@/context(.*)$': '<rootDir>/context/$1',
// Handle mock aliases
'^@/__mocks__/(.*)$': '<rootDir>/__mocks__/$1',
// Handle test aliases
'^@/__test__/(.*)$': '<rootDir>/__test__/$1',
// Handle hooks aliases
'^@/hooks(.*)$': '<rootDir>/hooks/$1',
// Handle pages aliases
'^@/pages/(.*)$': '<rootDir>src/pages/$1',
'^@/(.*)$': '<rootDir>/$1',
},
testEnvironment: 'jest-environment-jsdom',
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['@swc/jest'],
},
transformIgnorePatterns: ['/node_modules/', '^.+\\.module\\.(css|sass|scss)$'],
testPathIgnorePatterns: [
'/__test__/e2e/integration/', // Ignore the integration folder
],
setupFilesAfterEnv: ['./jestSetup.js'],
}
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)