forked from belgattitude/nextjs-monorepo-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.config.js
50 lines (44 loc) · 1.52 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
// @ts-check
const { defaults: tsjPreset } = require('ts-jest/presets');
const { pathsToModuleNameMapper } = require('ts-jest');
const { getJestCachePath } = require('../../cache.config');
const packageJson = require('./package.json');
const { compilerOptions: baseTsConfig } = require('./tsconfig.json');
// Take the paths from tsconfig automatically from base tsconfig.json
// @link https://kulshekhar.github.io/ts-jest/docs/paths-mapping
const getTsConfigBasePaths = () => {
return baseTsConfig.paths
? pathsToModuleNameMapper(baseTsConfig.paths, {
prefix: '<rootDir>/',
})
: {};
};
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
const config = {
displayName: `${packageJson.name}:unit`,
cacheDirectory: getJestCachePath(packageJson.name),
testEnvironment: 'jsdom',
verbose: true,
rootDir: './src',
transform: {
...tsjPreset.transform,
},
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
testMatch: ['<rootDir>/**/*.{spec,test}.{js,jsx,ts,tsx}'],
moduleNameMapper: {
// For @testing-library/react
'^@/test-utils$': '<rootDir>/../config/jest/test-utils',
...getTsConfigBasePaths(),
},
// 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.ts'],
globals: {
'ts-jest': {
diagnostics: false,
tsconfig: './tsconfig.jest.json',
},
},
};
module.exports = config;