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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(transformer): don't use cache when tsJestConfig is different
Ismaïl Ouazzany committed Jan 8, 2023
commit 2a201a392266b7532886dddaf1fa2ea67f4685a5
10 changes: 10 additions & 0 deletions src/legacy/ts-jest-transformer.spec.ts
Original file line number Diff line number Diff line change
@@ -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({
37 changes: 18 additions & 19 deletions src/legacy/ts-jest-transformer.ts
Original file line number Diff line number Diff line change
@@ -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,
)
@@ -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