/
jest.config.js
59 lines (54 loc) · 1.88 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
57
58
59
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',
// @ts-ignore
transform: {
'.*\\.(tsx?)$': [
'@swc/jest',
{
jsc: {
target: 'es2021',
transform: {
react: {
runtime: 'automatic',
},
},
},
},
],
},
setupFilesAfterEnv: ['<rootDir>/../.jest/setupTests.ts'],
testMatch: ['<rootDir>/**/*.{spec,test}.{js,jsx,ts,tsx}'],
moduleNameMapper: {
// For @testing-library/react
'^@/test-utils$': '<rootDir>/../config/jest/test-utils',
'^@/test-utils/(.*)$': '<rootDir>/../config/jest/$1',
'.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
// https://jestjs.io/docs/webpack#handling-static-assets
'^.+\\.(jpg|jpeg|png|gif|webp|svg)$': `<rootDir>/../.jest/__mocks__/fileMock.js`,
...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'],
coveragePathIgnorePatterns: ['<rootDir>/../config/', '<rootDir>/../.jest/'],
};
module.exports = config;