Skip to content

Commit

Permalink
chore(NODE-3715): add code coverage generation to Evergreen tasks (#3107
Browse files Browse the repository at this point in the history
)
  • Loading branch information
baileympearson committed Feb 1, 2022
1 parent 383bf6b commit deb8544
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 3 deletions.
37 changes: 37 additions & 0 deletions .evergreen/config.yml
Expand Up @@ -696,6 +696,42 @@ functions:
- command: attach.xunit_results
params:
file: src/xunit.xml
upload coverage report:
- command: shell.exec
params:
working_dir: src
script: |
${PREPARE_SHELL}
npx nyc report --reporter=json
- command: s3.put
params:
aws_key: ${aws_key}
aws_secret: ${aws_secret}
local_file: src/coverage/coverage-final.json
optional: true
remote_file: mongo-node-driver/${revision}/${version_id}/coverage.${build_variant}.${task_name}.json
bucket: mciuploads
permissions: public-read
content_type: application/json
display_name: Raw Coverage Report
download and merge coverage:
- command: shell.exec
params:
silent: true
working_dir: src
script: |
${PREPARE_SHELL}
export AWS_ACCESS_KEY_ID=${aws_key}
export AWS_SECRET_ACCESS_KEY=${aws_secret}
# Download all the task coverage files.
# TODO NODE-3897 - finish this function. the code below this point is untested because
# aws s3 cp fails due to permissions errors
aws s3 cp --recursive s3://mciuploads/mongo-node-driver/${revision}/${version_id}/ coverage/
npx nyc merge coverage/ merged-coverage/coverage.json
npx nyc report -t merged-coverage --reporter=html --report-dir output
aws s3 cp output/lcov-report s3://mciuploads/mongo-node-driver/${revision}/${version_id}//lcov-report/
tasks:
- name: test-serverless
tags:
Expand Down Expand Up @@ -1718,6 +1754,7 @@ pre:
- func: make files executable
post:
- func: upload test results
- func: upload coverage report
- func: cleanup
ignore:
- '*.md'
Expand Down
42 changes: 42 additions & 0 deletions .evergreen/config.yml.in
Expand Up @@ -730,6 +730,47 @@ functions:
params:
file: "src/xunit.xml"

"upload coverage report":
- command: shell.exec
params:
working_dir: "src"
script: |
${PREPARE_SHELL}
npx nyc report --reporter=json
- command: s3.put
params:
aws_key: ${aws_key}
aws_secret: ${aws_secret}
local_file: src/coverage/coverage-final.json
optional: true
# Upload the coverage report for all tasks in a single build to the same directory.
# TODO NODE-3897 - change upload directory to mongo-node-driver-next
# This change will require changing the `download and merge coverage` func as well
remote_file: mongo-node-driver/${revision}/${version_id}/coverage.${build_variant}.${task_name}.json
bucket: mciuploads
permissions: public-read
content_type: application/json
display_name: "Raw Coverage Report"

"download and merge coverage":
- command: shell.exec
params:
silent: true
working_dir: "src"
script: |
${PREPARE_SHELL}
export AWS_ACCESS_KEY_ID=${aws_key}
export AWS_SECRET_ACCESS_KEY=${aws_secret}
# Download all the task coverage files.
# TODO NODE-3897 - finish this function. the code below this point is untested because
# aws s3 cp fails due to permissions errors
aws s3 cp --recursive s3://mciuploads/mongo-node-driver/${revision}/${version_id}/ coverage/

npx nyc merge coverage/ merged-coverage/coverage.json
npx nyc report -t merged-coverage --reporter=html --report-dir output

aws s3 cp output/lcov-report s3://mciuploads/mongo-node-driver/${revision}/${version_id}//lcov-report/

tasks:
- name: "test-serverless"
tags: ["serverless"]
Expand Down Expand Up @@ -781,6 +822,7 @@ pre:

post:
- func: "upload test results"
- func: "upload coverage report"
- func: "cleanup"

ignore:
Expand Down
22 changes: 22 additions & 0 deletions .evergreen/generate_evergreen_tasks.js
Expand Up @@ -563,6 +563,14 @@ BUILD_VARIANTS.push({
tasks: ['run-checks']
});

// TODO NODE-3897 - generate combined coverage report
// BUILD_VARIANTS.push({
// name: 'generate-combined-coverage',
// display_name: 'Generate Combined Coverage',
// run_on: DEFAULT_OS,
// tasks: ['download-and-merge-coverage']
// });

// singleton build variant for mongosh integration tests
SINGLETON_TASKS.push({
name: 'run-mongosh-integration-tests',
Expand Down Expand Up @@ -629,6 +637,20 @@ const oneOffFuncAsTasks = oneOffFuncs.map(oneOffFunc => ({
]
}));

// TODO NODE-3897 - generate combined coverage report
const coverageTask = {
name: 'download and merge coverage'.split(' ').join('-'),
tags: [],
commands: [
{
func: 'download and merge coverage'
}
],
depends_on: [
{ name: '*', variant: '*', status: '*', patch_optional: true }
]
}

SINGLETON_TASKS.push(...oneOffFuncAsTasks);

BUILD_VARIANTS.push({
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/run-checks.sh
Expand Up @@ -18,7 +18,7 @@ set -o xtrace
## Checks typescript, eslint, and prettier
npm run check:lint

npm run check:unit
npx nyc npm run check:unit

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

Expand Down
4 changes: 2 additions & 2 deletions .evergreen/run-tests.sh
Expand Up @@ -8,14 +8,14 @@ set -o errexit # Exit the script with error if any of the commands fail
# UNIFIED Set to enable the Unified SDAM topology for the node driver
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
# MARCH Machine Architecture. Defaults to lowercase uname -m
# TEST_NPM_SCRIPT Script to npm run. Defaults to "check:test"
# TEST_NPM_SCRIPT Script to npm run. Defaults to "integration-coverage"
# SKIP_DEPS Skip installing dependencies
# NO_EXIT Don't exit early from tests that leak resources

AUTH=${AUTH:-noauth}
UNIFIED=${UNIFIED:-}
MONGODB_URI=${MONGODB_URI:-}
TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-check:test}
TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-check:integration-coverage}
if [[ -z "${NO_EXIT}" ]]; then
TEST_NPM_SCRIPT="$TEST_NPM_SCRIPT -- --exit"
fi
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -100,6 +100,7 @@
"build:docs": "typedoc",
"check:bench": "node test/benchmarks/driverBench",
"check:coverage": "nyc npm run test:all",
"check:integration-coverage": "nyc npm run check:test",
"check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
"check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
"check:tsd": "tsd --version && tsd",
Expand Down

0 comments on commit deb8544

Please sign in to comment.