Skip to content

Conversation

@pmarchini
Copy link
Member

I'm opening this PR as a draft to discuss the implementation.
The goal is to address issue #57728.
This PR unifies the behaviour of --require and --import for the specific case where the test runner is run with isolation none.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. test_runner Issues and PRs related to the test runner subsystem. labels Apr 18, 2025
@pmarchini pmarchini force-pushed the test_runner/fix/57728 branch from 599cf81 to f9472b6 Compare April 18, 2025 13:47
Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up!

Comment on lines 771 to 774
const userModules = [
...getOptionValue('--require'),
...getOptionValue('--import'),
];
Copy link
Member

Choose a reason for hiding this comment

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

I think the approach here is logical in terms of steps. But 2 caveats:

  • CascadedLoader (aka ESMLoader aka ModuleLoader) does not handle CJS modules exactly the same as CJSLoader; if we're in ESM mode, this is "correct" (ESMLoader should handle it); but if not ESM mode, for good or ill, it could lead to unexpected behaviour.
  • Does this prevent the --required module(s) executing prior to this? If not, they could be stateful or something else crazy which would get lost when the clone gets created here.
Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your review, @JakobJingleheimer 🚀

Regarding nr1: ok! I suspected that. I'll take a look to understand if we can just use the default method we're using for --require in the "default" entry point.

nr2: Yes, it prevents the default handling of --require from happening, it's now being executed only at this point!

Copy link
Member

Choose a reason for hiding this comment

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

W00t!

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the logic to use loadPreloadModules and applied the other suggestions.
Before marking this PR as "ready to be reviewed", I'd like to ask you to take another look at these changes 😁

@pmarchini pmarchini force-pushed the test_runner/fix/57728 branch from f9472b6 to a2134be Compare April 24, 2025 05:34
@pmarchini pmarchini marked this pull request as ready for review April 25, 2025 16:35
@codecov
Copy link

codecov bot commented Apr 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.19%. Comparing base (52d95f5) to head (b866b7e).
⚠️ Report is 1091 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@ ## main #57924 +/- ## ========================================== - Coverage 90.26% 90.19% -0.07%  ========================================== Files 630 630 Lines 185933 186470 +537 Branches 36450 36624 +174 ========================================== + Hits 167829 168186 +357  - Misses 10972 11061 +89  - Partials 7132 7223 +91 
Files with missing lines Coverage Δ
lib/internal/main/test_runner.js 100.00% <100.00%> (ø)
lib/internal/process/pre_execution.js 94.91% <100.00%> (-1.05%) ⬇️
lib/internal/test_runner/runner.js 89.03% <100.00%> (+0.15%) ⬆️

... and 71 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@pmarchini pmarchini added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 30, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 30, 2025
@pmarchini pmarchini requested a review from atlowChemi May 2, 2025 08:06
@pmarchini pmarchini added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels May 2, 2025
@pmarchini pmarchini added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels May 4, 2025
@jakecastelli jakecastelli added the commit-queue Add this label to land a pull request using GitHub Actions. label May 6, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 6, 2025
@nodejs-github-bot nodejs-github-bot merged commit 7e24ebc into nodejs:main May 6, 2025
68 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 7e24ebc

targos pushed a commit that referenced this pull request May 16, 2025
PR-URL: #57924 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
@richardlau richardlau added the backport-requested-v22.x PRs awaiting manual backport to the v22.x-staging branch. label Sep 19, 2025
@richardlau
Copy link
Member

This doesn't land cleanly on v22.x-staging so a manual backport will be necessary if this is to be released there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-requested-v22.x PRs awaiting manual backport to the v22.x-staging branch. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. test_runner Issues and PRs related to the test runner subsystem.

7 participants