From f486310031ddc145bf8183dc7c8b32e9a3cfd289 Mon Sep 17 00:00:00 2001 From: unional Date: Tue, 3 Jan 2023 00:53:56 -0800 Subject: [PATCH] fix: rethrow last error Updated changelog and removed copy.mjs --- CHANGELOG.md | 2 +- copy.mjs | 0 packages/jest-resolve/src/defaultResolver.ts | 7 ++++++- 3 files changed, 7 insertions(+), 2 deletions(-) delete mode 100644 copy.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index b5c0e2298881..b433bfc61233 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### Features - `[jest-haste-map]` ignore Sapling vcs directories (`.sl/`) ([#13674](https://github.com/facebook/jest/pull/13674)) -- `[jest-resolve]` Support subpath imports ([#13705](https://github.com/facebook/jest/pull/13705)) +- `[jest-resolve]` Support subpath imports ([#13705](https://github.com/facebook/jest/pull/13705), [#13723](https://github.com/facebook/jest/pull/13723)) - `[jest-runtime]` Add `jest.isolateModulesAsync` for scoped module initialization of asynchronous functions ([#13680](https://github.com/facebook/jest/pull/13680)) - `[jest-test-result]` Added `skipped` and `focused` status to `FormattedTestResult` ([#13700](https://github.com/facebook/jest/pull/13700)) diff --git a/copy.mjs b/copy.mjs deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/packages/jest-resolve/src/defaultResolver.ts b/packages/jest-resolve/src/defaultResolver.ts index 4672c6ce6e41..1ba3bb237cfe 100644 --- a/packages/jest-resolve/src/defaultResolver.ts +++ b/packages/jest-resolve/src/defaultResolver.ts @@ -164,14 +164,19 @@ function resolveByPathInModule( const resolvedValues = Array.isArray(resolved) ? resolved : [resolved]; + let lastError: Error; for (const resolved of resolvedValues) { const resolvedPath = resolveByPath(resolved); + try { return resolveSync(resolvedPath, options); - } catch (e) { + } catch (e: any) { + lastError = e; continue; } } + // eslint-disable-next-line @typescript-eslint/no-throw-literal + throw lastError!; function resolveByPath(resolved: string) { if (resolved.startsWith('.')) {