Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure test modules can require.resolve absolute paths #11943

Merged
merged 2 commits into from Oct 9, 2021

Conversation

airhorns
Copy link
Contributor

@airhorns airhorns commented Oct 9, 2021

Summary

Before this change, the runtime's require.resolve function would always try to resolve paths relative to the passed paths option. This prevents requiring paths which are absolute! Normal node require.resolve is fine requiring absolute paths, including when passed { paths: [] }, so this updates the jest require algorithm to detect absolute paths and handle them without trying to make the path relative to the passed paths option. This is similar to how node's own require.resolve works, see https://github.com/nodejs/node/blob/05002373176e8758c8c604f06659e171de4ca902/lib/internal/modules/cjs/loader.js#L240-L241

Fixes #11927.

Test plan

The added unit test fails on main and passes on this branch. Woop woop!

@facebook-github-bot
Copy link
Contributor

Hi @airhorns!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@airhorns airhorns force-pushed the absolute-requires-without-paths branch from d2c0c84 to 7ad3de1 Compare October 9, 2021 01:34
@airhorns airhorns changed the title Ensure test modules can require.resolve absolute paths Ensure test modules can require.resolve absolute paths Oct 9, 2021
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Before this change, the runtime's `require.resolve` function would always try to resolve paths relative to the passed `paths` option. This prevents requiring paths which are absolute! Normal node `require.resolve` is fine requiring absolute paths, including when passed `{ paths: [] }`, so this updates the jest require algorithm to detect absolute paths and handle them without trying to make the path relative to the passed `paths` option. This is similar to how node's own require.resolve works, see https://github.com/nodejs/node/blob/05002373176e8758c8c604f06659e171de4ca902/lib/internal/modules/cjs/loader.js#L240-L241

Fixes jestjs#11927.
@airhorns airhorns force-pushed the absolute-requires-without-paths branch from 7ad3de1 to 52bd70f Compare October 9, 2021 02:59
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@codecov-commenter
Copy link

Codecov Report

Merging #11943 (52bd70f) into main (1547740) will increase coverage by 0.00%.
The diff coverage is 50.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #11943   +/-   ##
=======================================
  Coverage   68.75%   68.76%           
=======================================
  Files         322      322           
  Lines       16615    16619    +4     
  Branches     4793     4795    +2     
=======================================
+ Hits        11424    11428    +4     
  Misses       5159     5159           
  Partials       32       32           
Impacted Files Coverage Δ
packages/jest-runtime/src/index.ts 56.64% <50.00%> (+0.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1547740...52bd70f. Read the comment docs.

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.

Great, thanks!

@SimenB SimenB merged commit dd859ac into jestjs:main Oct 9, 2021
@SimenB
Copy link
Member

SimenB commented Oct 17, 2021

https://github.com/facebook/jest/releases/tag/v27.3.0

@github-actions
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 Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: require.resolve with empty paths option does not locate absolute paths
4 participants