Skip to content

Commit

Permalink
Explicitly invalidate cache key when transform options change (#288)
Browse files Browse the repository at this point in the history
* explicitly invalidate cache key when transform options change

* update authors
  • Loading branch information
jwbay authored and kulshekhar committed Aug 5, 2017
1 parent 8368e21 commit 81b5307
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Henry Zektser <japhar81@gmail.com>
Ihor Chulinda <ichulinda@gmail.com>
J Cheyo Jimenez <cheyo@masters3d.com>
Joscha Feth <joscha@feth.com>
Justin Bay <jwbay@users.noreply.github.com>
Kulshekhar Kabra <kulshekhar@users.noreply.github.com>
Kyle Roach <kroach.work@gmail.com>
Marshall Bowers <elliott.codes@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions src/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function getCacheKey(

return crypto.createHash('md5')
.update(JSON.stringify(tsConfig), 'utf8')
.update(JSON.stringify(options), 'utf8')
.update(fileData + filePath + configStr, 'utf8')
.digest('hex');
}
9 changes: 8 additions & 1 deletion tests/__tests__/get-cache-key.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getCacheKey } from '../../src/preprocessor';
import { TransformOptions } from '../../src/jest-types'

describe('getCacheKey', () => {
const src = 'console.log(123);';
Expand All @@ -17,7 +18,8 @@ describe('getCacheKey', () => {
},
"testRegex": "(/__tests__/.*|\\\\.(test|spec))\\\\.(ts|tsx|js)$"
}`;
const originalHash = getCacheKey(src, filepath, configStr);
const options: TransformOptions = { instrument: false };
const originalHash = getCacheKey(src, filepath, configStr, options);

it('should change hash when src changes', () => {
const newSrc = 'console.log(1234);';
Expand All @@ -37,4 +39,9 @@ describe('getCacheKey', () => {
expect(newHash).not.toBe(originalHash);
});

it('should change hash when transform options change', () => {
const newOptions: TransformOptions = { instrument: true };
const newHash = getCacheKey(src, filepath, configStr, newOptions);
expect(newHash).not.toBe(originalHash);
});
});

0 comments on commit 81b5307

Please sign in to comment.