Skip to content

Commit 92da13f

Browse files
bcoeBethGriggs
authored andcommitted
test: refactor coverage logic
Cleanup logic in Makefile for coverage. Update BUILDING.md accordingly. PR-URL: #35767 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent ae3c82c commit 92da13f

File tree

2 files changed

+27
-40
lines changed

2 files changed

+27
-40
lines changed

BUILDING.md

+18-14
Original file line numberDiff line numberDiff line change
@@ -389,28 +389,32 @@ $ make coverage
389389
```
390390

391391
A detailed coverage report will be written to `coverage/index.html` for
392-
JavaScript coverage and to `coverage/cxxcoverage.html` for C++ coverage
393-
(if you only want to run the JavaScript tests then you do not need to run
394-
the first command `./configure --coverage`).
392+
JavaScript coverage and to `coverage/cxxcoverage.html` for C++ coverage.
395393

396-
_Generating a test coverage report can take several minutes._
397-
398-
To collect coverage for a subset of tests you can set the `CI_JS_SUITES` and
399-
`CI_NATIVE_SUITES` variables (to run specific suites, e.g., `child-process`, in
400-
isolation, unset the opposing `_SUITES` variable):
394+
If you only want to run the JavaScript tests then you do not need to run
395+
the first command (`./configure --coverage`). Run `make coverage-run-js`,
396+
to execute JavaScript tests independently of the C++ test suite:
401397

402398
```text
403-
$ CI_JS_SUITES=child-process CI_NATIVE_SUITES= make coverage
399+
$ make coverage-run-js
404400
```
405401

406-
The above command executes tests for the `child-process` subsystem and
407-
outputs the resulting coverage report.
402+
If you are updating tests and want to collect coverrage for a single test file
403+
(e.g. `test/parallel/test-stream2-transform.js`):
404+
405+
```text
406+
$ make coverage-clean
407+
$ NODE_V8_COVERAGE=coverage/tmp python tools/test.py test/parallel/test-stream2-transform.js
408+
$ make coverage-report-js
409+
```
408410

409-
Alternatively, you can run `make coverage-run-js`, to execute JavaScript tests
410-
independently of the C++ test suite:
411+
You can collect coverage for the entire suite of tests for a given subsystem
412+
by providing the name of a subsystem:
411413

412414
```text
413-
$ CI_JS_SUITES=fs CI_NATIVE_SUITES= make coverage-run-js
415+
$ make coverage-clean
416+
$ NODE_V8_COVERAGE=coverage/tmp python tools/test.py -J --mode=release child-process
417+
$ make coverage-report-js
414418
```
415419

416420
The `make coverage` command downloads some tools to the project root directory.

Makefile

+9-26
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,11 @@ check: test
197197
# Remove files generated by running coverage, put the non-instrumented lib back
198198
# in place
199199
coverage-clean:
200-
if [ -d lib_ ]; then $(RM) -r lib; mv lib_ lib; fi
201200
$(RM) -r node_modules
202201
$(RM) -r gcovr build
203-
$(RM) -r out/$(BUILDTYPE)/.coverage
204-
$(RM) out/$(BUILDTYPE)/obj.target/node/gen/*.gcda
205-
$(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcda
206-
$(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing/*.gcda
207-
$(RM) out/$(BUILDTYPE)/obj.target/node/gen/*.gcno
208-
$(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcno
209-
$(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing/*.gcno
210-
$(RM) out/$(BUILDTYPE)/obj.target/cctest/src/*.gcno
211-
$(RM) out/$(BUILDTYPE)/obj.target/cctest/test/cctest/*.gcno
212-
$(RM) out/$(BUILDTYPE)/obj.target/embedtest/src/*.gcno
213-
$(RM) out/$(BUILDTYPE)/obj.target/embedtest/test/embedding/*.gcno
202+
$(RM) -r coverage/tmp
203+
$(FIND) out/$(BUILDTYPE)/obj.target \( -name "*.gcda" -o -name "*.gcno" \) \
204+
-type f -exec $(RM) {} \;
214205

215206
.PHONY: coverage
216207
# Build and test with code coverage reporting. Leave the lib directory
@@ -245,8 +236,8 @@ coverage-test: coverage-build
245236
$(RM) out/$(BUILDTYPE)/obj.target/node/src/*/*.gcda
246237
$(RM) out/$(BUILDTYPE)/obj.target/node_lib/src/*.gcda
247238
$(RM) out/$(BUILDTYPE)/obj.target/node_lib/src/*/*.gcda
248-
-NODE_V8_COVERAGE=out/$(BUILDTYPE)/.coverage \
249-
TEST_CI_ARGS="$(TEST_CI_ARGS) --type=coverage" $(MAKE) $(COVTESTS)
239+
-NODE_V8_COVERAGE=coverage/tmp \
240+
TEST_CI_ARGS="$(TEST_CI_ARGS) --type=coverage" $(MAKE) $(COVTESTS)
250241
$(MAKE) coverage-report-js
251242
-(cd out && "../gcovr/scripts/gcovr" \
252243
--gcov-exclude='.*\b(deps|usr|out|cctest|embedding)\b' -v \
@@ -259,17 +250,10 @@ coverage-test: coverage-build
259250
@grep -A3 Lines coverage/cxxcoverage.html | grep style \
260251
| sed 's/<[^>]*>//g'| sed 's/ //g'
261252

262-
COV_REPORT_OPTIONS = --reporter=html \
263-
--temp-directory=out/$(BUILDTYPE)/.coverage --omit-relative=false \
264-
--resolve=./lib --exclude="benchmark/" --exclude="deps/" --exclude="test/" --exclude="tools/" \
265-
--wrapper-length=0
266-
ifdef COV_ENFORCE_THRESHOLD
267-
COV_REPORT_OPTIONS += --check-coverage --lines=$(COV_ENFORCE_THRESHOLD)
268-
endif
269-
270253
.PHONY: coverage-report-js
271254
coverage-report-js:
272-
$(NODE) ./node_modules/.bin/c8 report $(COV_REPORT_OPTIONS)
255+
-$(MAKE) coverage-build-js
256+
$(NODE) ./node_modules/.bin/c8 report
273257

274258
.PHONY: cctest
275259
# Runs the C++ tests using the built `cctest` executable.
@@ -305,9 +289,8 @@ tooltest:
305289

306290
.PHONY: coverage-run-js
307291
coverage-run-js:
308-
$(RM) -r out/$(BUILDTYPE)/.coverage
309-
$(MAKE) coverage-build-js
310-
-NODE_V8_COVERAGE=out/$(BUILDTYPE)/.coverage CI_SKIP_TESTS=$(COV_SKIP_TESTS) \
292+
$(RM) -r coverage/tmp
293+
-NODE_V8_COVERAGE=coverage/tmp CI_SKIP_TESTS=$(COV_SKIP_TESTS) \
311294
TEST_CI_ARGS="$(TEST_CI_ARGS) --type=coverage" $(MAKE) jstest
312295
$(MAKE) coverage-report-js
313296

0 commit comments

Comments
 (0)