From c8c6981266f30b0ee2489ff21a1f803e435f0e06 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 11 Feb 2022 15:26:05 +0100 Subject: [PATCH] fix: correctly resolve remapped directories --- .../conditions/node_modules/exports/package.json | 3 ++- .../exports/some-other-directory/file.js | 0 .../jest-resolve/src/__tests__/resolve.test.ts | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 packages/jest-resolve/src/__mocks__/conditions/node_modules/exports/some-other-directory/file.js diff --git a/packages/jest-resolve/src/__mocks__/conditions/node_modules/exports/package.json b/packages/jest-resolve/src/__mocks__/conditions/node_modules/exports/package.json index 7fd4bab2a661..fc9039934b2c 100644 --- a/packages/jest-resolve/src/__mocks__/conditions/node_modules/exports/package.json +++ b/packages/jest-resolve/src/__mocks__/conditions/node_modules/exports/package.json @@ -11,6 +11,7 @@ "./deeplyNested" : { "require": "./nestedRequire.js", "default": "./nestedDefault.js" - } + }, + "./directory/*": "./some-other-directory/*" } } diff --git a/packages/jest-resolve/src/__mocks__/conditions/node_modules/exports/some-other-directory/file.js b/packages/jest-resolve/src/__mocks__/conditions/node_modules/exports/some-other-directory/file.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-resolve/src/__tests__/resolve.test.ts b/packages/jest-resolve/src/__tests__/resolve.test.ts index 6c6dfaf0705e..4d0b1af072a6 100644 --- a/packages/jest-resolve/src/__tests__/resolve.test.ts +++ b/packages/jest-resolve/src/__tests__/resolve.test.ts @@ -234,6 +234,20 @@ describe('findNodeModule', () => { path.resolve(conditionsRoot, './node_modules/exports/nestedDefault.js'), ); }); + + test('supports separate directory path', () => { + const result = Resolver.findNodeModule('exports/directory/file.js', { + basedir: conditionsRoot, + conditions: [], + }); + + expect(result).toEqual( + path.resolve( + conditionsRoot, + './node_modules/exports/some-other-directory/file.js', + ), + ); + }); }); });