-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjest.config.ts
32 lines (29 loc) · 1001 Bytes
/
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
import configFromPreset from 'jest-presets/jest/node/jest-preset';
import nextJest from 'next/jest';
import { pathsToModuleNameMapper } from 'ts-jest';
import tsconfig from './tsconfig.json';
/* Creating a jest configuration for nextjs. */
const createJestConfig = nextJest({
dir: './',
})(configFromPreset);
const exportFunc = async () => {
// Create Next.js jest configuration
const configFromNext = await createJestConfig();
Object.keys(configFromNext.moduleNameMapper).forEach((regExp) => {
if (new RegExp(regExp).test('_.svg')) {
configFromNext.moduleNameMapper[regExp] = 'shared-utils/__mocks__/svg.js';
}
});
// moduleNameMapper overrided by nextjs, so we need to add it here.
const finalConfig = {
...configFromNext,
moduleNameMapper: {
...configFromNext.moduleNameMapper,
...pathsToModuleNameMapper(tsconfig.compilerOptions.paths, {
prefix: '<rootDir>/src/',
}),
},
};
return finalConfig;
};
export default exportFunc;