diff --git a/lib/codecept.js b/lib/codecept.js index dc9c6bd7a..a115a1e73 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.testFiles = this.shuffle(this.testFiles) } if (this.opts.shard) { @@ -194,6 +193,18 @@ class Codecept { } } + /** + * Fisher–Yates shuffle (non-mutating) + */ + 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 arr + } + /** * 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",