forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.js
More file actions
34 lines (31 loc) · 1.05 KB
/
Copy pathjest.config.js
File metadata and controls
34 lines (31 loc) · 1.05 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
const fs = require('fs');
// The tsconfig.aliases.json uses JSONC (JSON with comments) — strip line comments before parsing.
const aliasesRaw = fs.readFileSync('./tsconfig.aliases.json', 'utf-8').replace(/\/\/[^\n]*/g, '');
const {compilerOptions} = JSON.parse(aliasesRaw);
// Convert TypeScript path aliases to Jest moduleNameMapper format.
const moduleNameMapper = Object.fromEntries(
Object.entries(compilerOptions.paths).map(([key, [value]]) => [
`^${key.replace('/*', '/(.*)$')}`,
`<rootDir>/${value.replace('/*', '/$1')}`,
]),
);
/** @type {import('jest').Config} */
module.exports = {
testEnvironment: 'jsdom',
clearMocks: true,
testMatch: ['**/esm/tests/**/*.test.{ts,tsx}'],
moduleNameMapper,
transform: {
'^.+\\.(ts|tsx)$': ['ts-jest', {
tsconfig: './tsconfig.jest.json',
}],
},
setupFilesAfterEnv: [
'@testing-library/jest-dom',
'<rootDir>/.jest/globalSetup.ts',
],
collectCoverageFrom: [
'**/esm/src/**/*.{ts,tsx}',
'!**/*.d.ts',
],
};