forked from tangly1024/NotionNext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.js
More file actions
122 lines (101 loc) · 2.9 KB
/
jest.config.js
File metadata and controls
122 lines (101 loc) · 2.9 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const nextJest = require('next/jest')
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files
dir: './',
})
// Add any custom config to be passed to Jest
const customJestConfig = {
// Add more setup options before each test is run
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
moduleDirectories: ['node_modules', '<rootDir>/'],
// Module name mapping for path aliases
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
'^@/components/(.*)$': '<rootDir>/components/$1',
'^@/lib/(.*)$': '<rootDir>/lib/$1',
'^@/pages/(.*)$': '<rootDir>/pages/$1',
'^@/styles/(.*)$': '<rootDir>/styles/$1',
'^@/types/(.*)$': '<rootDir>/types/$1',
'^@/conf/(.*)$': '<rootDir>/conf/$1',
'^@/themes/(.*)$': '<rootDir>/themes/$1',
},
// Test environment
testEnvironment: 'jest-environment-jsdom',
// Test file patterns
testMatch: [
'<rootDir>/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/**/*.(test|spec).{js,jsx,ts,tsx}'
],
// Files to ignore
testPathIgnorePatterns: [
'<rootDir>/.next/',
'<rootDir>/node_modules/',
'<rootDir>/out/',
'<rootDir>/.vercel/'
],
// Transform files
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }]
},
// Transform ignore patterns
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
// Module file extensions
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
// Coverage configuration
collectCoverage: false,
collectCoverageFrom: [
'components/**/*.{js,jsx,ts,tsx}',
'lib/**/*.{js,jsx,ts,tsx}',
'pages/**/*.{js,jsx,ts,tsx}',
'!pages/_app.js',
'!pages/_document.js',
'!pages/api/**',
'!**/*.d.ts',
'!**/node_modules/**',
'!**/.next/**',
'!**/out/**',
'!**/coverage/**'
],
coverageReporters: ['text', 'lcov', 'html'],
coverageDirectory: 'coverage',
coverageThreshold: {
global: {
branches: 70,
functions: 70,
lines: 70,
statements: 70
}
},
// Setup files
setupFiles: ['<rootDir>/jest.env.js'],
// Global variables
globals: {
'ts-jest': {
tsconfig: 'tsconfig.json'
}
},
// Verbose output
verbose: true,
// Clear mocks between tests
clearMocks: true,
// Restore mocks after each test
restoreMocks: true,
// Error on deprecated features
errorOnDeprecated: true,
// Timeout for tests
testTimeout: 10000,
// Reporters
reporters: [
'default',
['jest-junit', {
outputDirectory: 'test-results',
outputName: 'junit.xml'
}]
]
}
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)