Skip to content

Commit

Permalink
fix(cache): includes all parameters in cache key computing
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Sep 12, 2018
1 parent 5fb876e commit 70e1867
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/ts-jest-transformer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,20 @@ describe('getCacheKey', () => {
fileContent: 'export default "foo"',
fileName: 'foo.ts',
jestConfigStr: '{"foo": "bar"}',
options: { instrument: false, rootDir: '/foo' },
}
const key1 = tr.getCacheKey(input.fileContent, input.fileName, input.jestConfigStr)
const key2 = tr.getCacheKey(input.fileContent, 'bar.ts', input.jestConfigStr)
const key3 = tr.getCacheKey(input.fileContent, input.fileName, '{}')
expect(key2).not.toBe(key1)
expect(key3).not.toBe(key1)
expect(key3).not.toBe(key2)
const keys = [
tr.getCacheKey(input.fileContent, input.fileName, input.jestConfigStr, input.options),
tr.getCacheKey(input.fileContent, 'bar.ts', input.jestConfigStr, input.options),
tr.getCacheKey(input.fileContent, input.fileName, '{}', input.options),
tr.getCacheKey(input.fileContent, input.fileName, '{}', { ...input.options, instrument: true }),
tr.getCacheKey(input.fileContent, input.fileName, '{}', { ...input.options, rootDir: '/bar' }),
]
// each key should have correct length
for (const key of keys) {
expect(key).toHaveLength(40)
}
// unique array should have same length
expect(keys.filter((k, i, all) => all.indexOf(k) === i)).toHaveLength(keys.length)
})
})
5 changes: 3 additions & 2 deletions src/ts-jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ export class TsJestTransformer implements jest.Transformer {
this.logger.debug({ fileName: filePath, transformOptions }, 'computing cache key for', filePath)
const configs = this.configsFor(jestConfigStr)
// we do not instrument, ensure it is false all the time
// const { instrument = false } = transformOptions
const instrument = false
const { instrument = false, rootDir = configs.rootDir } = transformOptions
return sha1(
configs.cacheKey,
'\x00',
rootDir,
'\x00',
`instrument:${instrument ? 'on' : 'off'}`,
'\x00',
fileContent,
Expand Down

0 comments on commit 70e1867

Please sign in to comment.