-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest.config.ts
54 lines (44 loc) · 1.89 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
import dotenv from 'dotenv';
import { getTsconfig } from 'get-tsconfig';
import nextJest from 'next/jest';
import path from 'path';
import { pathsToModuleNameMapper } from 'ts-jest';
import { additionalJestPackages, commonPackages, formatTransformIgnorePatterns } from './transpilePackages';
const createJestConfig = nextJest({
dir: './',
});
const fullTsconfig = getTsconfig();
if (!fullTsconfig) {
throw new Error(`a "tsconfig.json" must be provided`);
}
// Load test variables if any
dotenv.config({ path: path.resolve(__dirname, './.env.jest') });
dotenv.config({ path: path.resolve(__dirname, './.env.jest.local') });
// Add any custom config to be passed to Jest
const customJestConfig: Parameters<typeof createJestConfig>[0] = {
preset: 'ts-jest',
setupFilesAfterEnv: [],
moduleDirectories: ['node_modules', '<rootDir>/'],
moduleNameMapper: {
...(fullTsconfig.config.compilerOptions && fullTsconfig.config.compilerOptions.paths
? pathsToModuleNameMapper(fullTsconfig.config.compilerOptions.paths, { prefix: '<rootDir>/' })
: {}),
},
testEnvironment: 'jest-environment-jsdom',
modulePathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/data/'],
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/data/', '<rootDir>/node_modules/'],
transformIgnorePatterns: [],
extensionsToTreatAsEsm: ['.ts', '.tsx'],
};
// [WORKAROUND] To transpile additional dependencies we hack a bit as specified into https://github.com/vercel/next.js/discussions/31152#discussioncomment-1697047
// (and we add our own logic to avoid hardcoding values)
const asyncConfig = createJestConfig(customJestConfig);
const defaultExport = async () => {
const config = await asyncConfig();
config.transformIgnorePatterns = formatTransformIgnorePatterns(
[...commonPackages, ...additionalJestPackages],
customJestConfig.transformIgnorePatterns ?? []
);
return config;
};
export default defaultExport;