MCPcopy
hub / github.com/vitest-dev/vitest / shard

Method shard

packages/vitest/src/node/sequencers/BaseSequencer.ts:16–32  ·  view source on GitHub ↗
(files: TestSpecification[])

Source from the content-addressed store, hash-verified

14
15 // async so it can be extended by other sequencers
16 public async shard(files: TestSpecification[]): Promise<TestSpecification[]> {
17 const { config } = this.ctx
18 const { index, count } = config.shard!
19 const [shardStart, shardEnd] = this.calculateShardRange(files.length, index, count)
20 return [...files]
21 .map((spec) => {
22 const fullPath = resolve(slash(config.root), slash(spec.moduleId))
23 const specPath = fullPath?.slice(config.root.length)
24 return {
25 spec,
26 hash: hash('sha1', specPath, 'hex'),
27 }
28 })
29 .sort((a, b) => (a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : 0))
30 .slice(shardStart, shardEnd)
31 .map(({ spec }) => spec)
32 }
33
34 // async so it can be extended by other sequencers
35 public async sort(files: TestSpecification[]): Promise<TestSpecification[]> {

Callers 1

executeTestsFunction · 0.45

Calls 4

calculateShardRangeMethod · 0.95
slashFunction · 0.90
resolveFunction · 0.50
sortMethod · 0.45

Tested by

no test coverage detected