From 859f4748a1759fb2d75b6354763df3ed5eb985e2 Mon Sep 17 00:00:00 2001 From: Thomas Hohn Date: Fri, 14 Nov 2025 06:48:53 +0100 Subject: [PATCH 1/3] Use own implementation of shuffle to remve lodash.shuffle dependency --- lib/codecept.js | 18 ++++++++++++++++-- package.json | 1 - 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/codecept.js b/lib/codecept.js index dc9c6bd7a..54eafbf30 100644 --- a/lib/codecept.js +++ b/lib/codecept.js @@ -1,6 +1,5 @@ const { existsSync, readFileSync } = require('fs') const { globSync } = require('glob') -const shuffle = require('lodash.shuffle') const fsPath = require('path') const { resolve } = require('path') @@ -186,7 +185,7 @@ class Codecept { } if (this.opts.shuffle) { - this.testFiles = shuffle(this.testFiles) + this.shuffle(this.testFiles) } if (this.opts.shard) { @@ -194,6 +193,21 @@ class Codecept { } } + /** + * Fisher-Yates algorithm for shuffle + */ + shuffle(arrayToShuffle) { + var i = arrayToShuffle.length, + j, + temp + while (--i > 0) { + j = Math.floor(Math.random() * (i + 1)) + temp = arrayToShuffle[j] + arrayToShuffle[j] = arrayToShuffle[i] + arrayToShuffle[i] = temp + } + } + /** * Apply sharding to test files based on shard configuration * diff --git a/package.json b/package.json index 45134ebb4..fd4129816 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,6 @@ "js-beautify": "1.15.4", "lodash.clonedeep": "4.5.0", "lodash.merge": "4.6.2", - "lodash.shuffle": "4.2.0", "mkdirp": "3.0.1", "mocha": "11.7.2", "monocart-coverage-reports": "2.12.9", From ce03607644568e0d3566ab322ef4a0af2fc74a52 Mon Sep 17 00:00:00 2001 From: Thomas Hohn Date: Fri, 14 Nov 2025 07:31:01 +0100 Subject: [PATCH 2/3] Cleanup code --- lib/codecept.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/codecept.js b/lib/codecept.js index 54eafbf30..b412202f7 100644 --- a/lib/codecept.js +++ b/lib/codecept.js @@ -185,7 +185,7 @@ class Codecept { } if (this.opts.shuffle) { - this.shuffle(this.testFiles) + this.testFiles = this.shuffle(this.testFiles) } if (this.opts.shard) { @@ -206,6 +206,8 @@ class Codecept { arrayToShuffle[j] = arrayToShuffle[i] arrayToShuffle[i] = temp } + + return arrayToShuffle } /** From 17b4c98344690399ec0ae764aba3152ed2647ebf Mon Sep 17 00:00:00 2001 From: Thomas Hohn Date: Fri, 14 Nov 2025 10:01:11 +0100 Subject: [PATCH 3/3] After review --- lib/codecept.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/codecept.js b/lib/codecept.js index b412202f7..a115a1e73 100644 --- a/lib/codecept.js +++ b/lib/codecept.js @@ -194,20 +194,15 @@ class Codecept { } /** - * Fisher-Yates algorithm for shuffle + * Fisher–Yates shuffle (non-mutating) */ - shuffle(arrayToShuffle) { - var i = arrayToShuffle.length, - j, - temp - while (--i > 0) { - j = Math.floor(Math.random() * (i + 1)) - temp = arrayToShuffle[j] - arrayToShuffle[j] = arrayToShuffle[i] - arrayToShuffle[i] = temp + shuffle(array) { + const arr = [...array] // clone to avoid mutating input + for (let i = arr.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)) + ;[arr[i], arr[j]] = [arr[j], arr[i]] // swap } - - return arrayToShuffle + return arr } /**