Skip to content

Commit a5d6f2d

Browse files
hnrqerahnpnl
authored andcommitted
fix: calculated cache key based on supportsStaticESM
1 parent 2d16f4a commit a5d6f2d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ describe('TsJestTransformer', () => {
189189
...input.transformOptions,
190190
config: { ...input.transformOptions.config, instrument: true },
191191
}),
192+
tr.getCacheKey(input.fileContent, input.fileName, {
193+
...input.transformOptions,
194+
supportsStaticESM: true,
195+
}),
192196
tr.getCacheKey(input.fileContent, input.fileName, {
193197
...input.transformOptions,
194198
config: { ...input.transformOptions.config, rootDir: '/bar' },
@@ -242,6 +246,27 @@ describe('TsJestTransformer', () => {
242246
expect(cacheKey1).not.toEqual(cacheKey2)
243247
})
244248

249+
test('should be different between supportsStaticESM true and supportsStaticESM false', () => {
250+
jest.spyOn(TsJestCompiler.prototype, 'getResolvedModules').mockReturnValueOnce([])
251+
252+
const cacheKey1 = tr.getCacheKey(input.fileContent, input.fileName, {
253+
...transformOptionsWithCache,
254+
supportsStaticESM: true,
255+
})
256+
257+
jest.spyOn(TsJestCompiler.prototype, 'getResolvedModules').mockReturnValueOnce([])
258+
const tr1 = new TsJestTransformer()
259+
const cacheKey2 = tr1.getCacheKey(input.fileContent, input.fileName, transformOptionsWithCache)
260+
261+
expect(TsJestCompiler.prototype.getResolvedModules).toHaveBeenCalledTimes(1)
262+
expect(TsJestCompiler.prototype.getResolvedModules).toHaveBeenCalledWith(
263+
input.fileContent,
264+
input.fileName,
265+
new Map(),
266+
)
267+
expect(cacheKey1).not.toEqual(cacheKey2)
268+
})
269+
245270
test('should be different with different file content for the same file', () => {
246271
jest.spyOn(TsJestCompiler.prototype, 'getResolvedModules').mockReturnValueOnce([])
247272

src/legacy/ts-jest-transformer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,16 @@ export class TsJestTransformer implements SyncTransformer {
308308
this._logger.debug({ fileName: filePath, transformOptions }, 'computing cache key for', filePath)
309309

310310
// we do not instrument, ensure it is false all the time
311-
const { instrument = false } = transformOptions
311+
const { supportsStaticESM, instrument = false } = transformOptions
312312
const constructingCacheKeyElements = [
313313
this._transformCfgStr,
314314
CACHE_KEY_EL_SEPARATOR,
315315
configs.rootDir,
316316
CACHE_KEY_EL_SEPARATOR,
317317
`instrument:${instrument ? 'on' : 'off'}`,
318318
CACHE_KEY_EL_SEPARATOR,
319+
`supportsStaticESM:${supportsStaticESM ? 'on' : 'off'}`,
320+
CACHE_KEY_EL_SEPARATOR,
319321
fileContent,
320322
CACHE_KEY_EL_SEPARATOR,
321323
filePath,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy