-
Notifications
You must be signed in to change notification settings - Fork 67
/
jest.config.js
113 lines (105 loc) · 3.3 KB
/
jest.config.js
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
102
103
104
105
106
107
108
109
110
111
112
113
const BASE_CONFIG = {
testPathIgnorePatterns: ['node_modules'],
modulePathIgnorePatterns: ['/build/'],
moduleFileExtensions: [
'js', 'ts', 'tsx', 'json',
],
moduleNameMapper: {
'@epam/uui-test-utils': '<rootDir>/test-utils',
},
transform: {
'^.+\\.(js|ts|tsx)$': ['<rootDir>/node_modules/babel-jest'],
},
};
const JSDOM_ENV_CONFIG = {
...BASE_CONFIG,
testEnvironment: 'jsdom',
setupFiles: ['<rootDir>/node_modules/react-app-polyfill/jsdom'],
setupFilesAfterEnv: ['<rootDir>/uui-build/jest/setupJsDom.js'],
testMatch: ['<rootDir>/**/__tests__/**/*.test.{js,ts,tsx}'],
testURL: 'http://localhost',
transform: {
...BASE_CONFIG.transform,
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/uui-build/jest/fileTransform.js',
'^.+\\.css$': '<rootDir>/uui-build/jest/cssTransform.js',
},
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$', '^.+\\.(sass|scss|less)$'],
moduleNameMapper: {
...BASE_CONFIG.moduleNameMapper,
'^.+\\.(sass|scss|less)$': '<rootDir>/uui-build/jest/cssModuleTransform.js',
'^.+\\.svg$': '<rootDir>/uui-build/jest/svgrMock.js',
},
};
const NODE_ENV_CONFIG = {
...BASE_CONFIG,
testEnvironment: 'node',
testMatch: ['<rootDir>/**/__tests__/**/*.test.{js,ts}'],
};
const JSDOM_TESTS_ROOTS = [
'uui-core',
'uui-components',
'uui',
'epam-promo',
'epam-electric',
'loveship',
'uui-editor',
// TODO: uncomment line(s) below as soon as we have any tests in these modules
// 'extra',
// 'uui-db',
// 'app',
// 'draft-rte',
// 'uui-docs',
// 'uui-timeline',
];
const COLLECT_COVERAGE_FROM_PACKAGES = [
'uui-core',
'uui-components',
'uui',
'epam-promo',
'epam-electric',
'loveship',
];
const NODEJS_TESTS_ROOTS = [
// TODO: uncomment line(s) below as soon as we have any tests in these modules
'uui-build',
'server',
];
const argv = process.argv.slice(2);
const createHtmlReport = argv.indexOf('--collectCoverage') !== -1;
const reporters = createHtmlReport ? [
'default', [
'jest-html-reporter', {
pageTitle: 'UUI Unit Tests Results',
outputPath: '.reports/unit-tests/results.html',
executionTimeWarningThreshold: 3,
dateFormat: 'yyyy-mm-dd HH:MM:ss',
sort: 'status',
includeFailureMsg: true,
includeSuiteFailure: true,
},
],
] : undefined;
/**
* @type {import('@jest/types').Config.GlobalConfig}
*/
module.exports = {
coverageDirectory: '<rootDir>/.reports/unit-tests/coverage',
coverageReporters: ['html-spa'],
collectCoverageFrom: [
...COLLECT_COVERAGE_FROM_PACKAGES.map((dir) => `${dir}/**/*.{js,ts,tsx}`), ...NODEJS_TESTS_ROOTS.map((dir) => `${dir}/**/*.{js,ts}`), '!**/__tests__/**', '!**/node_modules/**', '!**/build/**',
],
reporters,
projects: [
{
displayName: 'jsdom',
roots: [...JSDOM_TESTS_ROOTS],
...JSDOM_ENV_CONFIG,
}, ...(NODEJS_TESTS_ROOTS.length > 0 ? [
{
displayName: 'nodejs',
roots: [...NODEJS_TESTS_ROOTS],
...NODE_ENV_CONFIG,
},
] : []),
],
};