|
1 | 1 | /* eslint-disable no-console,@typescript-eslint/no-magic-numbers */ |
2 | 2 | import { exposeTsCompilerOptionsByTsConfig } from '@angular-ru/common/node.js'; |
3 | | -import { Any } from '@angular-ru/common/typings'; |
4 | 3 | import type { Config } from '@jest/types'; |
5 | 4 | import * as fs from 'fs'; |
6 | 5 | import * as path from 'path'; |
| 6 | +import * as tsJestUtils from 'ts-jest/utils'; |
| 7 | +import { CompilerOptions } from 'typescript'; |
7 | 8 |
|
8 | 9 | import { |
9 | 10 | DEFAULT_BAIL, |
@@ -41,21 +42,18 @@ export function createTsJestConfig(options: JestConfigOptions): Config.InitialOp |
41 | 42 | ); |
42 | 43 | } |
43 | 44 |
|
44 | | - const compilerOptions: Record<string, Any> = exposeTsCompilerOptionsByTsConfig(resolvedTsConfigPath); |
| 45 | + const compilerOptions: CompilerOptions = exposeTsCompilerOptionsByTsConfig(resolvedTsConfigPath); |
| 46 | + const prefix: string = `<rootDir>/${compilerOptions?.baseUrl ?? ''}/`.replace(/\.\//g, '/').replace(/\/\/+/g, '/'); |
| 47 | + const rootModuleNameMapper: |
| 48 | + | { [key: string]: string | string[] } |
| 49 | + | undefined = tsJestUtils.pathsToModuleNameMapper(compilerOptions?.paths ?? {}, { prefix }); |
45 | 50 |
|
46 | | - const { pathsToModuleNameMapper: resolver }: Any = require('ts-jest/utils'); |
47 | | - |
48 | | - const prefix: Record<string, Any> = { |
49 | | - prefix: `<rootDir>/${compilerOptions?.baseUrl ?? ''}/`.replace(/\.\//g, '/').replace(/\/\/+/g, '/') |
50 | | - }; |
51 | | - |
52 | | - const rootModuleNameMapper: { [key: string]: string | string[] } = resolver(compilerOptions?.paths ?? {}, prefix); |
53 | 51 | const moduleNameMapper: JestModuleMapper = options.jestConfig?.moduleNameMapper ?? rootModuleNameMapper; |
54 | 52 |
|
55 | 53 | if (options.debug) { |
56 | 54 | console.log('[DEBUG]: rootDir: ', resolvedRootDir); |
57 | 55 | console.log('[DEBUG]: tsConfig: ', resolvedTsConfigPath); |
58 | | - console.log('[DEBUG]: prefix: ', JSON.stringify(prefix, null, 4)); |
| 56 | + console.log('[DEBUG]: prefix: ', prefix); |
59 | 57 | console.log('[DEBUG]: moduleNameMapper: ', JSON.stringify(moduleNameMapper, null, 4), '\n'); |
60 | 58 | } |
61 | 59 |
|
|
0 commit comments