From 60b59c455c3e4ee8f6392dcc1cec6fd056c97a61 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 10 May 2018 11:21:25 -0700 Subject: [PATCH] Add coverage reporting for JavaScript and TypeScript files --- gulpfile.ts | 2 +- package.json | 20 +++++++++++++++++--- run-tests.sh | 18 +++++++++++++++--- test/gulpfile.js | 20 ++++++++++++++------ 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/gulpfile.ts b/gulpfile.ts index 388a74f4..dac1421e 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -102,7 +102,7 @@ gulp.task('test.only', 'Run tests without rebuilding anything', ['js.core.test', 'native.test.only']); gulp.task('test', 'Run all tests', (callback) => { - runSequence('build', 'test.only', callback); + runSequence('build', 'test.only', 'internal.test.test', callback); }); gulp.task('doc.gen', 'Generate documentation', ['native.core.doc.gen']); diff --git a/package.json b/package.json index fb626214..053f7d29 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@types/node": "^8.0.32", "@types/pify": "^3.0.0", "@types/semver": "^5.5.0", + "coveralls": "^3.0.1", "del": "^3.0.0", "execa": "^0.8.0", "gulp": "^3.9.1", @@ -35,8 +36,11 @@ "mocha": "^3.5.3", "mocha-jenkins-reporter": "^0.3.9", "ncp": "^2.0.0", + "nyc": "^11.7.2", "pify": "^3.0.0", + "run-sequence": "^2.2.0", "semver": "^5.5.0", + "symlink": "^2.1.0", "through2": "^2.0.3", "ts-node": "^3.3.0", "tslint": "^5.5.0", @@ -48,8 +52,18 @@ "name": "Google Inc." } ], - "dependencies": { - "run-sequence": "^2.2.0", - "symlink": "^2.1.0" + "nyc": { + "include": [ + "packages/grpc-health-check/health.js", + "packages/grpc-js-core/build/src/*", + "packages/grpc-native-core/index.js", + "packages/grpc-native-core/src/*.js", + "packages/grpc-protobufjs/build/src/*" + ], + "cache": true + }, + "scripts": { + "test": "nyc gulp test", + "coverage": "nyc report --reporter=text-lcov | coveralls" } } diff --git a/run-tests.sh b/run-tests.sh index 300a2527..afce89bb 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -39,6 +39,16 @@ npm install --unsafe-perm mkdir -p reports export JOBS=8 +export JUNIT_REPORT_PATH="reports/node$version/" +export JUNIT_REPORT_STACK=1 + +gsutil cp gs://grpc-testing-secrets/coveralls_credentials/grpc-node.rc . +set +x +. grpc-node.rc +set -x +export COVERALLS_REPO_TOKEN +export COVERALLS_SERVICE_NAME=Kokoro +export COVERALLS_SERVICE_JOB_ID=$KOKORO_BUILD_ID # TODO(mlumish): Add electron tests @@ -62,8 +72,8 @@ do ./node_modules/.bin/gulp clean.all ./node_modules/.bin/gulp setup - # Rebuild libraries and run tests. - JUNIT_REPORT_PATH="reports/node$version/" JUNIT_REPORT_STACK=1 ./node_modules/.bin/gulp test || FAILED="true" + # npm test calls nyc gulp test + npm test || FAILED="true" done set +ex @@ -72,7 +82,9 @@ set -ex node merge_kokoro_logs.js -if [ "$FAILED" != "" ] +if [ "$FAILED" == "" ] then + npm run coverage +else exit 1 fi diff --git a/test/gulpfile.js b/test/gulpfile.js index 61ff1658..b6221ed6 100644 --- a/test/gulpfile.js +++ b/test/gulpfile.js @@ -21,6 +21,7 @@ const mocha = require('gulp-mocha'); const execa = require('execa'); const path = require('path'); const del = require('del'); +const semver = require('semver'); const linkSync = require('../util').linkSync; // gulp-help monkeypatches tasks to have an additional description parameter @@ -51,12 +52,19 @@ gulp.task('test', 'Run API-level tests', () => { .on('end', resolve) .on('error', reject); }); - const runTestsArgPairs = [ - ['native', 'native'], - ['native', 'js'], - // ['js', 'native'], - // ['js', 'js'] - ]; + let runTestsArgPairs; + if (semver.satisfies(process.version, '>=9.4')) { + runTestsArgPairs = [ + ['native', 'native'], + ['native', 'js'], + // ['js', 'native'], + // ['js', 'js'] + ]; + } else { + runTestsArgPairs = [ + ['native', 'native'] + ]; + } return runTestsArgPairs.reduce((previousPromise, argPair) => { return previousPromise.then(runTestsWithFixture.bind(null, argPair[0], argPair[1])); }, Promise.resolve());