Skip to content

Conversation

@pmarchini
Copy link
Member

@pmarchini pmarchini commented Feb 8, 2026

This PR adds test-file randomization to the test runner.

--test-randomize executes test files in randomized order, and --test-random-seed=<seed> replays the same order deterministically. When no seed is provided, one is generated and printed to make reproduction straightforward.

@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 93.44262% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.72%. Comparing base (ae2ffce) to head (08db017).
⚠️ Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/test_runner/utils.js 88.40% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61747      +/-   ##
==========================================
- Coverage   89.75%   89.72%   -0.03%     
==========================================
  Files         674      675       +1     
  Lines      204416   204651     +235     
  Branches    39285    39331      +46     
==========================================
+ Hits       183472   183631     +159     
- Misses      13227    13291      +64     
- Partials     7717     7729      +12     
Files with missing lines Coverage Δ
lib/internal/test_runner/runner.js 93.47% <100.00%> (+0.32%) ⬆️
src/node_options.cc 76.47% <100.00%> (+0.19%) ⬆️
src/node_options.h 97.92% <100.00%> (+0.03%) ⬆️
lib/internal/test_runner/utils.js 64.52% <88.40%> (+2.49%) ⬆️

... and 40 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

The value must be an integer between `0` and `4294967295`.

This flag cannot be used with `--watch`.
Copy link
Member

Choose a reason for hiding this comment

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

why?

Copy link
Member Author

Choose a reason for hiding this comment

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

IMHO, there’s little value in randomizing a run while in watch mode.
If you think it could be useful to users, I can follow up by supporting it!

Copy link
Member

Choose a reason for hiding this comment

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

I dont think a lot of value but why is it hard to support?

node --test "**/*.test.js" "**/*.spec.js"
```

### Randomizing test file execution order
Copy link
Member

Choose a reason for hiding this comment

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

Does this have an actual value without randomising the order of the tests themself?

Copy link
Member Author

@pmarchini pmarchini Feb 10, 2026

Choose a reason for hiding this comment

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

We can decide to randomize at the test level!

Do you see this as a blocker?

P.S.: Thinking about it, I agree that randomizing at the test level is also needed, even as part of the initial feature. At this point, it also adds value to allow it during watch mode.

Copy link
Member

Choose a reason for hiding this comment

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

Does this have an actual value without randomising the order of the tests themself?

I agree it would be highly valuable.

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'm gonna push a commit ASAP that introduces it!

const { isTestRunner } = globalOptions;

if (randomize) {
testFiles = shuffleArrayWithSeed(testFiles, randomSeed);
Copy link
Member

Choose a reason for hiding this comment

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

Does this randomize just the execution order or also the output order? I think we want the output order to be consistent?

Copy link
Member Author

Choose a reason for hiding this comment

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

The output order remains consistent with the execution order, so in case of randomization, it reflects the randomized execution sequence.

IMHO, the test stream should always align with the real underlying execution!

Furthermore, in order to keep the original output, the run necessarily has to be completed!

Copy link
Member

Choose a reason for hiding this comment

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

IMHO, the test stream should always align with the real underlying execution!

I agree, thats why I asked


This flag cannot be used with `--watch`.

### `--test-randomize`
Copy link
Member

@MoLow MoLow Feb 10, 2026

Choose a reason for hiding this comment

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

this feature should either be dissallowed when using --test-rerun-failures, or we should somehow save the seed in the rerun state so a rerun will be deterministic.

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.

4 participants