-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.js
56 lines (52 loc) · 1.57 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
// @ts-check
import { getTsconfig } from 'get-tsconfig';
import { pathsToModuleNameMapper } from 'ts-jest';
import { getJestCachePath } from '../../cache.config.js';
const tsConfigFile = new URL('./tsconfig.jest.json', import.meta.url).pathname;
/**
* Transform the tsconfig paths into jest compatible one (support extends)
* @param {string} tsConfigFile
*/
const getTsConfigBasePaths = (tsConfigFile) => {
const parsedTsConfig = getTsconfig(tsConfigFile);
if (parsedTsConfig === null) {
throw new Error(`Cannot find tsconfig file: ${tsConfigFile}`);
}
const tsPaths = parsedTsConfig.config.compilerOptions?.paths;
return tsPaths
? pathsToModuleNameMapper(tsPaths, {
prefix: '<rootDir>/',
})
: {};
};
/** @type {import('ts-jest/dist').InitialOptionsTsJest} */
const config = {
displayName: `cache-redis:unit`,
preset: 'ts-jest/presets/default-esm',
cacheDirectory: getJestCachePath('@soluble/cache-redis'),
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
verbose: true,
rootDir: './src',
testMatch: ['<rootDir>/**/*.{spec,test}.{js,jsx,ts,tsx}'],
transform: {
'^.+\\.m?[tj]sx?$': [
'ts-jest',
{
tsconfig: tsConfigFile,
},
],
},
moduleNameMapper: {
...getTsConfigBasePaths(tsConfigFile),
},
// false by default, overrides in cli, ie: yarn test:unit --collect-coverage=true
collectCoverage: false,
coverageDirectory: '<rootDir>/../coverage',
collectCoverageFrom: [
'<rootDir>/**/*.{ts,tsx,js,jsx}',
'!**/*.test.{js,ts}',
'!**/__mock__/*',
],
};
export default config;