Skip to content

Add --randomize flag to randomize test order - #3468

Open
stevenmini2019 wants to merge 1 commit into
avajs:mainfrom
stevenmini2019:randomize-test-runs
Open

Add --randomize flag to randomize test order#3468
stevenmini2019 wants to merge 1 commit into
avajs:mainfrom
stevenmini2019:randomize-test-runs

Conversation

@stevenmini2019

Copy link
Copy Markdown

Summary

Implements seeded randomization of the test run order, resolving #595.

  • New --randomize flag 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 --randomize is 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:

    Randomized test order with seed <seed>. Re-run with --seed <seed> to reproduce the same order.
    
  • .serial tests are unaffected: within-file randomization only reorders concurrent tests, preserving the source order that serial execution relies on.

  • Passing an empty --seed value 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() and testOrderSeed() give file-level and within-file salts so the two shuffle passes are independent.
  • lib/api.js: derives (or accepts) randomSeed when randomize is enabled, shuffles the selected files, and includes randomSeed in the run event.
  • lib/runner.js: shuffles concurrent tests within a file using a file-specific salt.
  • lib/worker/base.js: forwards randomSeed into the worker so the runner can use it.
  • lib/cli.js: adds the --randomize and --seed flags and resolves randomize/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 --seed error.

Notes

  • Default behavior is unchanged: without --randomize, no shuffling occurs and nothing is reported.
  • The same seed always yields the same order across machines and runs.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant