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: calculated cache key based on supportsStaticESM #4248

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading