Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resolver): resolve mapped paths #13242

Merged
merged 2 commits into from Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@
### Fixes

- `[jest-core]` Capture execError during `TestScheduler.scheduleTests` and dispatch to reporters ([#13203](https://github.com/facebook/jest/pull/13203))
- `[jest-resolver]` Make sure to resolve module paths after looking at `exports` ([#13242](https://github.com/facebook/jest/pull/13242))
- `[jest-snapshot]` Fix typings of snapshot matchers ([#13240])(https://github.com/facebook/jest/pull/13240))

### Chore & Maintenance
Expand Down
14 changes: 14 additions & 0 deletions packages/jest-resolve/src/__tests__/resolve.test.ts
Expand Up @@ -220,6 +220,20 @@ describe('findNodeModule', () => {
);
});

test('supports nested paths with wildcard and no extension', () => {
const result = Resolver.findNodeModule('exports/directory/file', {
basedir: conditionsRoot,
conditions: [],
});

expect(result).toEqual(
path.resolve(
conditionsRoot,
'./node_modules/exports/some-other-directory/file.js',
),
);
});

test('supports nested conditions', () => {
const resultRequire = Resolver.findNodeModule('exports/deeplyNested', {
basedir: conditionsRoot,
Expand Down
6 changes: 1 addition & 5 deletions packages/jest-resolve/src/defaultResolver.ts
Expand Up @@ -111,11 +111,7 @@ const defaultResolver: SyncResolver = (path, options) => {

const pathToResolve = getPathInModule(path, resolveOptions);

const result =
// if `getPathInModule` doesn't change the path, attempt to resolve it
pathToResolve === path
? resolveSync(pathToResolve, resolveOptions)
: pathToResolve;
const result = resolveSync(pathToResolve, resolveOptions);

// Dereference symlinks to ensure we don't create a separate
// module instance depending on how it was referenced.
Expand Down