I’ve been lately working on a large Node.js application, and running the full test suite with code coverage instrumentation became more a more time consuming. Some of my other projects generate HTML code coverage results on CI and publish the outcome on GitHub Pages, but doing so here would mean that anyone would be able to see the coverage reports, and thus the code.
My friend Lucian Buzzo and I discovered that Circle CI serves build artifacts in a way that makes it possible to store the coverage assets there and browse them directly. This means that we can publish code coverage results only to people with access to the repository, and so the builds, and that we can easily browse code coverage results even before we merge a pull request.
This is how
.circleci/config.yml looks like for an example Node.js project
store_artifacts setting will save
coverage, the directory where
Istanbul stores the generated HTML (when using
destination property defines the artifact’s readable name. This property is
optional, and defaults to the absolute path to the artifact:
Circle CI will now start uploading the
coverage directory on every job:
Once the build completes, we will see a new “Artifacts” tab that contains the uploaded files:
index.html will render the coverage results right in your browser,
and if the repo is private, you will get a
must be logged in error message if
you don’t have the right access: