Skip to content

Commit

Permalink
test: add basic coverage support (#1451)
Browse files Browse the repository at this point in the history
* test: add basic coverage support

* test: introduce codecov.io service support
Separate reporting into coverage creation and report generation (XML, HTML) steps.
Upload XML results to codecov.io.

* ci: run coverage on drafts; remove html coverage report artifact upload

---------

Co-authored-by: Kevin Eady <[email protected]>
  • Loading branch information
gabrielschulhof and KevinEady authored Mar 15, 2024
1 parent 089f1dc commit 0c46940
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/coverage-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Coverage Linux

on:
pull_request:
types: [opened, synchronize, reopened]
paths-ignore:
- '**.md'
- benchmark/**
- doc/**
- tools/**
- unit-test/**
- .github/**
- '!.github/workflows/coverage-linux.yml'
push:
branches:
- main
paths-ignore:
- '**.md'
- benchmark/**
- doc/**
- tools/**
- unit-test/**
- .github/**
- '!.github/workflows/coverage-linux.yml'

env:
PYTHON_VERSION: '3.11'
NODE_VERSION: '20.x'

permissions:
contents: read

jobs:
coverage-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Environment Information
run: npx envinfo
- name: Install gcovr
run: pip install gcovr==6.0
- name: Install dependencies
run: npm install
- name: Test with coverage
run: |
npm run create-coverage
- name: Generate coverage report (XML)
run: |
npm run report-coverage-xml
- name: Upload
uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0
with:
directory: ./coverage-xml
token: ${{ secrets.CODECOV_TOKEN }} # To bypass public API rate limiting, see https://github.com/codecov/codecov-action/issues/557
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@
"scripts": {
"prebenchmark": "node-gyp rebuild -C benchmark",
"benchmark": "node benchmark",
"create-coverage": "npm test --coverage",
"report-coverage-html": "rm -rf coverage-html && mkdir coverage-html && gcovr -e test --merge-mode-functions merge-use-line-max --html-nested ./coverage-html/index.html test",
"report-coverage-xml": "rm -rf coverage-xml && mkdir coverage-xml && gcovr -e test --merge-mode-functions merge-use-line-max --xml -o ./coverage-xml/coverage-cxx.xml test",
"pretest": "node-gyp rebuild -C test",
"test": "node test",
"test:debug": "node-gyp rebuild -C test --debug && NODE_API_BUILD_CONFIG=Debug node ./test/index.js",
Expand Down
7 changes: 7 additions & 0 deletions test/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,19 @@
'build_sources_type_check': [
'value_type_cast.cc'
],
'want_coverage': '<!(node -p process.env.npm_config_coverage)',
'conditions': [
['disable_deprecated!="true"', {
'build_sources': ['object/object_deprecated.cc']
}]
]
},
'conditions': [
['want_coverage=="true" and OS=="linux"', {
'cflags_cc': ['--coverage'],
'ldflags': ['--coverage'],
}]
],
},
'targets': [
{
Expand Down

0 comments on commit 0c46940

Please sign in to comment.