From deb854472c5bf8ed36f6b67ec5141ee6f02571fb Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 1 Feb 2022 14:11:42 -0500 Subject: [PATCH] chore(NODE-3715): add code coverage generation to Evergreen tasks (#3107) --- .evergreen/config.yml | 37 +++++++++++++++++++++++ .evergreen/config.yml.in | 42 ++++++++++++++++++++++++++ .evergreen/generate_evergreen_tasks.js | 22 ++++++++++++++ .evergreen/run-checks.sh | 2 +- .evergreen/run-tests.sh | 4 +-- package.json | 1 + 6 files changed, 105 insertions(+), 3 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index aa2c836b66..8dbd6cf3b7 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -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: @@ -1718,6 +1754,7 @@ pre: - func: make files executable post: - func: upload test results + - func: upload coverage report - func: cleanup ignore: - '*.md' diff --git a/.evergreen/config.yml.in b/.evergreen/config.yml.in index 794a252b2b..24ff723f73 100644 --- a/.evergreen/config.yml.in +++ b/.evergreen/config.yml.in @@ -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"] @@ -781,6 +822,7 @@ pre: post: - func: "upload test results" + - func: "upload coverage report" - func: "cleanup" ignore: diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index 21d842a783..deef3dd163 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -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', @@ -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({ diff --git a/.evergreen/run-checks.sh b/.evergreen/run-checks.sh index 944b4b36e7..bb493d7c76 100644 --- a/.evergreen/run-checks.sh +++ b/.evergreen/run-checks.sh @@ -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" diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index b1f0dd9688..791bc8b367 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -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 diff --git a/package.json b/package.json index 093ee89653..67c8d29094 100644 --- a/package.json +++ b/package.json @@ -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",