(method: 'run' | 'collect', specs: TestSpecification[], invalidates?: string[])
| 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, |
no test coverage detected