Skip to content

Commit 7d001be

Browse files
committed
refactor: use TsJestTransformerOptions everywhere possibly
1 parent 9e99c24 commit 7d001be

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

src/__helpers__/fakers.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Logger } from 'bs-logger'
55

66
import { TsCompiler } from '../legacy/compiler'
77
import { ConfigSet } from '../legacy/config/config-set'
8-
import type { StringMap, TsJestGlobalOptions } from '../types'
8+
import type { StringMap, TsJestTransformerOptions } from '../types'
99
import type { ImportReasons } from '../utils/messages'
1010

1111
export function filePath(relPath: string): string {
@@ -19,7 +19,7 @@ const defaultTestMatch = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[
1919

2020
function getJestConfig<T extends Config.ProjectConfig>(
2121
options?: Partial<Config.InitialOptions | Config.ProjectConfig>,
22-
tsJestOptions?: TsJestGlobalOptions,
22+
tsJestOptions?: TsJestTransformerOptions,
2323
): T {
2424
const res = {
2525
globals: {},
@@ -47,7 +47,7 @@ export function createConfigSet({
4747
...others
4848
}: {
4949
jestConfig?: Partial<Config.ProjectConfig>
50-
tsJestConfig?: TsJestGlobalOptions
50+
tsJestConfig?: TsJestTransformerOptions
5151
logger?: Logger
5252
resolve?: ((path: string) => string) | null
5353
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -81,8 +81,8 @@ export function makeCompiler(
8181
parentConfig,
8282
}: {
8383
jestConfig?: Partial<Config.ProjectConfig>
84-
tsJestConfig?: TsJestGlobalOptions
85-
parentConfig?: TsJestGlobalOptions
84+
tsJestConfig?: TsJestTransformerOptions
85+
parentConfig?: TsJestTransformerOptions
8686
} = {},
8787
jestCacheFS: StringMap = new Map<string, string>(),
8888
): TsCompiler {

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TsJestTransformer } from './legacy/ts-jest-transformer'
2-
import type { TsJestGlobalOptions } from './types'
2+
import type { TsJestTransformerOptions } from './types'
33

44
export * from './config'
55
export * from './constants'
@@ -12,7 +12,7 @@ export * from './utils'
1212
export * from './types'
1313

1414
export default {
15-
createTransformer(tsJestConfig?: TsJestGlobalOptions) {
15+
createTransformer(tsJestConfig?: TsJestTransformerOptions) {
1616
return new TsJestTransformer(tsJestConfig)
1717
},
1818
}

src/legacy/config/config-set.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as ts from 'typescript'
77
import { createConfigSet } from '../../__helpers__/fakers'
88
import { logTargetMock } from '../../__helpers__/mocks'
99
import type { RawCompilerOptions } from '../../raw-compiler-options'
10-
import type { AstTransformerDesc, TsJestGlobalOptions } from '../../types'
10+
import type { AstTransformerDesc, TsJestTransformerOptions } from '../../types'
1111
import { stringify } from '../../utils'
1212
import * as _backports from '../../utils/backports'
1313
import { getPackageVersion } from '../../utils/get-package-version'
@@ -47,7 +47,7 @@ test('should create a default fallback jest config when jest config is undefined
4747
})
4848

4949
describe('parsedTsConfig', () => {
50-
const get = (tsJest?: TsJestGlobalOptions) => createConfigSet({ tsJestConfig: tsJest }).parsedTsConfig
50+
const get = (tsJest?: TsJestTransformerOptions) => createConfigSet({ tsJestConfig: tsJest }).parsedTsConfig
5151

5252
it('should read file list from default tsconfig', () => {
5353
// since the default is to lookup for tsconfig,

src/legacy/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { TsJestGlobalOptions } from '../types'
1+
import type { TsJestTransformerOptions } from '../types'
22

33
import { TsJestTransformer } from './ts-jest-transformer'
44

55
export default {
6-
createTransformer: (tsJestConfig?: TsJestGlobalOptions): TsJestTransformer => new TsJestTransformer(tsJestConfig),
6+
createTransformer: (tsJestConfig?: TsJestTransformerOptions): TsJestTransformer =>
7+
new TsJestTransformer(tsJestConfig),
78
}

src/legacy/ts-jest-transformer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
5353
private _depGraphs: Map<string, DepGraphInfo> = new Map<string, DepGraphInfo>()
5454
private _watchMode = false
5555

56-
constructor(private readonly tsJestConfig?: TsJestTransformOptions['transformerConfig']) {
56+
constructor(private readonly transformerOptions?: TsJestTransformerOptions) {
5757
this._logger = rootLogger.child({ namespace: 'ts-jest-transformer' })
5858
VersionCheckers.jest.warn()
5959
/**
@@ -106,14 +106,14 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
106106
}
107107
const jestGlobalsConfig = config.globals ?? {}
108108
const tsJestGlobalsConfig = jestGlobalsConfig['ts-jest'] ?? {}
109-
const migratedConfig = this.tsJestConfig
109+
const migratedConfig = this.transformerOptions
110110
? {
111111
...config,
112112
globals: {
113113
...jestGlobalsConfig,
114114
'ts-jest': {
115115
...tsJestGlobalsConfig,
116-
...this.tsJestConfig,
116+
...this.transformerOptions,
117117
},
118118
},
119119
}

src/types.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@ import { JS_TRANSFORM_PATTERN, TS_JS_TRANSFORM_PATTERN, TS_TRANSFORM_PATTERN } f
88
import type { ConfigSet } from './legacy/config/config-set'
99
import type { RawCompilerOptions } from './raw-compiler-options'
1010

11-
declare module '@jest/types' {
12-
// eslint-disable-next-line @typescript-eslint/no-namespace
13-
namespace Config {
14-
interface ConfigGlobals {
15-
/**
16-
* strangely `@ts-expect-error` doesn't work in this case when running
17-
* `npm run build` vs `npm run pretest`
18-
*/
19-
// eslint-disable-next-line
20-
// @ts-ignore
21-
'ts-jest'?: TsJestGlobalOptions
22-
}
23-
}
24-
}
25-
2611
/**
2712
* @internal
2813
*/
@@ -269,3 +254,18 @@ export type JsWithBabelPreset = {
269254
[TS_TRANSFORM_PATTERN]: ['ts-jest', Omit<TsJestTransformerOptions, 'useESM'>]
270255
}
271256
}
257+
258+
declare module '@jest/types' {
259+
// eslint-disable-next-line @typescript-eslint/no-namespace
260+
namespace Config {
261+
interface ConfigGlobals {
262+
/**
263+
* strangely `@ts-expect-error` doesn't work in this case when running
264+
* `npm run build` vs `npm run pretest`
265+
*/
266+
// eslint-disable-next-line
267+
// @ts-ignore
268+
'ts-jest'?: TsJestTransformerOptions
269+
}
270+
}
271+
}

0 commit comments

Comments
 (0)