Created
March 27, 2026 06:19
-
-
Save AriPerkkio/0039e4c284ae35a7d81bedf71a616b76 to your computer and use it in GitHub Desktop.
Record v8 coverage for repros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import inspector from "node:inspector/promises"; | |
| import { writeFileSync } from "node:fs"; | |
| const target = "coverage-target.mjs"; | |
| writeFileSync( | |
| target, | |
| `\ | |
| // Repro code here | |
| `, | |
| "utf-8", | |
| ); | |
| const session = new inspector.Session(); | |
| const coverage = await recordCoverage(async () => { | |
| await import(`./${target}`); | |
| }); | |
| console.log(JSON.stringify(coverage, null, 2)); | |
| export async function recordCoverage(method: () => Promise<void>) { | |
| session.connect(); | |
| await session.post("Profiler.enable"); | |
| await session.post("Profiler.startPreciseCoverage", { | |
| callCount: true, | |
| detailed: true, | |
| }); | |
| await method(); | |
| const { result } = await session.post("Profiler.takePreciseCoverage"); | |
| await session.post("Profiler.stopPreciseCoverage"); | |
| await session.post("Profiler.disable"); | |
| session.disconnect(); | |
| return result.find(({ url }) => url.endsWith("coverage-target.mjs")); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment