From 1741e46a36eb52f0acca627bdde8bd7389f20c89 Mon Sep 17 00:00:00 2001 From: kapilvus Date: Mon, 15 Jun 2026 19:33:18 +0530 Subject: [PATCH] fix: guard sort() with shuffle check so --shuffle is not silently ignored MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sort() added in #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 #5605 --- lib/codecept.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/codecept.js b/lib/codecept.js index 3efbab82d..4c28afc6d 100644 --- a/lib/codecept.js +++ b/lib/codecept.js @@ -289,8 +289,11 @@ class Codecept { // Ignore if gherkin module not available } - // Sort test files alphabetically for consistent execution order - this.testFiles.sort() + // Sort test files alphabetically for consistent execution order, + // but skip sorting when --shuffle is active so the randomised order is preserved. + if (!this.opts.shuffle) { + this.testFiles.sort() + } return new Promise((resolve, reject) => { const mocha = container.mocha()