Instrument the browser build that your tests actually load.

Is the browser executing the intended bundle? Who exports counters before navigation clears them? A nyc wrapper around a Node controller does not collect code running inside a separate browser by itself. Define those responsibilities before adding flags.
Give each stage one job
| Stage | Responsibility |
|---|---|
| Coverage-only build | Insert counters into application modules. |
| Browser harness | Execute the instrumented asset and assertions. |
| Collection bridge | Retrieve the page’s coverage object. |
| Host report step | Combine compatible maps and render output. |
If webpack already transforms source through Babel, babel-plugin-istanbul can own instrumentation. Its README states that it does not persist data or generate reports. Keep it in the test environment so ordinary production builds do not acquire counters.
Instrument through the test transform
This fragment assumes application source already passes through Babel in webpack, and the plugin is installed as a development dependency. Preserve existing presets and loader settings.
Babel configuration fragment
{
"env": {
"test": {
"plugins": [["istanbul", {
"exclude": ["**/*.test.js", "**/*.spec.js"]
}]]
}
}
}Set NODE_ENV=test for the coverage build with your project's environment mechanism. Do not add another instrumenter to the same source. Preserve maps through transformation and bundling, then verify locations in the report.
Export before page teardown
Retrieve counters after the tested actions finish. This snippet describes the browser-side value your existing automation should transfer; it is not a browser-runner API.
Inside the instrumented browser page
const snapshot = window.__coverage__;
if (!snapshot) {
throw new Error('The page did not expose Istanbul counters');
}
const serializedCoverage = JSON.stringify(snapshot);Use the runner's documented bridge to transfer JSON to the host. Save a distinct snapshot for each completed page session. Collect before closing the page, navigating away or replacing global state.
Use the raw-object workflow to render snapshots. Raw V8 ranges and Istanbul file maps are different formats; do not place one in the other's input directory without conversion.
Verify the collection path
| Observation | Next check |
|---|---|
| The object is undefined | Loaded bundle and Babel test environment. |
| Only the controller is covered | Browser export and transfer. |
| Bundle locations appear | Maps through each build stage. |
| Results change after navigation | Snapshot timing and page contexts. |
Keep a branch probe in the test build: one asserted outcome should leave the alternative uncovered. This validates build, bridge and reporting together before you interpret a large report.
Primary sources
Check official documentation against the tools installed in your project. These explanations and examples are independent.