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

Function executeTests

packages/vitest/src/node/pool.ts:68–224  ·  view source on GitHub ↗
(method: 'run' | 'collect', specs: TestSpecification[], invalidates?: string[])

Source from the content-addressed store, hash-verified

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') {
112 browserSpecs.push(...specs)
113 continue
114 }
115
116 const environment = environments.get(specs[0])!
117 if (!environment) {
118 throw new Error(`Cannot find the environment. This is a bug in Vitest.`)
119 }
120
121 let env = projectEnvs.get(project)
122 if (!env) {
123 env = {
124 ...process.env,
125 ...options.env,

Callers 1

createPoolFunction · 0.70

Calls 15

getSpecificationsOptionsFunction · 0.90
createBrowserPoolFunction · 0.90
groupSpecsFunction · 0.85
resolveConditionsFunction · 0.85
getMemoryLimitFunction · 0.85
onCancelMethod · 0.80
setMaxWorkersMethod · 0.80
cancelFilesMethod · 0.80
runTestsMethod · 0.80
filterMethod · 0.65
cancelMethod · 0.45
shardMethod · 0.45

Tested by

no test coverage detected