(files: TestSpecification[])
| 33 | |
| 34 | // async so it can be extended by other sequencers |
| 35 | public async sort(files: TestSpecification[]): Promise<TestSpecification[]> { |
| 36 | const cache = this.ctx.cache |
| 37 | return [...files].sort((a, b) => { |
| 38 | // "sequence.groupOrder" is higher priority |
| 39 | const groupOrderDiff = a.project.config.sequence.groupOrder - b.project.config.sequence.groupOrder |
| 40 | if (groupOrderDiff !== 0) { |
| 41 | return groupOrderDiff |
| 42 | } |
| 43 | |
| 44 | // Projects run sequential |
| 45 | if (a.project.name !== b.project.name) { |
| 46 | return a.project.name < b.project.name ? -1 : 1 |
| 47 | } |
| 48 | |
| 49 | // Isolated run first |
| 50 | if (a.project.config.isolate && !b.project.config.isolate) { |
| 51 | return -1 |
| 52 | } |
| 53 | if (!a.project.config.isolate && b.project.config.isolate) { |
| 54 | return 1 |
| 55 | } |
| 56 | |
| 57 | const keyA = `${a.project.name}:${relative(this.ctx.config.root, a.moduleId)}` |
| 58 | const keyB = `${b.project.name}:${relative(this.ctx.config.root, b.moduleId)}` |
| 59 | |
| 60 | const aState = cache.getFileTestResults(keyA) |
| 61 | const bState = cache.getFileTestResults(keyB) |
| 62 | |
| 63 | if (!aState || !bState) { |
| 64 | const statsA = cache.getFileStats(keyA) |
| 65 | const statsB = cache.getFileStats(keyB) |
| 66 | |
| 67 | // run unknown first |
| 68 | if (!statsA || !statsB) { |
| 69 | return !statsA && statsB ? -1 : !statsB && statsA ? 1 : 0 |
| 70 | } |
| 71 | |
| 72 | // run larger files first |
| 73 | return statsB.size - statsA.size |
| 74 | } |
| 75 | |
| 76 | // run failed first |
| 77 | if (aState.failed && !bState.failed) { |
| 78 | return -1 |
| 79 | } |
| 80 | if (!aState.failed && bState.failed) { |
| 81 | return 1 |
| 82 | } |
| 83 | |
| 84 | // run longer first |
| 85 | return bState.duration - aState.duration |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | // Calculate distributed shard range [start, end] distributed equally |
| 90 | private calculateShardRange(filesCount: number, index: number, count: number): [number, number] { |
no test coverage detected