Skip to content

fix: guard sort() with shuffle check so --shuffle is not silently ignored#5639

Merged
DavertMik merged 1 commit into
codeceptjs:4.xfrom
kapil971390:fix/shuffle-overwritten-by-sort-4x
Jun 15, 2026
Merged

fix: guard sort() with shuffle check so --shuffle is not silently ignored#5639
DavertMik merged 1 commit into
codeceptjs:4.xfrom
kapil971390:fix/shuffle-overwritten-by-sort-4x

Conversation

@kapil971390

Copy link
Copy Markdown
Contributor

Fixes #5605

What

run() calls this.testFiles.sort() unconditionally after loadTests() has already applied shuffle() when --shuffle is set. The sort overwrites the randomised order every time, making --shuffle silently have no effect.

// loadTests() — line 217
if (this.opts.shuffle) {
  this.testFiles = shuffle(this.testFiles)  // ✅ shuffled
}

// run() — line 293 (added by #5438)
this.testFiles.sort()  // ❌ always runs — shuffle is lost

Fix

Guard the sort with !this.opts.shuffle:

// Sort alphabetically for consistent order, but preserve shuffle when active.
if (!this.opts.shuffle) {
  this.testFiles.sort()
}

Normal runs continue to get alphabetical order. --shuffle runs now keep their randomised order.

Why this happened

The sort() was introduced in #5438 to fix worker suite distribution — a correct fix for that issue, but it introduced this regression for --shuffle users.

Change

Single guard condition in lib/codecept.js — no other behaviour changed.

…ored

sort() added in codeceptjs#5438 was unconditional — it ran after loadTests() applied
shuffle(), overwriting the randomised order every time. Guard the sort
with !this.opts.shuffle so alphabetical order is used for normal runs
and the shuffled order is preserved when --shuffle is requested.

Fixes codeceptjs#5605
@kapil971390

Copy link
Copy Markdown
Contributor Author

Hi! Could a maintainer approve the workflows to run CI on this? The fix is a single guard condition in lib/codecept.js — happy to answer any questions.

@kapil971390

Copy link
Copy Markdown
Contributor Author

All relevant checks passing. appium failures are pre-existing, saucelabs infrastructure issues, unrelated to this change.

@DavertMik

Copy link
Copy Markdown
Contributor

Thank you for catching it!

@DavertMik DavertMik merged commit 7cb5366 into codeceptjs:4.x Jun 15, 2026
11 of 13 checks passed
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.

bug: --shuffle flag silently ignored after #5438 (sort() in run() overwrites shuffle from loadTests())

3 participants