Skip to content

Commit

Permalink
fix: calculated cache key based on supportsStaticESM
Browse files Browse the repository at this point in the history
  • Loading branch information
hnrqer authored and ahnpnl committed Jan 22, 2024
1 parent 2d16f4a commit a5d6f2d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/legacy/ts-jest-transformer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ describe('TsJestTransformer', () => {
...input.transformOptions,
config: { ...input.transformOptions.config, instrument: true },
}),
tr.getCacheKey(input.fileContent, input.fileName, {
...input.transformOptions,
supportsStaticESM: true,
}),
tr.getCacheKey(input.fileContent, input.fileName, {
...input.transformOptions,
config: { ...input.transformOptions.config, rootDir: '/bar' },
Expand Down Expand Up @@ -242,6 +246,27 @@ describe('TsJestTransformer', () => {
expect(cacheKey1).not.toEqual(cacheKey2)
})

test('should be different between supportsStaticESM true and supportsStaticESM false', () => {
jest.spyOn(TsJestCompiler.prototype, 'getResolvedModules').mockReturnValueOnce([])

const cacheKey1 = tr.getCacheKey(input.fileContent, input.fileName, {
...transformOptionsWithCache,
supportsStaticESM: true,
})

jest.spyOn(TsJestCompiler.prototype, 'getResolvedModules').mockReturnValueOnce([])
const tr1 = new TsJestTransformer()
const cacheKey2 = tr1.getCacheKey(input.fileContent, input.fileName, transformOptionsWithCache)

expect(TsJestCompiler.prototype.getResolvedModules).toHaveBeenCalledTimes(1)
expect(TsJestCompiler.prototype.getResolvedModules).toHaveBeenCalledWith(
input.fileContent,
input.fileName,
new Map(),
)
expect(cacheKey1).not.toEqual(cacheKey2)
})

test('should be different with different file content for the same file', () => {
jest.spyOn(TsJestCompiler.prototype, 'getResolvedModules').mockReturnValueOnce([])

Expand Down
4 changes: 3 additions & 1 deletion src/legacy/ts-jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,16 @@ export class TsJestTransformer implements SyncTransformer {
this._logger.debug({ fileName: filePath, transformOptions }, 'computing cache key for', filePath)

// we do not instrument, ensure it is false all the time
const { instrument = false } = transformOptions
const { supportsStaticESM, instrument = false } = transformOptions
const constructingCacheKeyElements = [
this._transformCfgStr,
CACHE_KEY_EL_SEPARATOR,
configs.rootDir,
CACHE_KEY_EL_SEPARATOR,
`instrument:${instrument ? 'on' : 'off'}`,
CACHE_KEY_EL_SEPARATOR,
`supportsStaticESM:${supportsStaticESM ? 'on' : 'off'}`,
CACHE_KEY_EL_SEPARATOR,
fileContent,
CACHE_KEY_EL_SEPARATOR,
filePath,
Expand Down

0 comments on commit a5d6f2d

Please sign in to comment.