-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest.config.ts
70 lines (66 loc) · 1.98 KB
/
jest.config.ts
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
import type { Config } from 'jest';
import nextJest from '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 config: Config = {
fakeTimers: {
enableGlobally: true,
},
preset: 'ts-jest',
coverageProvider: 'v8',
testEnvironment: 'jest-environment-jsdom',
testMatch: ['**/__tests__/**/*.test.ts?(x)'],
transform: {
'^.+\\.(tsx|jsx|ts|js|mjs)?$': [
'@swc/jest',
{
jsc: {
parser: {
syntax: 'typescript',
dynamicImport: true,
decorators: true,
},
transform: {
legacyDecorator: true,
decoratorMetadata: true,
react: {
runtime: 'automatic',
},
},
},
},
],
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
// mocks for mdx-js
'estree-walker': '<rootDir>/__tests__/mocks/estree-walker.ts',
'periscopic': '<rootDir>/__tests__/mocks/periscopic.ts',
// mocks for next-auth
'@/utils/auth': '<rootDir>/__tests__/mocks/auth.ts',
'next-auth/providers/credentials':
'<rootDir>/__tests__/mocks/next-auth-providers-credentials.ts',
'next-auth': '<rootDir>/__tests__/mocks/next-auth.ts',
},
testPathIgnorePatterns: [
'^.+\\.*.css$',
'<rootDir>/app/',
"<rootDir>/packages/",
'<rootDir>/dist',
'<rootDir>/.tsbuild',
],
};
// createJestConfig is exported in this way to ensure that next/jest can load the Next.js configuration, which is async
const jestConfig = async () => {
const nextJestConfig: any = await createJestConfig(config)();
// /node_modules/ is the first pattern
nextJestConfig.transformIgnorePatterns[0] = '/node_modules/(?!(nanoid||nanoevents))/';
nextJestConfig.transformIgnorePatterns[0] = '/node_modules/(?!(yjs))/';
return nextJestConfig;
}
export default jestConfig;