diff --git a/src/ts-jest-transformer.spec.ts b/src/ts-jest-transformer.spec.ts index 21ede97fff..411b352cd2 100644 --- a/src/ts-jest-transformer.spec.ts +++ b/src/ts-jest-transformer.spec.ts @@ -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) }) }) diff --git a/src/ts-jest-transformer.ts b/src/ts-jest-transformer.ts index 8d2153b77a..be690951b2 100644 --- a/src/ts-jest-transformer.ts +++ b/src/ts-jest-transformer.ts @@ -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,