diff --git a/CHANGELOG.md b/CHANGELOG.md index 975c3f3f4c36..88fb28751656 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/jest-resolve/src/__tests__/resolve.test.ts b/packages/jest-resolve/src/__tests__/resolve.test.ts index eb6d3c3cd7d3..4a84b71aa218 100644 --- a/packages/jest-resolve/src/__tests__/resolve.test.ts +++ b/packages/jest-resolve/src/__tests__/resolve.test.ts @@ -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, diff --git a/packages/jest-resolve/src/defaultResolver.ts b/packages/jest-resolve/src/defaultResolver.ts index c785c055f998..03be868ebc1a 100644 --- a/packages/jest-resolve/src/defaultResolver.ts +++ b/packages/jest-resolve/src/defaultResolver.ts @@ -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.