Skip to content

Commit

Permalink
Remove redundant information from the config hash part of the haste m…
Browse files Browse the repository at this point in the history
…ap filename
  • Loading branch information
rubennorte committed Oct 19, 2018
1 parent 22f67d4 commit e712705
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- `[jest-runtime]` If `require` fails without a file extension, print all files that match with one ([#7160](https://github.com/facebook/jest/pull/7160))
- `[jest-haste-map]` Make `ignorePattern` optional ([#7166](https://github.com/facebook/jest/pull/7166))
- `[jest-haste-map]` Add `getCacheFilePath` to get the path to the cache file for a `HasteMap` instance ([#7217](https://github.com/facebook/jest/pull/7217))
- `[jest-haste-map]` [**BREAKING**] Remove name from hash in `HasteMap.getCacheFilePath` ([#7218](https://github.com/facebook/jest/pull/7218))
- `[jest-runtime]` Remove `cacheDirectory` from `ignorePattern` for `HasteMap` if not necessary ([#7166](https://github.com/facebook/jest/pull/7166))
- `[jest-validate]` Add syntax to validate multiple permitted types ([#7207](https://github.com/facebook/jest/pull/7207))

Expand Down
26 changes: 22 additions & 4 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,30 @@ describe('HasteMap', () => {
expect(
HasteMap.getCacheFilePath('/', '@scoped/package', 'random-value'),
).toMatch(/^\/-scoped-package-(.*)$/);
});

expect(
HasteMap.getCacheFilePath('/', '@scoped/package', 'random-value'),
).not.toEqual(
HasteMap.getCacheFilePath('/', '-scoped-package', 'random-value'),
it('creates different cache file paths for different roots', () => {
jest.resetModuleRegistry();
const HasteMap = require('../');
const hasteMap1 = new HasteMap(
Object.assign({}, defaultConfig, {rootDir: '/root1'}),
);
const hasteMap2 = new HasteMap(
Object.assign({}, defaultConfig, {rootDir: '/root2'}),
);
expect(hasteMap1.getCacheFilePath()).not.toBe(hasteMap2.getCacheFilePath());
});

it('creates different cache file paths for different project names', () => {
jest.resetModuleRegistry();
const HasteMap = require('../');
const hasteMap1 = new HasteMap(
Object.assign({}, defaultConfig, {name: '@scoped/package'}),
);
const hasteMap2 = new HasteMap(
Object.assign({}, defaultConfig, {name: '-scoped-package'}),
);
expect(hasteMap1.getCacheFilePath()).not.toBe(hasteMap2.getCacheFilePath());
});

it('matches files against a pattern', () =>
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-haste-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class HasteMap extends EventEmitter {
this._options.cacheDirectory,
`haste-map-${this._options.name}-${rootDirHash}`,
VERSION,
this._options.name,
this._options.roots
.map(root => fastPath.relative(options.rootDir, root))
.join(':'),
Expand All @@ -283,7 +284,7 @@ class HasteMap extends EventEmitter {
name: string,
...extra: Array<string>
): string {
const hash = crypto.createHash('md5').update(name + extra.join(''));
const hash = crypto.createHash('md5').update(extra.join(''));
return path.join(
tmpdir,
name.replace(/\W/g, '-') + '-' + hash.digest('hex'),
Expand Down

0 comments on commit e712705

Please sign in to comment.