Code coverage support in Bazel is poor and one reason is the lack of a general mechanism for collecting the code coverage information.
As briefly described in Bazel coverage design doc, the next steps towards a more general solution are:
coverage_toolchain
@iirina I thought i'd post the instructions you left me here incase someone else is after a way to integrate with bazel coverage
in the interm until this is better supported.
If the rules are written in Starlark, something helpful can be:
Bazel generates coverage reports in the lcov format. To work well with Bazel, your test rules also have to generate lcov reports under COVERAGE_DIR directory. Your test rule has to define the $lcov_merger attrbiute (similar to how Java tests do ) https://github.com/bazelbuild/bazel/blob/17794d58cc493d918a98c3250302ca44b1d53e3f/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaTestRule.java#L70
One thing that came up today - with this design of coverage collection is it possible to have another rule depend on the coverage output? We would like to write another rule that depends on the output and then creates a script that will upload the report on bazel run
.
@iirina I'm taking another look at this but I havn't been able to figure out how to get COVERAGE_DIR
defined.
This is this PR im working in and im running the test npx bazel coverage packages/jasmine/test:coverage_test
but the only env var that's defined is LCOV_MERGER becasue I set it with coverage --test_env=LCOV_MERGER=/bin/true
https://github.com/bazelbuild/rules_nodejs/pull/1135
Most helpful comment
@iirina I thought i'd post the instructions you left me here incase someone else is after a way to integrate with
bazel coverage
in the interm until this is better supported.If the rules are written in Starlark, something helpful can be:
Bazel generates coverage reports in the lcov format. To work well with Bazel, your test rules also have to generate lcov reports under COVERAGE_DIR directory. Your test rule has to define the $lcov_merger attrbiute (similar to how Java tests do ) https://github.com/bazelbuild/bazel/blob/17794d58cc493d918a98c3250302ca44b1d53e3f/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaTestRule.java#L70