-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.config.ts
More file actions
93 lines (78 loc) · 3.03 KB
/
jest.config.ts
File metadata and controls
93 lines (78 loc) · 3.03 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
const esModules = ['normalize-url'].join('|');
const nextJest = require('next/jest');
/** @type {import('jest').Config} */
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
});
const config = {
displayName: {
name: 'Cloud-Console',
color: 'cyan',
},
coverageThreshold: {
global: {
statements: 70, // goal: 75
branches: 70,
functions: 70,
lines: 70, // goal: 75
},
},
collectCoverageFrom: ['**/*.{ts,tsx}'],
coverageReporters: ['json-summary', 'text', 'lcov'],
verbose: true,
moduleNameMapper: {
// Handle CSS imports (with CSS modules)
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
// Handle image imports
'^.+\\.(jpg|jpeg|png|gif|webp|avif)$': '<rootDir>/__mocks__/fileMock.js',
'^.+\\.(svg)$': '<rootDir>/__mocks__/svg.tsx',
// Handle module aliases
'^@pages/(.*)$': '<rootDir>/src/pages/$1',
'^@components/(.*)$': '<rootDir>/src/components/$1',
'^@layout/(.*)$': '<rootDir>/src/components/layout/$1',
'^@services/(.*)$': '<rootDir>/src/services/$1',
'^@hooks/(.*)$': '<rootDir>/src/hooks/$1',
'^@context/(.*)$': '<rootDir>/src/context/$1',
'^@config/(.*)$': '<rootDir>/src/config/$1',
'^@test/(.*)$': '<rootDir>/test/$1',
},
setupFiles: [
// '<rootDir>/jest.setup.mocks.ts'
],
setupFilesAfterEnv: [
'<rootDir>/jest.setup.ts',
// '<rootDir>/__mocks__/jest.next-router-mock.ts',
// '<rootDir>/__mocks__/jest.mock-next-head.ts',
// '<rootDir>/__mocks__/jest.mock-resize-observer.ts',
],
// on node 14.x coverage provider v8 offers good speed and more or less good report
coverageProvider: 'v8',
/**
* @see https://github.com/mswjs/jest-fixed-jsdom/tree/main
*/
testEnvironment: 'jest-fixed-jsdom',
transform: {
// Use babel-jest to transpile tests with the next/babel preset
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
},
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
/*
Sometimes 3rd party modules are published as untranspiled code.
Since all files inside node_modules are not transformed by default,
Jest will not understand the code in these modules, resulting in syntax errors.
To overcome this, you may use transformIgnorePatterns to allow transpiling such modules.
@see: https://jestjs.io/docs/tutorial-react-native#transformignorepatterns-customization
*/
// Jest will ignore all node_modules by default, except for the list "esModules" is assigned.
transformIgnorePatterns: [`node_modules/(?!${esModules})`, '^.+\\.module\\.(css|sass|scss)$'],
testEnvironmentOptions: {
/**
* MSW with JSDOM requires this option setting.
* @see https://mswjs.io/docs/migrations/1.x-to-2.x#cannot-find-module-mswnode-jsdom
*/
customExportConditions: [''],
},
};
module.exports = createJestConfig(config);