MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / _applySharding

Method _applySharding

lib/codecept.js:233–260  ·  view source on GitHub ↗

* Apply sharding to test files based on shard configuration * * @param {Array } testFiles - Array of test file paths * @param {string} shardConfig - Shard configuration in format "index/total" (e.g., "1/4") * @returns {Array } - Filtered array of test files for this shard

(testFiles, shardConfig)

Source from the content-addressed store, hash-verified

231 * @returns {Array<string>} - Filtered array of test files for this shard
232 */
233 _applySharding(testFiles, shardConfig) {
234 const shardMatch = shardConfig.match(/^(\d+)\/(\d+)$/)
235 if (!shardMatch) {
236 throw new Error('Invalid shard format. Expected format: "index/total" (e.g., "1/4")')
237 }
238
239 const shardIndex = parseInt(shardMatch[1], 10)
240 const shardTotal = parseInt(shardMatch[2], 10)
241
242 if (shardTotal < 1) {
243 throw new Error('Shard total must be at least 1')
244 }
245
246 if (shardIndex < 1 || shardIndex > shardTotal) {
247 throw new Error(`Shard index ${shardIndex} must be between 1 and ${shardTotal}`)
248 }
249
250 if (testFiles.length === 0) {
251 return testFiles
252 }
253
254 // Calculate which tests belong to this shard
255 const shardSize = Math.ceil(testFiles.length / shardTotal)
256 const startIndex = (shardIndex - 1) * shardSize
257 const endIndex = Math.min(startIndex + shardSize, testFiles.length)
258
259 return testFiles.slice(startIndex, endIndex)
260 }
261
262 /**
263 * Run a specific test or all loaded tests.

Callers 3

loadTestsMethod · 0.95
shard_test.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected