Skip to content

Commit deb8544

Browse files
chore(NODE-3715): add code coverage generation to Evergreen tasks (#3107)
1 parent 383bf6b commit deb8544

File tree

6 files changed

+105
-3
lines changed

6 files changed

+105
-3
lines changed

.evergreen/config.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,42 @@ functions:
696696
- command: attach.xunit_results
697697
params:
698698
file: src/xunit.xml
699+
upload coverage report:
700+
- command: shell.exec
701+
params:
702+
working_dir: src
703+
script: |
704+
${PREPARE_SHELL}
705+
npx nyc report --reporter=json
706+
- command: s3.put
707+
params:
708+
aws_key: ${aws_key}
709+
aws_secret: ${aws_secret}
710+
local_file: src/coverage/coverage-final.json
711+
optional: true
712+
remote_file: mongo-node-driver/${revision}/${version_id}/coverage.${build_variant}.${task_name}.json
713+
bucket: mciuploads
714+
permissions: public-read
715+
content_type: application/json
716+
display_name: Raw Coverage Report
717+
download and merge coverage:
718+
- command: shell.exec
719+
params:
720+
silent: true
721+
working_dir: src
722+
script: |
723+
${PREPARE_SHELL}
724+
export AWS_ACCESS_KEY_ID=${aws_key}
725+
export AWS_SECRET_ACCESS_KEY=${aws_secret}
726+
# Download all the task coverage files.
727+
# TODO NODE-3897 - finish this function. the code below this point is untested because
728+
# aws s3 cp fails due to permissions errors
729+
aws s3 cp --recursive s3://mciuploads/mongo-node-driver/${revision}/${version_id}/ coverage/
730+
731+
npx nyc merge coverage/ merged-coverage/coverage.json
732+
npx nyc report -t merged-coverage --reporter=html --report-dir output
733+
734+
aws s3 cp output/lcov-report s3://mciuploads/mongo-node-driver/${revision}/${version_id}//lcov-report/
699735
tasks:
700736
- name: test-serverless
701737
tags:
@@ -1718,6 +1754,7 @@ pre:
17181754
- func: make files executable
17191755
post:
17201756
- func: upload test results
1757+
- func: upload coverage report
17211758
- func: cleanup
17221759
ignore:
17231760
- '*.md'

.evergreen/config.yml.in

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,47 @@ functions:
730730
params:
731731
file: "src/xunit.xml"
732732

733+
"upload coverage report":
734+
- command: shell.exec
735+
params:
736+
working_dir: "src"
737+
script: |
738+
${PREPARE_SHELL}
739+
npx nyc report --reporter=json
740+
- command: s3.put
741+
params:
742+
aws_key: ${aws_key}
743+
aws_secret: ${aws_secret}
744+
local_file: src/coverage/coverage-final.json
745+
optional: true
746+
# Upload the coverage report for all tasks in a single build to the same directory.
747+
# TODO NODE-3897 - change upload directory to mongo-node-driver-next
748+
# This change will require changing the `download and merge coverage` func as well
749+
remote_file: mongo-node-driver/${revision}/${version_id}/coverage.${build_variant}.${task_name}.json
750+
bucket: mciuploads
751+
permissions: public-read
752+
content_type: application/json
753+
display_name: "Raw Coverage Report"
754+
755+
"download and merge coverage":
756+
- command: shell.exec
757+
params:
758+
silent: true
759+
working_dir: "src"
760+
script: |
761+
${PREPARE_SHELL}
762+
export AWS_ACCESS_KEY_ID=${aws_key}
763+
export AWS_SECRET_ACCESS_KEY=${aws_secret}
764+
# Download all the task coverage files.
765+
# TODO NODE-3897 - finish this function. the code below this point is untested because
766+
# aws s3 cp fails due to permissions errors
767+
aws s3 cp --recursive s3://mciuploads/mongo-node-driver/${revision}/${version_id}/ coverage/
768+
769+
npx nyc merge coverage/ merged-coverage/coverage.json
770+
npx nyc report -t merged-coverage --reporter=html --report-dir output
771+
772+
aws s3 cp output/lcov-report s3://mciuploads/mongo-node-driver/${revision}/${version_id}//lcov-report/
773+
733774
tasks:
734775
- name: "test-serverless"
735776
tags: ["serverless"]
@@ -781,6 +822,7 @@ pre:
781822

782823
post:
783824
- func: "upload test results"
825+
- func: "upload coverage report"
784826
- func: "cleanup"
785827

786828
ignore:

.evergreen/generate_evergreen_tasks.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,14 @@ BUILD_VARIANTS.push({
563563
tasks: ['run-checks']
564564
});
565565

566+
// TODO NODE-3897 - generate combined coverage report
567+
// BUILD_VARIANTS.push({
568+
// name: 'generate-combined-coverage',
569+
// display_name: 'Generate Combined Coverage',
570+
// run_on: DEFAULT_OS,
571+
// tasks: ['download-and-merge-coverage']
572+
// });
573+
566574
// singleton build variant for mongosh integration tests
567575
SINGLETON_TASKS.push({
568576
name: 'run-mongosh-integration-tests',
@@ -629,6 +637,20 @@ const oneOffFuncAsTasks = oneOffFuncs.map(oneOffFunc => ({
629637
]
630638
}));
631639

640+
// TODO NODE-3897 - generate combined coverage report
641+
const coverageTask = {
642+
name: 'download and merge coverage'.split(' ').join('-'),
643+
tags: [],
644+
commands: [
645+
{
646+
func: 'download and merge coverage'
647+
}
648+
],
649+
depends_on: [
650+
{ name: '*', variant: '*', status: '*', patch_optional: true }
651+
]
652+
}
653+
632654
SINGLETON_TASKS.push(...oneOffFuncAsTasks);
633655

634656
BUILD_VARIANTS.push({

.evergreen/run-checks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -o xtrace
1818
## Checks typescript, eslint, and prettier
1919
npm run check:lint
2020

21-
npm run check:unit
21+
npx nyc npm run check:unit
2222

2323
export TSC="./node_modules/typescript/bin/tsc"
2424

.evergreen/run-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ set -o errexit # Exit the script with error if any of the commands fail
88
# UNIFIED Set to enable the Unified SDAM topology for the node driver
99
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
1010
# MARCH Machine Architecture. Defaults to lowercase uname -m
11-
# TEST_NPM_SCRIPT Script to npm run. Defaults to "check:test"
11+
# TEST_NPM_SCRIPT Script to npm run. Defaults to "integration-coverage"
1212
# SKIP_DEPS Skip installing dependencies
1313
# NO_EXIT Don't exit early from tests that leak resources
1414

1515
AUTH=${AUTH:-noauth}
1616
UNIFIED=${UNIFIED:-}
1717
MONGODB_URI=${MONGODB_URI:-}
18-
TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-check:test}
18+
TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-check:integration-coverage}
1919
if [[ -z "${NO_EXIT}" ]]; then
2020
TEST_NPM_SCRIPT="$TEST_NPM_SCRIPT -- --exit"
2121
fi

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"build:docs": "typedoc",
101101
"check:bench": "node test/benchmarks/driverBench",
102102
"check:coverage": "nyc npm run test:all",
103+
"check:integration-coverage": "nyc npm run check:test",
103104
"check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
104105
"check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
105106
"check:tsd": "tsd --version && tsd",

0 commit comments

Comments
 (0)