diff --git a/src/ts-jest-transformer.spec.ts b/src/ts-jest-transformer.spec.ts index 1a1089bc75..a99b2cbead 100644 --- a/src/ts-jest-transformer.spec.ts +++ b/src/ts-jest-transformer.spec.ts @@ -31,14 +31,32 @@ beforeEach(() => { describe('TsJestTransformer', () => { describe('_configsFor', () => { + const obj1 = { + config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], globals: {}, testMatch: [], testRegex: [] }, + cacheFS: new Map(), + } + + test('should cache necessary things', () => { + // @ts-expect-error testing purpose + new TsJestTransformer()._configsFor(obj1) + + // @ts-expect-error testing purpose + expect(Object.keys(TsJestTransformer._cachedConfigSets[0])).toMatchInlineSnapshot(` +Array [ + "jestConfig", + "configSet", + "transformerCfgStr", + "compiler", + "depGraphs", + "tsResolvedModulesCachePath", +] +`) + }) + test( 'should return the same config set for same values with different jest config objects' + ' but their serialized versions are the same', () => { - const obj1 = { - config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], globals: {}, testMatch: [], testRegex: [] }, - cacheFS: new Map(), - } const obj2 = { ...obj1, config: { ...obj1.config, globals: Object.create(null) } } // @ts-expect-error testing purpose const cs1 = new TsJestTransformer()._configsFor(obj1) @@ -50,10 +68,6 @@ describe('TsJestTransformer', () => { ) test('should return the same config set for same values with jest config objects', () => { - const obj1 = { - config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], globals: {}, testMatch: [], testRegex: [] }, - cacheFS: new Map(), - } const obj2 = { ...obj1 } // @ts-expect-error testing purpose const cs1 = new TsJestTransformer()._configsFor(obj1) diff --git a/src/ts-jest-transformer.ts b/src/ts-jest-transformer.ts index 99ef2a5885..02f8e45f01 100644 --- a/src/ts-jest-transformer.ts +++ b/src/ts-jest-transformer.ts @@ -23,6 +23,8 @@ interface CachedConfigSet { jestConfig: JsonableValue transformerCfgStr: string compiler: TsJestCompiler + depGraphs: Map + tsResolvedModulesCachePath: string | undefined } interface TsJestHooksMap { @@ -65,6 +67,8 @@ export class TsJestTransformer implements Transformer { if (ccs) { this._transformCfgStr = ccs.transformerCfgStr this._compiler = ccs.compiler + this._depGraphs = ccs.depGraphs + this._tsResolvedModulesCachePath = ccs.tsResolvedModulesCachePath configSet = ccs.configSet } else { // try to look-it up by stringified version @@ -79,6 +83,8 @@ export class TsJestTransformer implements Transformer { serializedCcs.jestConfig.value = config this._transformCfgStr = serializedCcs.transformerCfgStr this._compiler = serializedCcs.compiler + this._depGraphs = serializedCcs.depGraphs + this._tsResolvedModulesCachePath = serializedCcs.tsResolvedModulesCachePath configSet = serializedCcs.configSet } else { // create the new record in the index @@ -92,13 +98,15 @@ export class TsJestTransformer implements Transformer { jest.cacheDirectory = undefined as any this._transformCfgStr = `${new JsonableValue(jest).serialized}${configSet.cacheSuffix}` this._compiler = new TsJestCompiler(configSet, cacheFS) + this._getFsCachedResolvedModules(configSet) TsJestTransformer._cachedConfigSets.push({ jestConfig: new JsonableValue(config), configSet, transformerCfgStr: this._transformCfgStr, compiler: this._compiler, + depGraphs: this._depGraphs, + tsResolvedModulesCachePath: this._tsResolvedModulesCachePath, }) - this._getFsCachedResolvedModules(configSet) } }