Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transformer): don't use cache when tsJestConfig is different #3966

Merged
merged 1 commit into from Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/legacy/ts-jest-transformer.spec.ts
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
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