|
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', |
5 |
| - testRegex: [ |
6 |
| - '/tests/.*tests?.[jt]sx?', |
7 |
| - '/__tests__/.*tests?.[jt]sx?', |
8 |
| - '.*.(spec|test).[jt]sx?', |
9 |
| - ], |
| 22 | + ...preset, |
| 23 | + roots: ['<rootDir>'], |
| 24 | + modulePaths: [compilerOptions.baseUrl], |
| 25 | + moduleNameMapper: pathsToModuleNameMapper(pathAliases, { |
| 26 | + useESM: true, |
| 27 | + }), |
| 28 | + modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/build/'], |
| 29 | + testRegex: ['/tests/.*tests?.[mc]?[jt]sx?$', '.*.(spec|test).[mc]?[jt]sx?$'], |
10 | 30 | // 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/'], |
| 31 | + // We can change this back if we consider it useful to run the spec tests when the code is transpiled to javascript |
| 32 | + testPathIgnorePatterns: [ |
| 33 | + 'node_modules', |
| 34 | + '<rootDir>/build[^/]*/', |
| 35 | + '<rootDir>/dist/', |
| 36 | + ], |
13 | 37 | testEnvironment: 'node',
|
14 |
| - collectCoverageFrom: ['src/**/*.{js,ts,jsx,tsx}'], |
| 38 | + collectCoverageFrom: [ |
| 39 | + 'src/**/*.{js,ts,jsx,tsx}', |
| 40 | + '!src/**/*.{spec,test}.{js,ts,jsx,tsx}', |
| 41 | + ], |
15 | 42 | verbose: true,
|
16 | 43 | // Important to use the AfterEnv to have the jest timeout and all the other settings inside that file to be correctly understood
|
17 | 44 | // See the difference between setupFiles and setupFilesAfterEnv to see the difference.
|
|
0 commit comments