Skip to content

V8 coverage data ​

ts
// Coverage data for a source range.
export interface CoverageRange {
    // JavaScript script source offset for the range start.
    startOffset: integer;
    // JavaScript script source offset for the range end.
    endOffset: integer;
    // Collected execution count of the source range.
    count: integer;
}
// Coverage data for a JavaScript function.
/**
 * @functionName can be an empty string.
 * @ranges is always non-empty. The first range is called the "root range".
 * @isBlockCoverage indicates if the function has block coverage information.
    If this is false, it usually means that the function was never called.
    It seems to be equivalent to ranges.length === 1 && ranges[0].count === 0.
*/
export interface FunctionCoverage {
    // JavaScript function name.
    functionName: string;
    // Source ranges inside the function with coverage data.
    ranges: CoverageRange[];
    // Whether coverage data for this function has block granularity.
    isBlockCoverage: boolean;
}
// Coverage data for a JavaScript script.
export interface ScriptCoverage {
    // JavaScript script id.
    scriptId: Runtime.ScriptId;
    // JavaScript script name or url.
    url: string;
    // Functions contained in the script that has coverage data.
    functions: FunctionCoverage[];
}
export type V8CoverageData = ScriptCoverage[];
JavaScript RuntimeV8 Coverage
Chrome (65%)✅Chromium-based
Safari (18%)❌
Edge (5%)✅Chromium-based
Firefox (2%)❌
Node.js✅
Deno❌issue
Bun❌issue

MCR extends each V8 coverage entry with additional fields:

FieldTypeDescription
urlstringScript URL or file path
type"js" | "css"Entry type
sourcestring(JS) Source code text
sourceMapobject(JS) Parsed sourcemap object
scriptOffsetnumber(JS) Byte offset for the script wrapper (e.g. in vm modules). This offset is automatically added to all range start/end values
distFilestring(JS) The dist bundle file this source was unpacked from
emptybooleanMarked as true when this entry was added via the all option (no real coverage data), showing 0% coverage
fakebooleanMarked as true when the source code is not original (e.g. compiled from .ts/.jsx). The AST parser skips coverage extraction for fake sources

These fields can be read/mutated in onEntry hooks.