Node.js coverage with GitHub Actions and coveralls
I wanted to automate the coverage of my NPM robots-parser package so all pull requests and commits are checked and coverage is automatically logged. I also wanted to test against multiple versions of node at once.
I’ve used Coveralls in the past, and it’s free for OSS, so I decided to go with that. If you’re using Istanbul/nyc it’s not too difficult to add coveralls support.
By default the Coveralls GitHub will try to load the lcov file from
./coverage/lcov.info
which happens to also be the location Istanbul/nyc puts
it by default.
So all that’s needed is to add the lcov reporter, which in my case was adding
--reporter=lcovonly
to the nyc command, and then trigger the coveralls action
once it’s run.
The final result:
name: test
on:
pull_request:
branches:
- master
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
node: ["12", "14", "15"]
name: Node ${{ matrix.node }} test
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- run: npm ci
# Run tests and generate the lcov.info file
- run: npm test
# Run the coveralls action which uploads the
# lcov.info file
- name: Coveralls Parallel
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.node }}
# This is a parallel build so need this
parallel: true
# As testing against multiple versions need this to
# finish the parallel build
finish:
name: Coveralls coverage
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
You can see the YAML file here and what the generated coverage looks like here.
Comments