Skip to content

Commit

Permalink
fix(resolver): resolve mapped paths (#13242)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 10, 2022
1 parent 1a767e0 commit 18ba31f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
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

0 comments on commit 18ba31f

Please sign in to comment.