Skip to content

Commit 110a107

Browse files
committed
ci: parallelize coverage contract collection
1 parent aea5ab9 commit 110a107

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

‎src/scripts/verify-coverage-contract.mjs‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { spawnSync } from "node:child_process"
1+
import { execFile, spawnSync } from "node:child_process"
22
import { mkdtempSync, readFileSync, readdirSync, rmSync } from "node:fs"
33
import { tmpdir } from "node:os"
44
import { relative, resolve } from "node:path"
55
import process from "node:process"
6+
import { promisify } from "node:util"
67

78
const pnpm = process.platform === "win32" ? process.env.npm_execpath : "pnpm"
89
if (!pnpm) throw new Error("pnpm executable path is unavailable")
@@ -116,20 +117,30 @@ if (Object.values(laneCounts).flat().length !== testFiles.length)
116117

117118
const collectionDirectory = mkdtempSync(resolve(tmpdir(), "zoo-code-coverage-contract-"))
118119
try {
119-
const collect = (config) => {
120+
const execFileAsync = promisify(execFile)
121+
const collect = async (config) => {
120122
const output = resolve(collectionDirectory, `${config}.json`)
121-
const collection = spawnSync(
123+
await execFileAsync(
122124
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 },
125136
)
126-
if (collection.status !== 0) throw new Error(collection.stderr || `Vitest collection failed for ${config}`)
127137
return new Set(JSON.parse(readFileSync(output, "utf8")).map(({ file, name }) => `${file}\0${name}`))
128138
}
129-
const unitTests = collect("unit")
139+
const collections = ["unit", ...ownershipLanes, "tree-sitter"]
140+
const [unitTests, ...resolvedLanes] = await Promise.all(collections.map(collect))
130141
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) {
133144
if (laneTests.has(test)) throw new Error(`Test belongs to multiple coverage lanes: ${test}`)
134145
laneTests.add(test)
135146
}

0 commit comments

Comments
 (0)