diff --git a/packages/react-scripts/config/jest/typescriptTransform.js b/packages/react-scripts/config/jest/typescriptTransform.js index 6e6fd0752..5a4da0a6a 100644 --- a/packages/react-scripts/config/jest/typescriptTransform.js +++ b/packages/react-scripts/config/jest/typescriptTransform.js @@ -3,13 +3,15 @@ '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, jsx: tsc.JsxEmit.React, -} +}; if (fs.existsSync(tsconfigPath)) { try { @@ -18,18 +20,32 @@ if (fs.existsSync(tsconfigPath)) { if (tsconfig && tsconfig.compilerOptions) { compilerConfig = tsconfig.compilerOptions; } - } catch (e) { /* Do nothing - default is set */ } + } catch (e) { + /* Do nothing - default is set */ + } } module.exports = { process(src, path) { if (path.endsWith('.ts') || path.endsWith('.tsx')) { - return tsc.transpile( - src, - compilerConfig, - path, [] - ); + return tsc.transpile(src, compilerConfig, path, []); } 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'); + }, };