Skip to content

test_runner: support test order randomization#61747

Open
pmarchini wants to merge 5 commits intonodejs:mainfrom
pmarchini:test_runner/deterministic-test-randomizer
Open

test_runner: support test order randomization#61747
pmarchini wants to merge 5 commits intonodejs:mainfrom
pmarchini:test_runner/deterministic-test-randomizer

Conversation

@pmarchini
Copy link
Member

@pmarchini pmarchini commented Feb 8, 2026

This PR adds deterministic randomization to the Node.js test runner at both levels:

  • test file execution order
  • the order of tests inside each file

--test-randomize enables randomized execution, and --test-random-seed=<seed> replays the same order deterministically (and implicitly enables randomization).
When no seed is provided, one is generated and printed in the summary so runs are easy to reproduce.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Feb 8, 2026
@pmarchini pmarchini force-pushed the test_runner/deterministic-test-randomizer branch 2 times, most recently from 5556788 to e6f9a59 Compare February 8, 2026 22:20
@pmarchini pmarchini added test_runner Issues and PRs related to the test runner subsystem. semver-minor PRs that contain new features and should be released in the next minor version. labels Feb 8, 2026
@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

❌ Patch coverage is 91.98113% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.66%. Comparing base (4d0cb65) to head (cd9a8ee).
⚠️ Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/test_runner/utils.js 75.36% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61747      +/-   ##
==========================================
- Coverage   91.63%   89.66%   -1.97%     
==========================================
  Files         337      676     +339     
  Lines      140376   206533   +66157     
  Branches    21768    39554   +17786     
==========================================
+ Hits       128627   185180   +56553     
- Misses      11527    13499    +1972     
- Partials      222     7854    +7632     
Files with missing lines Coverage Δ
lib/internal/test_runner/runner.js 93.65% <100.00%> (+0.76%) ⬆️
lib/internal/test_runner/test.js 96.91% <100.00%> (+0.16%) ⬆️
src/node_options.cc 76.44% <100.00%> (ø)
src/node_options.h 97.96% <100.00%> (ø)
lib/internal/test_runner/utils.js 63.28% <75.36%> (+1.26%) ⬆️

... and 457 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 force-pushed the test_runner/deterministic-test-randomizer branch from e6f9a59 to b3b2388 Compare February 9, 2026 08:09
@pmarchini pmarchini marked this pull request as draft February 9, 2026 08:42
@pmarchini pmarchini force-pushed the test_runner/deterministic-test-randomizer branch from b3b2388 to 08db017 Compare February 9, 2026 09:19
@pmarchini pmarchini marked this pull request as ready for review February 9, 2026 09:19
@pmarchini pmarchini force-pushed the test_runner/deterministic-test-randomizer branch 2 times, most recently from 08db017 to 4d626b6 Compare February 10, 2026 22:16
@nodejs-github-bot
Copy link
Collaborator

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.

🙌

I see I'm late to the party. None of my comments are pressing :)

```

Using suite-style APIs such as `describe()`/`it()` or `suite()`/`test()`
still allows randomization, because sibling tests are queued together.
Copy link
Member

Choose a reason for hiding this comment

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

nit: I thiiink it should be "enqueued"? "queued" together means they wait together; enqueued together means they're added to a queue one-by-one setting up a sequence.

@@ -191,6 +198,12 @@ function getRunArgs(path, { forceExit,
if (rerunFailuresFilePath) {
ArrayPrototypePush(runArgs, `--test-rerun-failures=${rerunFailuresFilePath}`);
}
if (randomize === true) {
Copy link
Member

Choose a reason for hiding this comment

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

Related to the skip and todo discussion: should this check truthiness rather than strict?

@JakobJingleheimer
Copy link
Member

@nodejs-github-bot
Copy link
Collaborator

@JakobJingleheimer JakobJingleheimer added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Feb 23, 2026
@pmarchini pmarchini force-pushed the test_runner/deterministic-test-randomizer branch from 84b6260 to d013ca5 Compare March 1, 2026 15:56
@pmarchini pmarchini added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 1, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 2, 2026
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@pmarchini pmarchini removed 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 Mar 2, 2026
Comment on lines +6 to +15
✔ describe-it 1-1-1 (*ms)
✔ describe-it 1-1-3 (*ms)
✔ describe-it 1-1-2 (*ms)
✔ describe-it 1-1 (*ms)
▶ describe-it 1-3
✔ describe-it 1-3-1 (*ms)
✔ describe-it 1-3-3 (*ms)
✔ describe-it 1-3-2 (*ms)
✔ describe-it 1-3 (*ms)
▶ describe-it 1-2
Copy link
Member Author

@pmarchini pmarchini Mar 2, 2026

Choose a reason for hiding this comment

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

Checking the pattern I've noticed that the first test is always executed before the shuffle.
A fix is coming!

thanks @hiimjako

Copy link
Contributor

@Ethan-Arrowood Ethan-Arrowood left a comment

Choose a reason for hiding this comment

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

lgtm - there is a lint failure and I have some docs edits but wouldn't consider them blocking

enable this mode.

```bash
node --test --test-randomize
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this is valid? I thought everything after the --test is considered as an entry path?

so `--test-randomize` is optional when a seed is provided:

```bash
node --test --test-randomize --test-random-seed=12345
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
node --test --test-randomize --test-random-seed=12345
node --test --test-random-seed=12345

Copy link
Contributor

Choose a reason for hiding this comment

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

this change is in reference to the previous line of text that states the --test-randomize is not needed when --test-random-seed is provided.

* `randomize` {boolean} Randomize execution order for test files and queued tests.
This option is not supported with `watch: true`.
**Default:** `false`.
* `randomSeed` {number} Seed used when randomizing execution order. If this
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets mention the 0 to 2^32 - 1 limit here.

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants