Lightweight V8 Coverage Mode
Applies to: Node.js services, workers and in-process tests started with
slnodejs run,slnodejs mochaor the preload script. Available fromslnodejs6.2.100. Requires Node.js later than 20.6.0.
What it is
The test listener has two ways to collect coverage:
Default (NYC)
Lightweight V8 mode
How it collects coverage
Instruments your code in memory as it loads, adding counters to every function.
Reads the coverage that Node.js itself records (V8 coverage). Your code runs unchanged.
Overhead
Higher: the instrumented code uses more memory and runs slower. Large services can start slowly or run out of memory.
Lower: no instrumented copy, no counters.
Node.js version
18 and later
Later than 20.6.0
Applications
Node.js processes. (Browser code is covered by the Browser Agent; Lambda by the Lambda layer.)
Node.js processes only.
Coverage per test
Yes
No: coverage is reported per test stage
HTTP coloring (--httpServerColoring, --httpClientColoring)
Yes
No
Set-up change
None (default)
Scan with --rawCoverage; set SL_useLeanCoverageListener=true where the service starts
Both modes use the same package, the same commands, and the same start-up methods. If lightweight mode cannot start, slnodejs logs Lean coverage listener failed to start, falling back to NYC and collects coverage with NYC.
When to use it
The service runs out of memory, or starts slowly, after adding SeaLights.
Tests run noticeably slower against the instrumented service.
You want the lowest overhead, and coverage per test stage is enough.
When not to use it
You need coverage per test, for example for Test Impact Analysis of functional tests through HTTP headers.
The process runs on Node.js 20.6.0 or earlier. On those versions,
slnodejs runandslnodejs mocharun your program inside theslnodejsprocess, where V8 coverage cannot be turned on: only child processes would be covered.You want to check the setup with
dryRun, which does not simulate this mode.
How it works
slnodejs scan --rawCoveragereports the build, plus the metadata SeaLights needs to process V8 coverage.slnodejs run(ormocha, or the preload script) starts your program in a new Node.js process, with the Node.js variableNODE_V8_COVERAGEpointing to a coverage folder.Inside your program, the agent makes Node.js write the coverage collected so far every
SL_COVERAGE_INTERVALmilliseconds (10 seconds by default).The
slnodejsprocess watches the folder, reads each new coverage file, and sends the functions that ran to SeaLights, for the test stage open on the lab.SeaLights maps the coverage to the methods of the scanned build.
With slnodejs mocha, the SeaLights Mocha reporter still opens the test stage, reports results and applies Test Impact Analysis; the lightweight listener sends the coverage to that test stage.
Next steps
How to Use: set-up, TypeScript, shutdown.
Configuration: the settings of this mode.
Troubleshooting: common problems and their log messages.
Last updated
Was this helpful?

