-
Notifications
You must be signed in to change notification settings - Fork 86
/
vitest.config.ts
82 lines (73 loc) · 2.51 KB
/
vitest.config.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { join, relative } from 'node:path'
import { defineConfig } from 'vitest/config'
import { BaseSequencer, WorkspaceSpec } from 'vitest/node'
/**
* Tests that might influence others and should run on an isolated executor (shard)
* Needs to be relative paths to the repository root.
*/
const RUN_ISOLATED = new Set([
join('tests', 'integration', 'fetch-handler.test.ts'),
join('tests', 'integration', 'revalidate-path.test.ts'),
join('tests', 'integration', 'cache-handler.test.ts'),
join('tests', 'integration', 'edge-handler.test.ts'),
])
class Sequencer extends BaseSequencer {
async shard(projects: WorkspaceSpec[]): Promise<WorkspaceSpec[]> {
const {
config: { shard: { index = 1, count = 1 } = {} },
} = this.ctx
if (count === 1) {
console.log('[Sequencer]: No test sharding configured please specify with --shard 1/3')
return projects
}
console.log(`[Sequencer]: Sharding configured to run on ${index}/${count}`)
if (RUN_ISOLATED.size + 1 > count) {
throw new Error(
`[Sequencer]: The number of special tests + 1 for the remaining tests (${RUN_ISOLATED.size}) is larger than the node count (${count})
Increasing the node count of the sharding to --shard 1/${RUN_ISOLATED.size}`,
)
}
const specialTests = projects.filter((project) =>
RUN_ISOLATED.has(relative(process.cwd(), project[1])),
)
const regularTests = projects.filter(
(project) => !RUN_ISOLATED.has(relative(process.cwd(), project[1])),
)
// Allocate the first nodes for special tests
if (index <= specialTests.length) {
return [specialTests[index - 1]]
}
// Distribute remaining tests on the remaining nodes
if (index > specialTests.length && index <= count) {
const remainingNodes = count - specialTests.length
const bucketSize = Math.ceil(regularTests.length / remainingNodes)
const startIndex = (index - specialTests.length - 1) * bucketSize
const endIndex = startIndex + bucketSize
return regularTests.slice(startIndex, endIndex)
}
return projects
}
}
export default defineConfig({
root: '.',
test: {
include: [],
globals: true,
restoreMocks: true,
clearMocks: true,
mockReset: true,
unstubEnvs: true,
unstubGlobals: true,
environment: 'node',
testTimeout: 100_000,
setupFiles: ['tests/test-setup.ts'],
logHeapUsage: true,
hookTimeout: 50_000,
sequence: {
sequencer: Sequencer,
},
},
esbuild: {
include: ['**/*.ts', '**/*.cts'],
},
})