Skip to content

Commit c641475

Browse files
committed
fix(ci): support coverage verifier on Windows
1 parent 6db7e3c commit c641475

4 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎src/scripts/copy-tree-sitter-wasms.spec.mjs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ describe("publishTreeSitterWasms", () => {
4848
expect(() => publishTreeSitterWasms(source, destination, filesystem)).toThrow("copy failed")
4949
expect(fs.readdirSync(destination)).toEqual([])
5050
})
51+
52+
it("removes published and temporary outputs when an atomic rename fails", () => {
53+
const source = path.join(root, "source")
54+
const destination = path.join(root, "dist")
55+
fs.mkdirSync(source)
56+
fs.writeFileSync(path.join(source, "tree-sitter-a.wasm"), "a")
57+
const filesystem = {
58+
...fs,
59+
renameSync() {
60+
throw new Error("rename failed")
61+
},
62+
}
63+
64+
expect(() => publishTreeSitterWasms(source, destination, filesystem)).toThrow("rename failed")
65+
expect(fs.readdirSync(destination)).toEqual([])
66+
})
5167
})

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,24 @@ import process from "node:process"
55
import { fileURLToPath } from "node:url"
66

77
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..")
8-
const pnpm = process.platform === "win32" ? "pnpm.cmd" : "pnpm"
8+
const pnpm = process.platform === "win32" ? process.env.npm_execpath : "pnpm"
9+
if (!pnpm) throw new Error("pnpm executable path is unavailable")
10+
const pnpmPrefix = process.platform === "win32" ? [pnpm] : []
911
const run = (args, options = {}) => {
1012
const { includeStderr = true, ...spawnOptions } = options
11-
const result = spawnSync(pnpm, args, { cwd: root, encoding: "utf8", ...spawnOptions })
12-
if (result.status !== 0) throw new Error(result.stderr || result.stdout || `${pnpm} failed`)
13+
const command = process.platform === "win32" ? process.execPath : pnpm
14+
const result = spawnSync(command, [...pnpmPrefix, ...args], { cwd: root, encoding: "utf8", ...spawnOptions })
15+
if (result.status !== 0) {
16+
const details = [
17+
result.error?.message,
18+
result.signal ? `terminated by ${result.signal}` : undefined,
19+
result.stderr,
20+
result.stdout,
21+
]
22+
.filter(Boolean)
23+
.join("\n")
24+
throw new Error(details || `pnpm exited with status ${result.status ?? "unknown"}`)
25+
}
1326
return `${result.stdout || ""}${includeStderr ? result.stderr || "" : ""}`
1427
}
1528

‎src/scripts/verify-lcov.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export function verifyLcov(content) {
1212
inRecord = true
1313
} else if (line.startsWith("LH:")) {
1414
if (!inRecord) throw new Error("LCOV hit count is outside a source record")
15-
if (Number(line.slice(3)) > 0) anyCovered = true
15+
const hits = line.slice(3)
16+
if (!/^\d+$/.test(hits)) throw new Error("LCOV hit count is not a decimal integer")
17+
if (BigInt(hits) > 0n) anyCovered = true
1618
} else if (line === "end_of_record") {
1719
if (!inRecord) throw new Error("LCOV terminator is outside a source record")
1820
inRecord = false

‎src/scripts/verify-lcov.spec.mjs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ describe("verifyLcov", () => {
1111
["an unterminated record", "SF:file.ts\nLH:1\n"],
1212
["a zero-hit report", "SF:file.ts\nLF:1\nLH:0\nend_of_record\n"],
1313
["a hit count outside a record", "LH:1\n"],
14+
["a terminator outside a record", "end_of_record\n"],
15+
["an infinite hit count", "SF:file.ts\nLH:Infinity\nend_of_record\n"],
16+
["a fractional hit count", "SF:file.ts\nLH:1.5\nend_of_record\n"],
17+
["an exponential hit count", "SF:file.ts\nLH:1e3\nend_of_record\n"],
1418
])("rejects %s", (_, content) => {
1519
expect(() => verifyLcov(content)).toThrow()
1620
})

0 commit comments

Comments
 (0)