-
Notifications
You must be signed in to change notification settings - Fork 4
/
jest.config.base.mjs
63 lines (60 loc) · 1.85 KB
/
jest.config.base.mjs
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
import { relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { resolveRoot } from './tools/utils.mjs';
const dirname = fileURLToPath( new URL( '.', import.meta.url ) );
/**
* @param pkg - Package name
* @returns {import('ts-jest/dist/types').InitialOptionsTsJest} - Opts.
*/
const baseConfig = pkg => ( {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'.*\\.tsx?': [ 'ts-jest', {
tsconfig: resolveRoot( 'packages', pkg, 'tsconfig.spec.json' ),
diagnostics: {
pathRegex: new RegExp( `^${dirname.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' )}/packages/${pkg}/.*` ),
},
} ],
},
moduleNameMapper: {
'^@knodes/typedoc-pluginutils/(.*)$': resolveRoot( dirname, './packages/pluginutils/src/utils/$1' ),
'^@knodes/typedoc-(plugin.*)$': resolveRoot( dirname, './packages/$1/src' ),
'^#plugintestbed$': resolveRoot( './packages/plugintestbed/src' ),
},
setupFilesAfterEnv: [ 'jest-extended/all' ],
watchPathIgnorePatterns: [ '__tests__/mock-fs/.*/docs' ],
modulePathIgnorePatterns: [ '__tests__/mock-fs/.*/' ],
} );
export const anyExt = '.{c,m,}{t,j}s{x,}';
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest[]} */
const generateJestProjectConfig = projectDir => {
const pkg = relative( resolveRoot( 'packages' ), projectDir );
const base = baseConfig( pkg );
return {
rootDir: resolveRoot( 'packages', pkg ),
projects: [
{
...base,
displayName: {
name: 'unit',
color: 'blue',
},
testMatch: [ resolveRoot( 'packages', pkg, `src/**/*.spec${anyExt}` ) ],
},
{
...base,
displayName: {
name: 'integration',
color: 'green',
},
testMatch: [ resolveRoot( 'packages', pkg, `__tests__/integration/**/*.spec${anyExt}` ) ],
},
],
collectCoverageFrom: [
'packages/*/src/**',
`!**/*.spec${anyExt}`,
],
};
};
export default generateJestProjectConfig;