-
Notifications
You must be signed in to change notification settings - Fork 3
/
jest.config.ts
44 lines (39 loc) · 1.32 KB
/
jest.config.ts
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
import { compilerOptions } from './tsconfig.json';
import type { Config } from '@jest/types';
/**
* Make `tsconfig.json`'s `paths` work in Jest
* @link https://stackoverflow.com/a/56792936
*/
function makeModuleNameMapperFromTsConfig(srcPath: string) {
// Get paths from tsconfig
const { paths }: { paths: Record<string, string[]> } = compilerOptions;
const aliases: { [key: string]: string } = {};
// Iterate over paths and convert them into moduleNameMapper format
Object.keys(paths).forEach((item) => {
const key = item.replace('/*', '/(.*)');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const path = paths[item]![0]!.replace('/*', '/$1');
aliases[key] = srcPath + '/' + path;
});
return aliases;
}
const config: Config.InitialOptions = {
verbose: true,
roots: ['<rootDir>'],
testMatch: [
'**/tests/**/*.+(ts|tsx|js)',
'**/?(*.)+(spec|test).+(ts|tsx|js)',
],
testPathIgnorePatterns: ['<rootDir>/.next', '<rootDir>/playwright/'],
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
},
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
testEnvironment: 'node',
moduleNameMapper: makeModuleNameMapperFromTsConfig('<rootDir>'),
setupFiles: ['dotenv/config'],
};
export default config;