Add --randomize flag to randomize test order - #3468
Open
stevenmini2019 wants to merge 1 commit into
Open
Conversation
Implements seeded randomization of the test run order. - New --randomize flag randomizes test file order and concurrent test order within a file. - New --seed <seed> flag reproduces a specific order; a random seed is generated when omitted. - The active seed is reported so a failing order can be reproduced. - .serial tests keep their source order (within-file shuffle only affects concurrent tests). - lib/test-order.js: deterministic Fisher-Yates shuffle (xorshift32 PRNG + FNV-1a seed hash). - Wired into api.js (file order), runner.js (within-file), worker/base.js (seed passthrough), cli.js (flags), reporters/default.js (seed reporting). - Tests added in test/scheduler/test.js.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements seeded randomization of the test run order, resolving #595.
New
--randomizeflag randomizes both the order of test files and the order of concurrent tests within a file.New
--seed <seed>flag reproduces a specific order. When--randomizeis used without--seed, a random 16-character hex seed is generated.The active seed is reported in the run output so a failing order can be reproduced:
.serialtests are unaffected: within-file randomization only reorders concurrent tests, preserving the source order that serial execution relies on.Passing an empty
--seedvalue exits with a clear error.Implementation
lib/test-order.js(new): deterministic Fisher-Yates shuffle backed by an xorshift32 PRNG seeded from an FNV-1a hash of the seed string.fileOrderSeed()andtestOrderSeed()give file-level and within-file salts so the two shuffle passes are independent.lib/api.js: derives (or accepts)randomSeedwhenrandomizeis enabled, shuffles the selected files, and includesrandomSeedin therunevent.lib/runner.js: shuffles concurrent tests within a file using a file-specific salt.lib/worker/base.js: forwardsrandomSeedinto the worker so the runner can use it.lib/cli.js: adds the--randomizeand--seedflags and resolvesrandomize/randomSeed.lib/reporters/default.js: prints the seed line when a run is randomized.test/scheduler/test.js: tests for seed reporting, generated seed, absence without--randomize, and the empty--seederror.Notes
--randomize, no shuffling occurs and nothing is reported.