-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathjest.config.mjs
More file actions
60 lines (53 loc) · 1.47 KB
/
jest.config.mjs
File metadata and controls
60 lines (53 loc) · 1.47 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
import { createRequire } from 'module';
import { pathsToModuleNameMapper } from 'ts-jest';
const require = createRequire(import.meta.url);
const { compilerOptions } = require('./tsconfig.json');
/**
* Enhance the Jest path mappings map returned from `pathsModuleNameMapper`
* to support ES modules import syntax in TypeScript.
*
* @returns Jest path mappings map.
*/
function pathsToESModuleNameMapper() {
const map = pathsToModuleNameMapper(
compilerOptions.paths,
{ prefix: '<rootDir>' },
);
const esmMap = {};
Object.entries(map).forEach((entry) => {
const [key, val] = entry;
if (/.*\(\.\*\)\$$/.test(key)) {
// eslint-disable-next-line prefer-template
const convertedKey = key.substring(0, key.length - 2)
+ '[^\\.js])(\\.js)?$';
esmMap[convertedKey] = val;
}
});
// Append the mapping for relative paths without path alias.
esmMap['^(\\.{1,2}/.*)\\.js$'] = '$1';
return esmMap;
}
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
moduleNameMapper: pathsToESModuleNameMapper(),
modulePathIgnorePatterns: [
'<rootDir>/dist',
'<rootDir>/node_modules',
'<rootDir>/out',
],
transform: {
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
},
],
},
testMatch: [
'**/tests/**/*.(spec|test).([jt]s?(x))',
],
collectCoverage: true,
verbose: true,
};