Skip to content

Commit 0c46940

Browse files
test: add basic coverage support (#1451)
* 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 <8634912+KevinEady@users.noreply.github.com>
1 parent 089f1dc commit 0c46940

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Coverage Linux
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
paths-ignore:
7+
- '**.md'
8+
- benchmark/**
9+
- doc/**
10+
- tools/**
11+
- unit-test/**
12+
- .github/**
13+
- '!.github/workflows/coverage-linux.yml'
14+
push:
15+
branches:
16+
- main
17+
paths-ignore:
18+
- '**.md'
19+
- benchmark/**
20+
- doc/**
21+
- tools/**
22+
- unit-test/**
23+
- .github/**
24+
- '!.github/workflows/coverage-linux.yml'
25+
26+
env:
27+
PYTHON_VERSION: '3.11'
28+
NODE_VERSION: '20.x'
29+
30+
permissions:
31+
contents: read
32+
33+
jobs:
34+
coverage-linux:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
38+
with:
39+
persist-credentials: false
40+
- name: Set up Python ${{ env.PYTHON_VERSION }}
41+
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
42+
with:
43+
python-version: ${{ env.PYTHON_VERSION }}
44+
- name: Use Node.js ${{ env.NODE_VERSION }}
45+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
46+
with:
47+
node-version: ${{ env.NODE_VERSION }}
48+
- name: Environment Information
49+
run: npx envinfo
50+
- name: Install gcovr
51+
run: pip install gcovr==6.0
52+
- name: Install dependencies
53+
run: npm install
54+
- name: Test with coverage
55+
run: |
56+
npm run create-coverage
57+
- name: Generate coverage report (XML)
58+
run: |
59+
npm run report-coverage-xml
60+
- name: Upload
61+
uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0
62+
with:
63+
directory: ./coverage-xml
64+
token: ${{ secrets.CODECOV_TOKEN }} # To bypass public API rate limiting, see https://github.com/codecov/codecov-action/issues/557

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@
463463
"scripts": {
464464
"prebenchmark": "node-gyp rebuild -C benchmark",
465465
"benchmark": "node benchmark",
466+
"create-coverage": "npm test --coverage",
467+
"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",
468+
"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",
466469
"pretest": "node-gyp rebuild -C test",
467470
"test": "node test",
468471
"test:debug": "node-gyp rebuild -C test --debug && NODE_API_BUILD_CONFIG=Debug node ./test/index.js",

test/binding.gyp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,19 @@
8787
'build_sources_type_check': [
8888
'value_type_cast.cc'
8989
],
90+
'want_coverage': '<!(node -p process.env.npm_config_coverage)',
9091
'conditions': [
9192
['disable_deprecated!="true"', {
9293
'build_sources': ['object/object_deprecated.cc']
9394
}]
9495
]
9596
},
97+
'conditions': [
98+
['want_coverage=="true" and OS=="linux"', {
99+
'cflags_cc': ['--coverage'],
100+
'ldflags': ['--coverage'],
101+
}]
102+
],
96103
},
97104
'targets': [
98105
{

0 commit comments

Comments
 (0)