From 7d001be30a0859e3d1614c78b91c559fc6a6775f Mon Sep 17 00:00:00 2001 From: ahnpnl Date: Fri, 5 Jul 2024 16:09:09 +0200 Subject: [PATCH] refactor: use `TsJestTransformerOptions` everywhere possibly --- src/__helpers__/fakers.ts | 10 +++++----- src/index.ts | 4 ++-- src/legacy/config/config-set.spec.ts | 4 ++-- src/legacy/index.ts | 5 +++-- src/legacy/ts-jest-transformer.ts | 6 +++--- src/types.ts | 30 ++++++++++++++-------------- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/__helpers__/fakers.ts b/src/__helpers__/fakers.ts index 5566b94948..3e30dc6a41 100644 --- a/src/__helpers__/fakers.ts +++ b/src/__helpers__/fakers.ts @@ -5,7 +5,7 @@ import type { Logger } from 'bs-logger' import { TsCompiler } from '../legacy/compiler' import { ConfigSet } from '../legacy/config/config-set' -import type { StringMap, TsJestGlobalOptions } from '../types' +import type { StringMap, TsJestTransformerOptions } from '../types' import type { ImportReasons } from '../utils/messages' export function filePath(relPath: string): string { @@ -19,7 +19,7 @@ const defaultTestMatch = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[ function getJestConfig( options?: Partial, - tsJestOptions?: TsJestGlobalOptions, + tsJestOptions?: TsJestTransformerOptions, ): T { const res = { globals: {}, @@ -47,7 +47,7 @@ export function createConfigSet({ ...others }: { jestConfig?: Partial - tsJestConfig?: TsJestGlobalOptions + tsJestConfig?: TsJestTransformerOptions logger?: Logger resolve?: ((path: string) => string) | null // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -81,8 +81,8 @@ export function makeCompiler( parentConfig, }: { jestConfig?: Partial - tsJestConfig?: TsJestGlobalOptions - parentConfig?: TsJestGlobalOptions + tsJestConfig?: TsJestTransformerOptions + parentConfig?: TsJestTransformerOptions } = {}, jestCacheFS: StringMap = new Map(), ): TsCompiler { diff --git a/src/index.ts b/src/index.ts index 4a4c4d9d2f..605a2ef8bf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { TsJestTransformer } from './legacy/ts-jest-transformer' -import type { TsJestGlobalOptions } from './types' +import type { TsJestTransformerOptions } from './types' export * from './config' export * from './constants' @@ -12,7 +12,7 @@ export * from './utils' export * from './types' export default { - createTransformer(tsJestConfig?: TsJestGlobalOptions) { + createTransformer(tsJestConfig?: TsJestTransformerOptions) { return new TsJestTransformer(tsJestConfig) }, } diff --git a/src/legacy/config/config-set.spec.ts b/src/legacy/config/config-set.spec.ts index d167817c16..ebcb658c1b 100644 --- a/src/legacy/config/config-set.spec.ts +++ b/src/legacy/config/config-set.spec.ts @@ -7,7 +7,7 @@ import * as ts from 'typescript' import { createConfigSet } from '../../__helpers__/fakers' import { logTargetMock } from '../../__helpers__/mocks' import type { RawCompilerOptions } from '../../raw-compiler-options' -import type { AstTransformerDesc, TsJestGlobalOptions } from '../../types' +import type { AstTransformerDesc, TsJestTransformerOptions } from '../../types' import { stringify } from '../../utils' import * as _backports from '../../utils/backports' import { getPackageVersion } from '../../utils/get-package-version' @@ -47,7 +47,7 @@ test('should create a default fallback jest config when jest config is undefined }) describe('parsedTsConfig', () => { - const get = (tsJest?: TsJestGlobalOptions) => createConfigSet({ tsJestConfig: tsJest }).parsedTsConfig + const get = (tsJest?: TsJestTransformerOptions) => createConfigSet({ tsJestConfig: tsJest }).parsedTsConfig it('should read file list from default tsconfig', () => { // since the default is to lookup for tsconfig, diff --git a/src/legacy/index.ts b/src/legacy/index.ts index 8993db0b27..e3a3b70403 100644 --- a/src/legacy/index.ts +++ b/src/legacy/index.ts @@ -1,7 +1,8 @@ -import type { TsJestGlobalOptions } from '../types' +import type { TsJestTransformerOptions } from '../types' import { TsJestTransformer } from './ts-jest-transformer' export default { - createTransformer: (tsJestConfig?: TsJestGlobalOptions): TsJestTransformer => new TsJestTransformer(tsJestConfig), + createTransformer: (tsJestConfig?: TsJestTransformerOptions): TsJestTransformer => + new TsJestTransformer(tsJestConfig), } diff --git a/src/legacy/ts-jest-transformer.ts b/src/legacy/ts-jest-transformer.ts index ffbfe846f7..a08fa132e1 100644 --- a/src/legacy/ts-jest-transformer.ts +++ b/src/legacy/ts-jest-transformer.ts @@ -53,7 +53,7 @@ export class TsJestTransformer implements SyncTransformer = new Map() private _watchMode = false - constructor(private readonly tsJestConfig?: TsJestTransformOptions['transformerConfig']) { + constructor(private readonly transformerOptions?: TsJestTransformerOptions) { this._logger = rootLogger.child({ namespace: 'ts-jest-transformer' }) VersionCheckers.jest.warn() /** @@ -106,14 +106,14 @@ export class TsJestTransformer implements SyncTransformer] } } + +declare module '@jest/types' { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Config { + interface ConfigGlobals { + /** + * strangely `@ts-expect-error` doesn't work in this case when running + * `npm run build` vs `npm run pretest` + */ + // eslint-disable-next-line + // @ts-ignore + 'ts-jest'?: TsJestTransformerOptions + } + } +}