-
Notifications
You must be signed in to change notification settings - Fork 3
/
jest.config.ts
47 lines (39 loc) · 1.68 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
const ROOT = process.cwd();
const ROOT_PROJECT = `${ROOT}`;
const SRC_PATH = `${ROOT_PROJECT}/src`;
const TESTS_PATH = `${ROOT_PROJECT}/__tests__`;
const MODE_MODULES_PATH = `${ROOT_PROJECT}/node_modules`;
const TS_CONFIG_PATH = './tsconfig.paths.json';
const FILE_MOCK = 'jest.config.fileMock.ts';
const extensionsAllowed = {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$/': `${TESTS_PATH}/${FILE_MOCK}`,
'\\.(css|scss)$': `${TESTS_PATH}/${FILE_MOCK}`
};
function makeModuleNameMapper(srcPath: string, tsconfigPath: string) {
const { paths } = require(tsconfigPath).compilerOptions;
const aliases: { [key: string]: string } = {};
Object.keys(paths).forEach((item) => {
const key = item.replace('/*', '/(.*)');
const path = paths[item][0].replace('/*', '/$1');
aliases[key] = `${srcPath}/${path}`;
});
return { ...extensionsAllowed, ...aliases };
}
const config = {
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['@testing-library/jest-dom'],
moduleNameMapper: makeModuleNameMapper(SRC_PATH, TS_CONFIG_PATH),
moduleDirectories: [MODE_MODULES_PATH, SRC_PATH],
roots: [TESTS_PATH],
// We need to include 'd3' or 'internmap' for the @nivo/sankey library
transformIgnorePatterns: [`${MODE_MODULES_PATH}/(?!d3|internmap)`],
transform: {
'^.+\\.(ts|tsx)$': ['ts-jest', { isolatedModules: true }],
'^.+\\.svg$': `${TESTS_PATH}/${FILE_MOCK}`,
'.+\\.(png)$': `${TESTS_PATH}/${FILE_MOCK}`
},
modulePathIgnorePatterns: [`${TESTS_PATH}/${FILE_MOCK}`],
coveragePathIgnorePatterns: ['API', './src/index.tsx', 'routes.tsx', './src/config', 'core/components/SkGraph']
};
export default config;