-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjest.frontend.config.ts
47 lines (41 loc) · 1.44 KB
/
jest.frontend.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
import nextJest from 'next/jest';
import { Config } from 'jest';
import { TextDecoder, TextEncoder } from 'util';
export {};
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: Config = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testEnvironment: 'jsdom',
modulePathIgnorePatterns: ['cypress'],
globals: {
'ts-jest': {
tsConfigFile: 'tsconfig.json',
},
TextEncoder: TextEncoder,
TextDecoder: TextDecoder,
},
// mock all svg files
moduleNameMapper: {
'^.+\\.(svg)$': '<rootDir>/__mocks__/svg.tsx',
},
testMatch: ['**/__tests__/**/*.tsx', '**/?(*.)+(spec|test).tsx'],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
};
// @ts-expect-error We don't know the type
const jestConfigWithOverrides = async (...args) => {
const fn = createJestConfig(config);
// @ts-expect-error We don't know the type
const res = await fn(...args);
// Don't ignore specific node_modules during transformation. This is needed if a node_module doesn't return valid JavaScript files.
res.transformIgnorePatterns = res.transformIgnorePatterns!.map((pattern) => {
if (pattern === '/node_modules/') {
return '/node_modules/(?!.+)';
}
return pattern;
});
return res;
};
module.exports = jestConfigWithOverrides;