Skip to content

Commit a445638

Browse files
authoredJan 9, 2023
fix(transformer): don't use cache when tsJestConfig is different (#3966)
1 parent d62a7ef commit a445638

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed
 

‎src/legacy/ts-jest-transformer.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ describe('TsJestTransformer', () => {
8080
expect(cs2).toBe(cs1)
8181
})
8282

83+
test('should return different config set for different tsJestConfig', () => {
84+
const obj2 = { ...obj1, config: { ...obj1.config } }
85+
// @ts-expect-error testing purpose
86+
const cs1 = new TsJestTransformer({ isolatedModules: true })._configsFor(obj1)
87+
// @ts-expect-error testing purpose
88+
const cs2 = new TsJestTransformer({ isolatedModules: false })._configsFor(obj2)
89+
90+
expect(cs2).not.toBe(cs1)
91+
})
92+
8393
test(`should not read disk cache with isolatedModules true`, () => {
8494
const tr = new TsJestTransformer()
8595
const cs = createConfigSet({

‎src/legacy/ts-jest-transformer.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,25 @@ export class TsJestTransformer implements SyncTransformer {
8686
this._watchMode = ccs.watchMode
8787
configSet = ccs.configSet
8888
} else {
89+
if (config.globals?.['ts-jest']) {
90+
this._logger.warn(Deprecations.GlobalsTsJestConfigOption)
91+
}
92+
const jestGlobalsConfig = config.globals ?? {}
93+
const tsJestGlobalsConfig = jestGlobalsConfig['ts-jest'] ?? {}
94+
const migratedConfig = this.tsJestConfig
95+
? {
96+
...config,
97+
globals: {
98+
...jestGlobalsConfig,
99+
'ts-jest': {
100+
...tsJestGlobalsConfig,
101+
...this.tsJestConfig,
102+
},
103+
},
104+
}
105+
: config
89106
// try to look-it up by stringified version
90-
const serializedJestCfg = stringify(config)
107+
const serializedJestCfg = stringify(migratedConfig)
91108
const serializedCcs = TsJestTransformer._cachedConfigSets.find(
92109
(cs) => cs.jestConfig.serialized === serializedJestCfg,
93110
)
@@ -105,24 +122,6 @@ export class TsJestTransformer implements SyncTransformer {
105122
} else {
106123
// create the new record in the index
107124
this._logger.info('no matching config-set found, creating a new one')
108-
109-
if (config.globals?.['ts-jest']) {
110-
this._logger.warn(Deprecations.GlobalsTsJestConfigOption)
111-
}
112-
const jestGlobalsConfig = config.globals ?? {}
113-
const tsJestGlobalsConfig = jestGlobalsConfig['ts-jest'] ?? {}
114-
const migratedConfig = this.tsJestConfig
115-
? {
116-
...config,
117-
globals: {
118-
...jestGlobalsConfig,
119-
'ts-jest': {
120-
...tsJestGlobalsConfig,
121-
...this.tsJestConfig,
122-
},
123-
},
124-
}
125-
: config
126125
configSet = this._createConfigSet(migratedConfig)
127126
const jest = { ...migratedConfig }
128127
// we need to remove some stuff from jest config

0 commit comments

Comments
 (0)
Please sign in to comment.