diff --git a/src/config/__snapshots__/config-set.spec.ts.snap b/src/config/__snapshots__/config-set.spec.ts.snap index 6619771d30..cdf4b615f8 100644 --- a/src/config/__snapshots__/config-set.spec.ts.snap +++ b/src/config/__snapshots__/config-set.spec.ts.snap @@ -59,8 +59,6 @@ Object { "before": Array [ Object { "factory": [Function], - "name": "hoisting-jest-mock", - "version": 4, }, ], } @@ -73,8 +71,6 @@ Object { "before": Array [ Object { "factory": [Function], - "name": "hoisting-jest-mock", - "version": 4, }, Object { "factory": [Function], @@ -94,8 +90,6 @@ Object { "before": Array [ Object { "factory": [Function], - "name": "hoisting-jest-mock", - "version": 4, }, ], } @@ -112,8 +106,6 @@ Object { "before": Array [ Object { "factory": [Function], - "name": "hoisting-jest-mock", - "version": 4, }, ], } @@ -126,8 +118,6 @@ Object { "before": Array [ Object { "factory": [Function], - "name": "hoisting-jest-mock", - "version": 4, }, Object { "factory": [Function], diff --git a/src/config/config-set.ts b/src/config/config-set.ts index 2a1498cd60..2753035a04 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -101,6 +101,7 @@ export class ConfigSet { readonly isolatedModules: boolean readonly cwd: string readonly rootDir: string + cacheSuffix!: string tsCacheDir: string | undefined parsedTsConfig!: ParsedCommandLine | Record resolvedTransformers: TsJestAstTransformer = { @@ -349,20 +350,30 @@ export class ConfigSet { * @internal */ private _resolveTsCacheDir(): void { + this.cacheSuffix = sha1( + stringify({ + version: this.compilerModule.version, + digest: this.tsJestDigest, + babelConfig: this.babelConfig, + compilerModule: this.compilerModule, + tsconfig: { + options: this.parsedTsConfig.options, + raw: this.parsedTsConfig.raw, + }, + isolatedModules: this.isolatedModules, + diagnostics: this._diagnostics, + transformers: this.resolvedTransformers, + }), + ) if (!this._jestCfg.cache) { this.logger.debug('file caching disabled') } else { - const cacheSuffix = sha1( - stringify({ - version: this.compilerModule.version, - digest: this.tsJestDigest, - compilerModule: this.compilerModule, - compilerOptions: this.parsedTsConfig.options, - isolatedModules: this.isolatedModules, - diagnostics: this._diagnostics, - }), + const res = join( + this._jestCfg.cacheDirectory, + 'ts-jest', + this.cacheSuffix.substr(0, 2), + this.cacheSuffix.substr(2), ) - const res = join(this._jestCfg.cacheDirectory, 'ts-jest', cacheSuffix.substr(0, 2), cacheSuffix.substr(2)) this.logger.debug({ cacheDirectory: res }, 'will use file caching') diff --git a/src/transformers/README.md b/src/transformers/README.md index b5bb598a60..f4b9b0e55e 100644 --- a/src/transformers/README.md +++ b/src/transformers/README.md @@ -9,11 +9,6 @@ import { SourceFile, TransformationContext, Transformer, Visitor } from 'typescr import type { TsCompilerInstance } from 'ts-jest/dist/types' -// this is a unique identifier for your transformer -export const name = 'my-transformer' -// increment this each time you change the behavior of your transformer -export const version = 1 - export function factory(compilerInstance: TsCompilerInstance) { const ts = compilerInstance.configSet.compilerModule function createVisitor(ctx: TransformationContext, sf: SourceFile) { diff --git a/src/transformers/hoist-jest.spec.ts b/src/transformers/hoist-jest.spec.ts index 80a01c78bc..9dc6930aec 100644 --- a/src/transformers/hoist-jest.spec.ts +++ b/src/transformers/hoist-jest.spec.ts @@ -121,14 +121,7 @@ const createFactory = () => hoist.factory(new TsCompiler(createConfigSet(), new const transpile = (source: string) => ts.transpileModule(source, { transformers: { before: [createFactory()] } }) describe('hoisting', () => { - it('should have correct signature', () => { - expect(hoist.name).toBe('hoisting-jest-mock') - expect(typeof hoist.version).toBe('number') - expect(hoist.version).toBeGreaterThan(0) - expect(typeof hoist.factory).toBe('function') - }) - - it.each([CODE_WITH_HOISTING_NO_JEST_GLOBALS, CODE_WITH_HOISTING_HAS_JEST_GLOBALS])( + test.each([CODE_WITH_HOISTING_NO_JEST_GLOBALS, CODE_WITH_HOISTING_HAS_JEST_GLOBALS])( 'should hoist correctly jest methods', (data) => { const out = transpile(data) diff --git a/src/transformers/hoist-jest.ts b/src/transformers/hoist-jest.ts index 30c3492b68..b0511a41a3 100644 --- a/src/transformers/hoist-jest.ts +++ b/src/transformers/hoist-jest.ts @@ -20,16 +20,6 @@ const HOIST_METHODS = ['mock', 'unmock', 'enableAutomock', 'disableAutomock', 'd const JEST_GLOBALS_MODULE_NAME = '@jest/globals' const JEST_GLOBAL_NAME = 'jest' const ROOT_LEVEL_AST = 1 -/** - * @internal - */ -export const name = 'hoisting-jest-mock' -/** - * Please increment this each time the code is modified - * - * @internal - */ -export const version = 4 /** * The factory of hoisting transformer factory diff --git a/src/transformers/path-mapping.spec.ts b/src/transformers/path-mapping.spec.ts index 951f988d7b..7ab86020c7 100644 --- a/src/transformers/path-mapping.spec.ts +++ b/src/transformers/path-mapping.spec.ts @@ -30,13 +30,6 @@ const TS_JS_CODE_WITH_PATH_ALIAS = ` ` describe('path-mapping', () => { - test('should have correct signature', () => { - expect(pathMapping.name).toBe('path-mapping') - expect(typeof pathMapping.version).toBe('number') - expect(pathMapping.version).toBeGreaterThan(0) - expect(typeof pathMapping.factory).toBe('function') - }) - test.each([ { baseUrl: '.', diff --git a/src/transformers/path-mapping.ts b/src/transformers/path-mapping.ts index 6d4971d5c7..dfdcb6aa85 100644 --- a/src/transformers/path-mapping.ts +++ b/src/transformers/path-mapping.ts @@ -11,16 +11,6 @@ import type * as _ts from 'typescript' import type { TsCompilerInstance } from '../types' -/** - * @internal - */ -export const name = 'path-mapping' -// increment this each time the code is modified -/** - * @internal - */ -export const version = 1 - const isBaseDir = (base: string, dir: string) => !relative(base, dir)?.startsWith('.') /** diff --git a/src/ts-jest-transformer.ts b/src/ts-jest-transformer.ts index b42b6a2cab..99ef2a5885 100644 --- a/src/ts-jest-transformer.ts +++ b/src/ts-jest-transformer.ts @@ -90,15 +90,7 @@ export class TsJestTransformer implements Transformer { // this which does not depend on config jest.name = undefined as any jest.cacheDirectory = undefined as any - this._transformCfgStr = new JsonableValue({ - digest: configSet.tsJestDigest, - babel: configSet.babelConfig, - ...jest, - tsconfig: { - options: configSet.parsedTsConfig.options, - raw: configSet.parsedTsConfig.raw, - }, - }).serialized + this._transformCfgStr = `${new JsonableValue(jest).serialized}${configSet.cacheSuffix}` this._compiler = new TsJestCompiler(configSet, cacheFS) TsJestTransformer._cachedConfigSets.push({ jestConfig: new JsonableValue(config),