When tests are instrumented with Istanbul, the Datadog Tracer reports code coverage under the test.code_coverage.lines_pct tag for your test sessions automatically. To instrument tests with Istanbul, you can use nyc.
To report total code coverage from your test sessions, follow these steps:
Install nyc:
npm install --save-dev nyc
Wrap your test command with nyc:
{"scripts":{"test":"mocha","coverage":"nyc npm run test"}}
Note: Jest includes Istanbul by default, so you don't need to install nyc. Simply pass --coverage.
{"scripts":{"coverage":"jest --coverage"}}
新しい coverage コマンドでテストを実行します。
NODE_OPTIONS="-r dd-trace/ci/init" DD_ENV=ci DD_SERVICE=my-javascript-service npm run coverage
If the all option is set to true when running nyc (see nyc docs), the total code coverage reported in the test session does not coincide with the value reported by nyc. This is because it does not include uncovered files (the ones that are not touched by your tests).
If you are using Coverlet to compute your code coverage, indicate the path to the report file in the DD_CIVISIBILITY_EXTERNAL_CODE_COVERAGE_PATH environment variable when running dd-trace. The report file must be in the OpenCover or Cobertura formats. Alternatively, you can enable the Datadog Tracer’s built-in code coverage calculation with the DD_CIVISIBILITY_CODE_COVERAGE_ENABLED=true environment variable.
Otherwise, you can configure the tracer to add Jacoco to your test runs at runtime.
Use DD_CIVISIBILITY_JACOCO_PLUGIN_VERSION environment variable to specify which version of Jacoco you want to have injected (for example: DD_CIVISIBILITY_JACOCO_PLUGIN_VERSION=0.8.11).
Reported code coverage is reported as @test.code_coverage.lines_pct, which represents the total percentage in the facet, and can be plotted as any other measure facet in the CI Visibility Explorer.