Skip to content

Commit 859f474

Browse files
committed
Use own implementation of shuffle to remve lodash.shuffle dependency
1 parent 5ac9fb5 commit 859f474

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/codecept.js

Lines changed: 16 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,29 @@ class Codecept {
186185
}
187186

188187
if (this.opts.shuffle) {
189-
this.testFiles = shuffle(this.testFiles)
188+
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 algorithm for shuffle
198+
*/
199+
shuffle(arrayToShuffle) {
200+
var i = arrayToShuffle.length,
201+
j,
202+
temp
203+
while (--i > 0) {
204+
j = Math.floor(Math.random() * (i + 1))
205+
temp = arrayToShuffle[j]
206+
arrayToShuffle[j] = arrayToShuffle[i]
207+
arrayToShuffle[i] = temp
208+
}
209+
}
210+
197211
/**
198212
* Apply sharding to test files based on shard configuration
199213
*

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)