Skip to content

Commit

Permalink
Merge pull request facebook#79 from zinserjan/fix-jest-caching
Browse files Browse the repository at this point in the history
Jest cache busting for ts/tsx files
  • Loading branch information
wmonk authored Jun 23, 2017
2 parents 45b53ce + 0618b12 commit 0b2821f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/react-scripts/config/jest/typescriptTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
'use strict';

const fs = require('fs');
const crypto = require('crypto');
const tsc = require('typescript');
const tsconfigPath = require('app-root-path').resolve('/tsconfig.json');
const THIS_FILE = fs.readFileSync(__filename);

let compilerConfig = {
module: tsc.ModuleKind.CommonJS,
Expand All @@ -30,4 +32,20 @@ module.exports = {
}
return src;
},
getCacheKey(fileData, filePath, configStr, options) {
return crypto
.createHash('md5')
.update(THIS_FILE)
.update('\0', 'utf8')
.update(fileData)
.update('\0', 'utf8')
.update(filePath)
.update('\0', 'utf8')
.update(configStr)
.update('\0', 'utf8')
.update(JSON.stringify(compilerConfig))
.update('\0', 'utf8')
.update(options.instrument ? 'instrument' : '')
.digest('hex');
},
};

0 comments on commit 0b2821f

Please sign in to comment.