Skip to content

Commit

Permalink
fix(transformer): don't use cache when tsJestConfig is different (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy228 authored Jan 9, 2023
1 parent d62a7ef commit a445638
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
10 changes: 10 additions & 0 deletions src/legacy/ts-jest-transformer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ describe('TsJestTransformer', () => {
expect(cs2).toBe(cs1)
})

test('should return different config set for different tsJestConfig', () => {
const obj2 = { ...obj1, config: { ...obj1.config } }
// @ts-expect-error testing purpose
const cs1 = new TsJestTransformer({ isolatedModules: true })._configsFor(obj1)
// @ts-expect-error testing purpose
const cs2 = new TsJestTransformer({ isolatedModules: false })._configsFor(obj2)

expect(cs2).not.toBe(cs1)
})

test(`should not read disk cache with isolatedModules true`, () => {
const tr = new TsJestTransformer()
const cs = createConfigSet({
Expand Down
37 changes: 18 additions & 19 deletions src/legacy/ts-jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,25 @@ export class TsJestTransformer implements SyncTransformer {
this._watchMode = ccs.watchMode
configSet = ccs.configSet
} else {
if (config.globals?.['ts-jest']) {
this._logger.warn(Deprecations.GlobalsTsJestConfigOption)
}
const jestGlobalsConfig = config.globals ?? {}
const tsJestGlobalsConfig = jestGlobalsConfig['ts-jest'] ?? {}
const migratedConfig = this.tsJestConfig
? {
...config,
globals: {
...jestGlobalsConfig,
'ts-jest': {
...tsJestGlobalsConfig,
...this.tsJestConfig,
},
},
}
: config
// try to look-it up by stringified version
const serializedJestCfg = stringify(config)
const serializedJestCfg = stringify(migratedConfig)
const serializedCcs = TsJestTransformer._cachedConfigSets.find(
(cs) => cs.jestConfig.serialized === serializedJestCfg,
)
Expand All @@ -105,24 +122,6 @@ export class TsJestTransformer implements SyncTransformer {
} else {
// create the new record in the index
this._logger.info('no matching config-set found, creating a new one')

if (config.globals?.['ts-jest']) {
this._logger.warn(Deprecations.GlobalsTsJestConfigOption)
}
const jestGlobalsConfig = config.globals ?? {}
const tsJestGlobalsConfig = jestGlobalsConfig['ts-jest'] ?? {}
const migratedConfig = this.tsJestConfig
? {
...config,
globals: {
...jestGlobalsConfig,
'ts-jest': {
...tsJestGlobalsConfig,
...this.tsJestConfig,
},
},
}
: config
configSet = this._createConfigSet(migratedConfig)
const jest = { ...migratedConfig }
// we need to remove some stuff from jest config
Expand Down

0 comments on commit a445638

Please sign in to comment.