Skip to content

Commit

Permalink
perf: do not hash cache key, jest does it underneath
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Jul 26, 2018
1 parent 5ab100c commit fbe4f1f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
},
"peerDependencies": {
"babel-core": "^7.0.0-0",
"jest": "^23.0.0 || ^24.0.0",
"babel-jest": "^23.0.0",
"jest": "^23.0.0",
"typescript": "2.x"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const TSCONFIG_GLOBALS_KEY = 'ts-jest';
export const PACKAGE_JSON = 'package.json';
export const MY_PACKAGE_CONTENT = readFileSync(
resolve(__dirname, '..', '..', PACKAGE_JSON),
'utf8',
);
1 change: 0 additions & 1 deletion src/utils/get-babel-rc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
PACKAGE_JSON,
BABEL_CONFIG_KEY,
} from './constants';
import { BabelTransformOptions } from '../types';

const babelReaders = [
{
Expand Down
27 changes: 10 additions & 17 deletions src/utils/get-cache-key.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createHash } from 'crypto';
import { JestCacheKeyOptions } from '../types';
import { relative } from 'path';
import { MY_PACKAGE_CONTENT } from './constants';
Expand All @@ -14,20 +13,14 @@ export default function getCacheKey(
const jestConfig: jest.ProjectConfig = JSON.parse(jestConfigString) || {};
delete jestConfig.cacheDirectory;
delete jestConfig.name;
const hash = createHash('md5')
.update(MY_PACKAGE_CONTENT)
.update('\0', 'utf8')
.update(fileData)
.update('\0', 'utf8')
.update(relative(rootDir, filePath))
.update('\0', 'utf8')
.update(jestConfigString)
.update('\0', 'utf8')
.update(JSON.stringify(getTSConfig(jestConfig)))
.update('\0', 'utf8');
const babelRc = getBabelRC(filePath);
if (babelRc) {
hash.update(JSON.stringify(babelRc)).update('\0', 'utf8');
}
return hash.update(instrument ? 'instrument' : '').digest('hex');
// jest creates hash under the hoods
return JSON.stringify([
MY_PACKAGE_CONTENT,
fileData,
relative(rootDir, filePath),
jestConfig,
getTSConfig(jestConfig),
getBabelRC(filePath),
instrument,
]);
}

0 comments on commit fbe4f1f

Please sign in to comment.