Skip to content

Commit f93a53f

Browse files
committed
!fixup feat(@angular-ru/jest-utils): refactor configuration
1 parent 71619c3 commit f93a53f

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

packages/jest-utils/src/utils/create-ts-jest-config.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable no-console,@typescript-eslint/no-magic-numbers */
22
import { exposeTsCompilerOptionsByTsConfig } from '@angular-ru/common/node.js';
3-
import { Any } from '@angular-ru/common/typings';
43
import type { Config } from '@jest/types';
54
import * as fs from 'fs';
65
import * as path from 'path';
6+
import * as tsJestUtils from 'ts-jest/utils';
7+
import { CompilerOptions } from 'typescript';
78

89
import {
910
DEFAULT_BAIL,
@@ -41,21 +42,18 @@ export function createTsJestConfig(options: JestConfigOptions): Config.InitialOp
4142
);
4243
}
4344

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 });
4550

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);
5351
const moduleNameMapper: JestModuleMapper = options.jestConfig?.moduleNameMapper ?? rootModuleNameMapper;
5452

5553
if (options.debug) {
5654
console.log('[DEBUG]: rootDir: ', resolvedRootDir);
5755
console.log('[DEBUG]: tsConfig: ', resolvedTsConfigPath);
58-
console.log('[DEBUG]: prefix: ', JSON.stringify(prefix, null, 4));
56+
console.log('[DEBUG]: prefix: ', prefix);
5957
console.log('[DEBUG]: moduleNameMapper: ', JSON.stringify(moduleNameMapper, null, 4), '\n');
6058
}
6159

0 commit comments

Comments
 (0)