Skip to content

Commit 70e1867

Browse files
committed
fix(cache): includes all parameters in cache key computing
1 parent 5fb876e commit 70e1867

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/ts-jest-transformer.spec.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,20 @@ describe('getCacheKey', () => {
112112
fileContent: 'export default "foo"',
113113
fileName: 'foo.ts',
114114
jestConfigStr: '{"foo": "bar"}',
115+
options: { instrument: false, rootDir: '/foo' },
115116
}
116-
const key1 = tr.getCacheKey(input.fileContent, input.fileName, input.jestConfigStr)
117-
const key2 = tr.getCacheKey(input.fileContent, 'bar.ts', input.jestConfigStr)
118-
const key3 = tr.getCacheKey(input.fileContent, input.fileName, '{}')
119-
expect(key2).not.toBe(key1)
120-
expect(key3).not.toBe(key1)
121-
expect(key3).not.toBe(key2)
117+
const keys = [
118+
tr.getCacheKey(input.fileContent, input.fileName, input.jestConfigStr, input.options),
119+
tr.getCacheKey(input.fileContent, 'bar.ts', input.jestConfigStr, input.options),
120+
tr.getCacheKey(input.fileContent, input.fileName, '{}', input.options),
121+
tr.getCacheKey(input.fileContent, input.fileName, '{}', { ...input.options, instrument: true }),
122+
tr.getCacheKey(input.fileContent, input.fileName, '{}', { ...input.options, rootDir: '/bar' }),
123+
]
124+
// each key should have correct length
125+
for (const key of keys) {
126+
expect(key).toHaveLength(40)
127+
}
128+
// unique array should have same length
129+
expect(keys.filter((k, i, all) => all.indexOf(k) === i)).toHaveLength(keys.length)
122130
})
123131
})

src/ts-jest-transformer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,12 @@ export class TsJestTransformer implements jest.Transformer {
143143
this.logger.debug({ fileName: filePath, transformOptions }, 'computing cache key for', filePath)
144144
const configs = this.configsFor(jestConfigStr)
145145
// we do not instrument, ensure it is false all the time
146-
// const { instrument = false } = transformOptions
147-
const instrument = false
146+
const { instrument = false, rootDir = configs.rootDir } = transformOptions
148147
return sha1(
149148
configs.cacheKey,
150149
'\x00',
150+
rootDir,
151+
'\x00',
151152
`instrument:${instrument ? 'on' : 'off'}`,
152153
'\x00',
153154
fileContent,

0 commit comments

Comments
 (0)