istanbul-js
Menu
Tutorials

AVA coverage: choose the source-loading setup first

Choose your AVA coverage setup around the way application code loads.

Separate execution runs contribute results to a shared coverage report.
With AVA, verify that results from worker execution reach the collected dataset.

Does your source use CommonJS or native ES modules? Do worker processes appear in the result? The documented nyc wrapper is a starting point for compatible source loading. A passing AVA run alone does not show that instrumentation reached the application.

Keep the passing test command

For an AVA project whose application modules use CommonJS, add nyc as a development dependency. Preserve existing AVA arguments and test discovery settings. These entries assume AVA is already installed and configured.

npm install --save-dev nyc

package.json (script fragment)

{
  "scripts": {
    "test": "ava",
    "coverage": "nyc --reporter=text --reporter=html npm test"
  }
}

.nycrc.json

{
  "all": true,
  "include": ["src/**/*.js", "src/**/*.cjs"]
}

The wrapper belongs in coverage only. Avoid a test script that calls it in return. Source scope belongs in nyc configuration; it is separate from which tests AVA discovers.

Prove that the source was measured

Open coverage/index.html and find an application module you recognize. Add a small module under src that no test imports; with this scope it should appear as unexecuted code. That catches a report limited to files that happened to load.

For a function with two outcomes, assert each one. A worker starting and an application branch executing are different observations. Use the process tree when subprocess collection is uncertain.

Handle transforms deliberately

If Babel owns instrumentation, follow the Babel recipe and disable nyc's second instrumentation pass. Native ESM uses a different loading path from CommonJS; do not assume a require-based wrapper measures it. Verify a collection approach supported by the installed runner and runtime.

Read symptoms before adding flags

ObservationNext check
AVA passes; report is emptySource loading and instrumentation ownership.
Only some modules appearInclude rules, extensions and all.
Generated lines appearThe transform’s source maps.
Worker appears; module does notThe module’s path and import mechanism.

Report format is independent of AVA's assertion API. Once collection works, choose HTML for investigation or LCOV for downstream tools.

Primary sources

Check official documentation against the tools installed in your project. These explanations and examples are independent.