-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathjest.config.js
More file actions
55 lines (49 loc) · 2 KB
/
Copy pathjest.config.js
File metadata and controls
55 lines (49 loc) · 2 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
// force timezone to UTC to allow tests to work regardless of local timezone
// generally used by snapshots, but can affect specific tests
process.env.TZ = 'UTC';
const { compilerOptions } = require('./tsconfig');
/** Maps tsconfig `paths` entries to Jest `moduleNameMapper` (replaces ts-jest helper). */
function pathsToModuleNameMapper(paths, { prefix = '' } = {}) {
return Object.entries(paths).reduce((mapper, [from, to]) => {
const [target] = Array.isArray(to) ? to : [to];
const normalizedTarget = target.replace(/^\.\//, '');
const jestPattern = `^${from.replace(/\*/g, '(.*)')}$`;
mapper[jestPattern] = `${prefix}${normalizedTarget.replace(/\*/g, '$1')}`;
return mapper;
}, {});
}
const copyCompilerOptionsPath = {
...compilerOptions.paths,
};
// TODO:
// tsconfig.json points to @types/react
// here jest needs the actual code
copyCompilerOptionsPath['react'] = ['./node_modules/react'];
module.exports = {
// Jest configuration provided by Grafana scaffolding
...require('./.config/jest.config'),
testEnvironment: '<rootDir>/.config/jest/ProfilesDrilldownJsdomEnvironment.js',
testEnvironmentOptions: {
url: 'http://localhost:3000/',
},
modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value
moduleNameMapper: pathsToModuleNameMapper(copyCompilerOptionsPath, { prefix: '<rootDir>/' }),
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest'],
'\\.module\\.(css|scss)$': 'jest-css-modules-transform',
'\\.(css|scss)$': 'jest-css-modules-transform',
},
transformIgnorePatterns: [
// the PprofRequest class uses decorators - FIXME or don't use them (see coveragePathIgnorePatterns below)
'PprofRequest.ts',
],
resetMocks: true,
clearMocks: true,
resetModules: true,
collectCoverageFrom: ['./src/**'],
coveragePathIgnorePatterns: [
// the PprofRequest class uses decorators - FIXME or don't use them (see transformIgnorePatterns above)
'PprofRequest.ts',
],
coverageReporters: ['json-summary', 'text', 'text-summary'],
};