Fallow publishes a Rust package for mapping JavaScript V8 coverage offsets
fallow-v8-coverage 3.51.0 parses V8 coverage JSON and maps UTF-16 source offsets to line and column locations.
A library for one stage of coverage processing
fallow-v8-coverage 3.51.0 reached the Rust package registry at 02:09:30 on November 29 in Istanbul. Docs.rs records the separate version. The release contains types for parsing coverage records and a mapper that turns V8 source offsets into line and column positions. Coverage records tell a reader about executed code ranges. The mapper handles the step between a raw offset and the location that can be shown in a report. The package is one part of the broader Fallow analysis pipeline.
Offsets and bytes can differ
V8 reports these offsets in UTF-16 code units. A file stored in UTF-8 represents some characters with a different number of bytes. A smiling face before a function uses two UTF-16 units and four UTF-8 bytes. A mapper that assumes equality will identify the wrong column after that character. An ASCII-only fixture can miss the error. The package stores line starts in UTF-16 units. That makes its offset table match the unit used by the coverage data producer.
Report coordinates need a convention
The mapper reports lines starting at one and columns starting at zero. A consumer must preserve that convention when it hands the location to a viewer or editor. It also needs the source associated with that coverage run. Opening a newer revision of the file can produce a mismatch even when the calculation is correct. Generated files require additional care, since a source map may have a separate role in locating the original code. Keep the artifact and source identity with its coverage result.
Design a fixture that can catch a unit error
Put a non-ASCII character before a named function on the same line. Call the function once and collect its reported range. Check that the start resolves to the expected function and that the preceding character is outside the range. Keep a matching ASCII fixture to isolate the effect of the character encoding. A multiline fixture can separately test the next line start. This gives a team a focused way to distinguish an offset conversion problem from a real coverage gap.
What the package release verifies
Parallel test workers may write separate coverage files for the same module. Record the source identity and test run with each file. Verify they refer to the same artifact before combining counts, even if both reports show a path with the same spelling. The crate contains the parsing and mapping layer. It receives coverage data from an execution environment and does not decide which code was run by a test. A complete coverage report still depends on which tests ran, which scripts loaded and how multiple runs are combined. Before merging results, check that they refer to the intended versions of the files. The distribution and the Docs.rs record verify the release. The laptop photograph is illustrative and does not show a Fallow benchmark.
Photo · Negative Space / Wikimedia Commons. Resized and converted to WebP. ↗ · CC0 1.0
Sources and verification
- Primary sourcecrates.io ↗
- Technical documentV8 JavaScript code coverage ↗
- Reporting / cross-checkDocs.rs ↗
Reader discussion
Which alternative architecture would you try for the same problem?
No comments yet. Be the first to contribute.
Write a comment