Skip to content

Commit

Permalink
Preserve module identity for symlinks (#4761)
Browse files Browse the repository at this point in the history
* Preserve module identity for symlinks

* Add changelog entry

* Remove unintentional whitespace change

* Revert integration test to undebuggable state
  • Loading branch information
gaearon authored and cpojer committed Oct 25, 2017
1 parent 8c5e870 commit 2890498
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 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-message-util]` Always remove node internals from stacktraces ([#4695](https://github.com/facebook/jest/pull/4695))
* `[jest-resolve]` changes method of determining builtin modules to include missing builtins ([#4740](https://github.com/facebook/jest/pull/4740))
* `[pretty-format]` Prevent error in pretty-format for window in jsdom test env ([#4750](https://github.com/facebook/jest/pull/4750))
* `[jest-resolve]` Preserve module identity for symlinks ([#4761](https://github.com/facebook/jest/pull/4761))

### Features
* `[jest-environment-*]` [**BREAKING**] Add Async Test Environment APIs, dispose is now teardown ([#4506](https://github.com/facebook/jest/pull/4506))
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/resolve/__tests__/resolve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ test('should resolve filename.json', () => {
expect(testRequire('../test4')).not.toThrow();
expect(platform.extension).toBe('json');
});

test('should preserve identity for symlinks', () => {
expect(require('../../../packages/jest-resolve')).toBe(
require('jest-resolve')
);
});
5 changes: 5 additions & 0 deletions packages/jest-resolve/src/default_resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ function resolveSync(target: Path, options: ResolverOptions): Path {
if (isDirectory(dir)) {
result = resolveAsFile(name) || resolveAsDirectory(name);
}
if (result) {
// Dereference symlinks to ensure we don't create a separate
// module instance depending on how it was referenced.
result = fs.realpathSync(result);
}
return result;
}

Expand Down

0 comments on commit 2890498

Please sign in to comment.