Skip to content

Commit fbe4f1f

Browse files
committedJul 26, 2018
perf: do not hash cache key, jest does it underneath
1 parent 5ab100c commit fbe4f1f

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed
 

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
},
7979
"peerDependencies": {
8080
"babel-core": "^7.0.0-0",
81-
"jest": "^23.0.0 || ^24.0.0",
81+
"babel-jest": "^23.0.0",
82+
"jest": "^23.0.0",
8283
"typescript": "2.x"
8384
},
8485
"devDependencies": {

‎src/utils/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const TSCONFIG_GLOBALS_KEY = 'ts-jest';
99
export const PACKAGE_JSON = 'package.json';
1010
export const MY_PACKAGE_CONTENT = readFileSync(
1111
resolve(__dirname, '..', '..', PACKAGE_JSON),
12+
'utf8',
1213
);

‎src/utils/get-babel-rc.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
PACKAGE_JSON,
77
BABEL_CONFIG_KEY,
88
} from './constants';
9-
import { BabelTransformOptions } from '../types';
109

1110
const babelReaders = [
1211
{

‎src/utils/get-cache-key.ts

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createHash } from 'crypto';
21
import { JestCacheKeyOptions } from '../types';
32
import { relative } from 'path';
43
import { MY_PACKAGE_CONTENT } from './constants';
@@ -14,20 +13,14 @@ export default function getCacheKey(
1413
const jestConfig: jest.ProjectConfig = JSON.parse(jestConfigString) || {};
1514
delete jestConfig.cacheDirectory;
1615
delete jestConfig.name;
17-
const hash = createHash('md5')
18-
.update(MY_PACKAGE_CONTENT)
19-
.update('\0', 'utf8')
20-
.update(fileData)
21-
.update('\0', 'utf8')
22-
.update(relative(rootDir, filePath))
23-
.update('\0', 'utf8')
24-
.update(jestConfigString)
25-
.update('\0', 'utf8')
26-
.update(JSON.stringify(getTSConfig(jestConfig)))
27-
.update('\0', 'utf8');
28-
const babelRc = getBabelRC(filePath);
29-
if (babelRc) {
30-
hash.update(JSON.stringify(babelRc)).update('\0', 'utf8');
31-
}
32-
return hash.update(instrument ? 'instrument' : '').digest('hex');
16+
// jest creates hash under the hoods
17+
return JSON.stringify([
18+
MY_PACKAGE_CONTENT,
19+
fileData,
20+
relative(rootDir, filePath),
21+
jestConfig,
22+
getTSConfig(jestConfig),
23+
getBabelRC(filePath),
24+
instrument,
25+
]);
3326
}

0 commit comments

Comments
 (0)
Please sign in to comment.