|
1 |
| -import type { JestConfigWithTsJest } from 'ts-jest'; |
| 1 | +import { |
| 2 | + createDefaultEsmPreset, |
| 3 | + pathsToModuleNameMapper, |
| 4 | + type JestConfigWithTsJest, |
| 5 | +} from 'ts-jest'; |
| 6 | + |
| 7 | +import { compilerOptions } from './tsconfig.aliases.json'; |
| 8 | +import packageJson from './package.json'; |
| 9 | + |
| 10 | +const pathAliases = { |
| 11 | + ...compilerOptions.paths, |
| 12 | + // Jest wants to know the folder to do the transformation, not the `src/index.js`. 🤷 |
| 13 | + [packageJson.name]: ['src'], |
| 14 | +}; |
| 15 | + |
| 16 | +// See here for more info https://kulshekhar.github.io/ts-jest/docs/getting-started/presets/#advanced |
| 17 | +const preset = createDefaultEsmPreset({ |
| 18 | + tsconfig: './__tests__/tsconfig.json', |
| 19 | +}); |
2 | 20 |
|
3 | 21 | const config: JestConfigWithTsJest = {
|
4 |
| - preset: 'ts-jest', |
| 22 | + ...preset, |
| 23 | + roots: ['<rootDir>'], |
| 24 | + modulePaths: [compilerOptions.baseUrl], |
| 25 | + moduleNameMapper: pathsToModuleNameMapper(pathAliases, { |
| 26 | + useESM: true, |
| 27 | + }), |
| 28 | + modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/build/'], |
5 | 29 | testRegex: [
|
6 | 30 | '/tests/.*tests?.[jt]sx?',
|
7 | 31 | '/__tests__/.*tests?.[jt]sx?',
|
8 | 32 | '.*.(spec|test).[jt]sx?',
|
9 | 33 | ],
|
10 | 34 | // I dono't think we need to run the spec multiple times.. the functional test on tests/ maybe.
|
11 |
| - // We can change this if we consider it useful to run the spec tests when the code is transpiled to javascript |
12 |
| - testPathIgnorePatterns: ['node_modules', 'build/'], |
| 35 | + // We can change this back if we consider it useful to run the spec tests when the code is transpiled to javascript |
| 36 | + testPathIgnorePatterns: [ |
| 37 | + 'node_modules', |
| 38 | + '<rootDir>/build/', |
| 39 | + '<rootDir>/dist/', |
| 40 | + ], |
13 | 41 | testEnvironment: 'node',
|
14 | 42 | collectCoverageFrom: ['src/**/*.{js,ts,jsx,tsx}'],
|
15 | 43 | verbose: true,
|
|
0 commit comments