Skip to content

Commit f052b1a

Browse files
authored
Use own implementation of shuffle to remve lodash.shuffle dependency (#5301)
* Use own implementation of shuffle to remve lodash.shuffle dependency * Cleanup code * After review
1 parent 5ac9fb5 commit f052b1a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/codecept.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { existsSync, readFileSync } = require('fs')
22
const { globSync } = require('glob')
3-
const shuffle = require('lodash.shuffle')
43
const fsPath = require('path')
54
const { resolve } = require('path')
65

@@ -186,14 +185,26 @@ class Codecept {
186185
}
187186

188187
if (this.opts.shuffle) {
189-
this.testFiles = shuffle(this.testFiles)
188+
this.testFiles = this.shuffle(this.testFiles)
190189
}
191190

192191
if (this.opts.shard) {
193192
this.testFiles = this._applySharding(this.testFiles, this.opts.shard)
194193
}
195194
}
196195

196+
/**
197+
* Fisher–Yates shuffle (non-mutating)
198+
*/
199+
shuffle(array) {
200+
const arr = [...array] // clone to avoid mutating input
201+
for (let i = arr.length - 1; i > 0; i--) {
202+
const j = Math.floor(Math.random() * (i + 1))
203+
;[arr[i], arr[j]] = [arr[j], arr[i]] // swap
204+
}
205+
return arr
206+
}
207+
197208
/**
198209
* Apply sharding to test files based on shard configuration
199210
*

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
"js-beautify": "1.15.4",
114114
"lodash.clonedeep": "4.5.0",
115115
"lodash.merge": "4.6.2",
116-
"lodash.shuffle": "4.2.0",
117116
"mkdirp": "3.0.1",
118117
"mocha": "11.7.2",
119118
"monocart-coverage-reports": "2.12.9",

0 commit comments

Comments
 (0)