/
shard-test.test.ts
50 lines (36 loc) · 1.18 KB
/
shard-test.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { expect, test } from 'vitest'
import { basename } from 'pathe'
import { execa } from 'execa'
const runVitest = async (args: string[]) => {
const { stdout } = await execa('vitest', ['--run', '--dir', './test', ...args])
return stdout
}
const parsePaths = (stdout: string) => {
return Array.from(new Set(stdout
.split('\n')
.filter(line => line && line.includes('.test.js'))
.map(file => basename(file.trim().split(' ')[1]))
.sort()))
}
test('--shard=1/1', async () => {
const stdout = await runVitest(['--shard=1/1'])
const paths = parsePaths(stdout)
expect(paths).toEqual(['1.test.js', '2.test.js', '3.test.js'])
})
test('--shard=1/2', async () => {
const stdout = await runVitest(['--shard=1/2'])
const paths = parsePaths(stdout)
expect(paths).toEqual(['1.test.js', '2.test.js'])
})
test('--shard=2/2', async () => {
const stdout = await runVitest(['--shard=2/2'])
const paths = parsePaths(stdout)
expect(paths).toEqual(['3.test.js'])
})
test('--shard=4/4', async () => {
const stdout = await runVitest(['--shard=4/4'])
const paths = parsePaths(stdout)
// project only has 3 files
// shards > 3 are empty
expect(paths).toEqual([])
})