-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathjest.config.mjs
More file actions
101 lines (89 loc) · 2.91 KB
/
jest.config.mjs
File metadata and controls
101 lines (89 loc) · 2.91 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// @ts-check
/* eslint-disable import/no-extraneous-dependencies */
import fse from 'fs-extra';
import path from 'node:path';
import slash from 'slash';
import { createJsWithTsEsmPreset, pathsToModuleNameMapper } from 'ts-jest';
import { resolveInternal } from './tools/resolve-internal.cjs';
const tsconfig = await fse.readJson(path.join(import.meta.dirname, 'tsconfig.test.json'), {
encoding: 'utf8',
});
const IGNORED_PACKAGES = ['@alfalab/core-components-codemod'];
/**
* Список пакетов которые нужно трансформировать, так как react-markdown@7.0.0 ESM-only
* @see https://github.com/remarkjs/react-markdown/blob/main/changelog.md#700---2021-08-13
*/
const REACT_MARKDOWN_IGNORED_MODULES = [
'react-markdown',
'remark-.*',
'unist-util-.*',
'vfile.*',
'unified',
'bail',
'is-plain-obj',
'trough',
'mdast-.*',
'micromark.*',
'decode-named-character-reference',
'trim-lines',
'property-information',
'hast-util-.*',
'.*-separated-tokens',
'devlop',
'estree-util-is-identifier-name',
'html-url-attributes',
];
const IGNORED_MODULES = [
'@alfalab/hooks',
'simplebar',
'uuid',
'swiper',
...REACT_MARKDOWN_IGNORED_MODULES,
];
const tsJestPreset = createJsWithTsEsmPreset({ tsconfig: '<rootDir>/tsconfig.test.json' });
/**
* @type {import('ts-jest').JestConfigWithTsJest['projects']}
*/
const [initialProjectOptions] = [
{
...tsJestPreset,
globalSetup: '<rootDir>/tools/jest/globalSetup.ts',
setupFilesAfterEnv: ['<rootDir>/tools/jest/setupTests.ts'],
modulePathIgnorePatterns: ['/dist/', '/ts-dist/'],
moduleNameMapper: {
...pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: '<rootDir>/' }),
'^.+\\.css$': 'identity-obj-proxy',
},
testPathIgnorePatterns: IGNORED_PACKAGES.map((pkg) => {
const relativeDir = path.relative(import.meta.dirname, resolveInternal(pkg));
return `<rootDir>/${slash(relativeDir)}`;
}),
transformIgnorePatterns: [`/node_modules/(?!(${IGNORED_MODULES.join('|')})/)`],
},
];
/**
* @type {import('ts-jest').JestConfigWithTsJest}
*/
const config = {
projects: [
{
...initialProjectOptions,
displayName: 'jsdom',
testEnvironment: 'jsdom',
testMatch: [
'**/*.{spec,test}.ts?(x)',
'!**/*.{node,screenshots,ssr}.{spec,test}.ts?(x)',
],
coveragePathIgnorePatterns: ['/index.tsx?$'],
},
{
...initialProjectOptions,
displayName: 'node',
testEnvironment: 'node',
testMatch: ['**/*.{node,ssr}.{spec,test}.ts?(x)'],
coveragePathIgnorePatterns: ['/index.tsx?$'],
},
],
coverageReporters: ['lcov', 'text', 'text-summary', 'clover'],
};
export default config;