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

Function createPool

packages/vitest/src/node/pool.ts:54–238  ·  view source on GitHub ↗
(ctx: Vitest)

Source from the content-addressed store, hash-verified

52}
53
54export function createPool(ctx: Vitest): ProcessPool {
55 const pool = new Pool({
56 distPath: ctx.distPath,
57 teardownTimeout: ctx.config.teardownTimeout,
58 state: ctx.state,
59 }, ctx.logger)
60
61 const options = resolveOptions(ctx)
62
63 const Sequencer = ctx.config.sequence.sequencer
64 const sequencer = new Sequencer(ctx)
65
66 let browserPool: ProcessPool | undefined
67
68 async function executeTests(method: 'run' | 'collect', specs: TestSpecification[], invalidates?: string[]): Promise<void> {
69 ctx.onCancel(() => pool.cancel())
70
71 if (ctx.config.shard) {
72 if (!ctx.config.passWithNoTests && ctx.config.shard.count > specs.length) {
73 throw new Error(
74 '--shard <count> must be a smaller than count of test files. '
75 + `Resolved ${specs.length} test files for --shard=${ctx.config.shard.index}/${ctx.config.shard.count}.`,
76 )
77 }
78 specs = await sequencer.shard(Array.from(specs))
79 }
80
81 const taskGroups: {
82 tasks: PoolTask[]
83 maxWorkers: number
84 // browser pool has a more complex logic, so we keep it separately for now
85 browserSpecs: TestSpecification[]
86 }[] = []
87 let workerId = 0
88
89 const sorted = await sequencer.sort(specs)
90 const { environments, tags } = await getSpecificationsOptions(specs)
91 const groups = groupSpecs(sorted, environments)
92
93 const projectEnvs = new WeakMap<TestProject, Partial<NodeJS.ProcessEnv>>()
94 const projectExecArgvs = new WeakMap<TestProject, string[]>()
95
96 for (const group of groups) {
97 if (!group) {
98 continue
99 }
100
101 const taskGroup: PoolTask[] = []
102 const browserSpecs: TestSpecification[] = []
103 taskGroups.push({
104 tasks: taskGroup,
105 maxWorkers: group.maxWorkers,
106 browserSpecs,
107 })
108
109 for (const specs of group.specs) {
110 const { project, pool } = specs[0]
111 if (pool === 'browser') {

Callers 2

runFilesMethod · 0.90
collectTestsMethod · 0.90

Calls 2

resolveOptionsFunction · 0.70
executeTestsFunction · 0.70

Tested by

no test coverage detected