* 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)
| 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. |
no outgoing calls
no test coverage detected