-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.ts
More file actions
48 lines (43 loc) · 1.7 KB
/
Copy pathjest.config.ts
File metadata and controls
48 lines (43 loc) · 1.7 KB
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
import dotenv from 'dotenv';
import { getTsconfig } from 'get-tsconfig';
import { Config } from 'jest';
import path from 'path';
import { pathsToModuleNameMapper } from 'ts-jest';
const fullTsconfig = getTsconfig();
if (!fullTsconfig) {
throw new Error(`a "tsconfig.json" must be provided`);
}
// Load test variables if any
dotenv.config({ path: path.resolve(__dirname, './.env.jest') });
dotenv.config({ path: path.resolve(__dirname, './.env.jest.local') });
// Add any custom config to be passed to Jest
const customJestConfig: Config = {
preset: 'ts-jest',
setupFilesAfterEnv: [],
moduleDirectories: ['node_modules', '<rootDir>/'],
moduleNameMapper: {
...(fullTsconfig.config.compilerOptions && fullTsconfig.config.compilerOptions.paths
? pathsToModuleNameMapper(fullTsconfig.config.compilerOptions.paths, { prefix: '<rootDir>/' })
: {}),
},
testEnvironment: 'jest-environment-node',
modulePathIgnorePatterns: ['<rootDir>/data/'],
testPathIgnorePatterns: ['<rootDir>/data/', '<rootDir>/node_modules/'],
transformIgnorePatterns: [],
extensionsToTreatAsEsm: ['.ts'],
transform: {
'\\.ts$': [
'ts-jest',
{
useESM: true,
isolatedModules: true, // It disables type checking to make it faster (note it's not taken by default from the `tsconfig.json`)
},
],
},
};
// Used to specify the default cache directory in our CI/CD environment
// Note: it cannot be set to undefined directly into the config object because Jest would take it due to the object key existing, so using a separate condition
if (typeof process.env.JEST_CACHE_PATH === 'string') {
customJestConfig.cacheDirectory = process.env.JEST_CACHE_PATH;
}
export default customJestConfig;