File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 11const { existsSync, readFileSync } = require ( 'fs' )
22const { globSync } = require ( 'glob' )
3- const shuffle = require ( 'lodash.shuffle' )
43const fsPath = require ( 'path' )
54const { 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 *
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments