Skip to content

Conversation

JounQin
Copy link
Collaborator

@JounQin JounQin commented Jun 13, 2025

Summary

Follow up #15619 (comment)

packageFilter has been removed with #15619, so related document has just been updated.

Test plan

cc @cpojer @SimenB

Copy link

netlify bot commented Jun 13, 2025

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 37399db
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/684c4470c16010000854f6ed
😎 Deploy Preview https://deploy-preview-15679--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@JounQin JounQin requested review from SimenB, cpojer and Copilot June 13, 2025 15:08
Copilot

This comment was marked as outdated.

Copy link

pkg-pr-new bot commented Jun 13, 2025

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@15679

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@15679

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@15679

create-jest

npm i https://pkg.pr.new/create-jest@15679

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@15679

expect

npm i https://pkg.pr.new/expect@15679

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@15679

jest

npm i https://pkg.pr.new/jest@15679

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@15679

jest-circus

npm i https://pkg.pr.new/jest-circus@15679

jest-cli

npm i https://pkg.pr.new/jest-cli@15679

jest-config

npm i https://pkg.pr.new/jest-config@15679

@jest/console

npm i https://pkg.pr.new/@jest/console@15679

@jest/core

npm i https://pkg.pr.new/@jest/core@15679

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@15679

jest-diff

npm i https://pkg.pr.new/jest-diff@15679

jest-docblock

npm i https://pkg.pr.new/jest-docblock@15679

jest-each

npm i https://pkg.pr.new/jest-each@15679

@jest/environment

npm i https://pkg.pr.new/@jest/environment@15679

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@15679

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@15679

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@15679

@jest/expect

npm i https://pkg.pr.new/@jest/expect@15679

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@15679

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@15679

@jest/globals

npm i https://pkg.pr.new/@jest/globals@15679

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@15679

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@15679

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@15679

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@15679

jest-message-util

npm i https://pkg.pr.new/jest-message-util@15679

jest-mock

npm i https://pkg.pr.new/jest-mock@15679

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@15679

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@15679

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@15679

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@15679

jest-resolve

npm i https://pkg.pr.new/jest-resolve@15679

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@15679

jest-runner

npm i https://pkg.pr.new/jest-runner@15679

jest-runtime

npm i https://pkg.pr.new/jest-runtime@15679

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@15679

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@15679

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@15679

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@15679

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@15679

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@15679

@jest/transform

npm i https://pkg.pr.new/@jest/transform@15679

@jest/types

npm i https://pkg.pr.new/@jest/types@15679

jest-util

npm i https://pkg.pr.new/jest-util@15679

jest-validate

npm i https://pkg.pr.new/jest-validate@15679

jest-watcher

npm i https://pkg.pr.new/jest-watcher@15679

jest-worker

npm i https://pkg.pr.new/jest-worker@15679

pretty-format

npm i https://pkg.pr.new/pretty-format@15679

commit: 37399db

@JounQin JounQin force-pushed the feat/defaultAsyncResolver branch from 7e1a758 to 87874b1 Compare June 13, 2025 15:19
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Could you update the changelog as well?

@JounQin
Copy link
Collaborator Author

JounQin commented Jun 13, 2025

Could you update the changelog as well?

Done!


@SimenB CI is also passing now.

@JounQin JounQin force-pushed the feat/defaultAsyncResolver branch from bfd45e0 to 47d9b5b Compare June 13, 2025 15:24
@JounQin JounQin requested review from SimenB and Copilot June 14, 2025 02:33
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds and wires up an asynchronous version of Jest’s default module resolver across documentation, implementation, tests, snapshots, and the changelog.

  • Introduces defaultAsyncResolver API in the docs and types.
  • Refactors defaultResolver.ts to share logic between sync and async resolver paths.
  • Updates Resolver class, tests, e2e snapshots, and the changelog to incorporate the new async resolver.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
website/versioned_docs/version-30.0/Configuration.md Documented the new defaultAsyncResolver option
packages/jest-resolve/src/resolver.ts Passed defaultAsyncResolver into sync/async flows
packages/jest-resolve/src/defaultResolver.ts Extracted common logic and exported async resolver
packages/jest-resolve/src/tests/resolve.test.ts Imported and asserted presence of the new resolver
e2e/tests/* Updated stack-trace line numbers in snapshots
CHANGELOG.md Logged the feature under [jest-resolver]
Comments suppressed due to low confidence (3)

packages/jest-resolve/src/defaultResolver.ts:97

  • Removing the absolute resolution of basedir may allow relative directories to slip through, potentially breaking resolution. Consider reintroducing basedir = path.resolve(basedir); or validating that options.basedir is always absolute.
// make sure that `basedir` is an absolute path

packages/jest-resolve/src/tests/resolve.test.ts:16

  • We should add direct tests for defaultAsyncResolver to confirm it returns the same results as defaultResolver when resolving valid paths and rejects on missing modules.
import defaultResolver, {defaultAsyncResolver} from '../defaultResolver';

website/versioned_docs/version-30.0/Configuration.md:1499

  • [nitpick] Consider adding a short code snippet showing how to call defaultAsyncResolver within an async custom resolver, mirroring the example for defaultResolver above.
Similarly, the `defaultAsyncResolver` is the default async resolver which takes the same arguments and returns a promise that resolves with a string or rejects with an error.

@cpojer cpojer merged commit 42c8e7d into jestjs:main Jun 14, 2025
76 checks passed
@JounQin JounQin deleted the feat/defaultAsyncResolver branch June 14, 2025 13:38
});
};
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another way to do similar with new resolver:

module.exports = (path, options) => {
  // Call the defaultResolver, so we leverage its cache, error handling, etc.
  return options.defaultResolver(path, {
    ...options,
    // HACK!!!
    // this is option from unrs-resolver from https://github.com/unrs/unrs-resolver?tab=readme-ov-file#main-field
    // unrs-resolver used from jest-resolve now https://github.com/jestjs/jest/blob/v30.0.0/packages/jest-resolve/src/defaultResolver.ts#L84-L98
    // We use the fact that jest-resolve just pass extra options to resolver
    mainFields: ["react-native", "main"],
  });
};

Copy link
Member

@SimenB SimenB Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seems like a very reasonable way of doing it. should be added to the docs 😀

Copy link
Collaborator Author

@JounQin JounQin Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vovkasm Would you like to raise a PR to add it?

@SimenB I'm thinking that we can expose more options from unrs-resolver for example tsconfig or we can also detect tsconfig.json or jsconfig.json automatically, so that paths/references will be supported out of box.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JounQin I'd love to do it. Today or tomorrow!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JounQin see #15687

As for exposing options from unrs-resolver, it seems it is not necessary, interface ResolverOptions already extends UpstreamResolveOptions.

Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants