|
1 | | -import { spawnSync } from "node:child_process" |
| 1 | +import { execFile, spawnSync } from "node:child_process" |
2 | 2 | import { mkdtempSync, readFileSync, readdirSync, rmSync } from "node:fs" |
3 | 3 | import { tmpdir } from "node:os" |
4 | 4 | import { relative, resolve } from "node:path" |
5 | 5 | import process from "node:process" |
| 6 | +import { promisify } from "node:util" |
6 | 7 |
|
7 | 8 | const pnpm = process.platform === "win32" ? process.env.npm_execpath : "pnpm" |
8 | 9 | if (!pnpm) throw new Error("pnpm executable path is unavailable") |
@@ -116,20 +117,30 @@ if (Object.values(laneCounts).flat().length !== testFiles.length) |
116 | 117 |
|
117 | 118 | const collectionDirectory = mkdtempSync(resolve(tmpdir(), "zoo-code-coverage-contract-")) |
118 | 119 | try { |
119 | | - const collect = (config) => { |
| 120 | + const execFileAsync = promisify(execFile) |
| 121 | + const collect = async (config) => { |
120 | 122 | const output = resolve(collectionDirectory, `${config}.json`) |
121 | | - const collection = spawnSync( |
| 123 | + await execFileAsync( |
122 | 124 | command, |
123 | | - [...args, "exec", "vitest", "list", "--config", `vitest.${config}.config.ts`, `--json=${output}`], |
124 | | - { encoding: "utf8" }, |
| 125 | + [ |
| 126 | + ...args, |
| 127 | + "exec", |
| 128 | + "vitest", |
| 129 | + "list", |
| 130 | + "--staticParse", |
| 131 | + "--config", |
| 132 | + `vitest.${config}.config.ts`, |
| 133 | + `--json=${output}`, |
| 134 | + ], |
| 135 | + { maxBuffer: 10 * 1024 * 1024 }, |
125 | 136 | ) |
126 | | - if (collection.status !== 0) throw new Error(collection.stderr || `Vitest collection failed for ${config}`) |
127 | 137 | return new Set(JSON.parse(readFileSync(output, "utf8")).map(({ file, name }) => `${file}\0${name}`)) |
128 | 138 | } |
129 | | - const unitTests = collect("unit") |
| 139 | + const collections = ["unit", ...ownershipLanes, "tree-sitter"] |
| 140 | + const [unitTests, ...resolvedLanes] = await Promise.all(collections.map(collect)) |
130 | 141 | const laneTests = new Set() |
131 | | - for (const lane of [...ownershipLanes, "tree-sitter"]) { |
132 | | - for (const test of collect(lane)) { |
| 142 | + for (const tests of resolvedLanes) { |
| 143 | + for (const test of tests) { |
133 | 144 | if (laneTests.has(test)) throw new Error(`Test belongs to multiple coverage lanes: ${test}`) |
134 | 145 | laneTests.add(test) |
135 | 146 | } |
|
0 commit comments