Skip to content

Commit 0b2821f

Browse files
authored
Merge pull request facebook#79 from zinserjan/fix-jest-caching
Jest cache busting for ts/tsx files
2 parents 45b53ce + 0618b12 commit 0b2821f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/react-scripts/config/jest/typescriptTransform.js

+18
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
'use strict';
44

55
const fs = require('fs');
6+
const crypto = require('crypto');
67
const tsc = require('typescript');
78
const tsconfigPath = require('app-root-path').resolve('/tsconfig.json');
9+
const THIS_FILE = fs.readFileSync(__filename);
810

911
let compilerConfig = {
1012
module: tsc.ModuleKind.CommonJS,
@@ -30,4 +32,20 @@ module.exports = {
3032
}
3133
return src;
3234
},
35+
getCacheKey(fileData, filePath, configStr, options) {
36+
return crypto
37+
.createHash('md5')
38+
.update(THIS_FILE)
39+
.update('\0', 'utf8')
40+
.update(fileData)
41+
.update('\0', 'utf8')
42+
.update(filePath)
43+
.update('\0', 'utf8')
44+
.update(configStr)
45+
.update('\0', 'utf8')
46+
.update(JSON.stringify(compilerConfig))
47+
.update('\0', 'utf8')
48+
.update(options.instrument ? 'instrument' : '')
49+
.digest('hex');
50+
},
3351
};

0 commit comments

Comments
 (0)