From c3f140feacf2a69d3e3166fea85ae2b6a001728c Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 30 Jun 2019 20:31:32 -0400 Subject: [PATCH] build: use nyc for test coverage --- .gitignore | 1 + .travis.yml | 22 +++++++++++++++++++++- appveyor.yml | 2 ++ package.json | 5 +++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 0fa6951..f15b98e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.nyc_output/ coverage/ node_modules/ npm-debug.log diff --git a/.travis.yml b/.travis.yml index 85a1c66..8b19e93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,5 +11,25 @@ before_install: # Setup npm - "test $TRAVIS_NODE_VERSION != '0.8' || npm install -g npm@1.2.8000" - "npm config set shrinkwrap false" + # Setup Node.js version-specific dependencies + - | + # nyc for coverage + # - remove for Node.js < 6 + if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then + npm rm --silent --save-dev nyc + fi +script: + # Run test script + - | + if npm -ps ls nyc | grep -q nyc; then + npm run test-cov + else + npm test + fi after_script: - - "test -e ./coverage/lcov.info && npm install coveralls@2 && coveralls < ./coverage/lcov.info" + - | + # Upload coverage to coveralls if exists + if [[ -d .nyc_output ]]; then + npm install --save-dev coveralls@2 + nyc report --reporter=text-lcov | coveralls + fi diff --git a/appveyor.yml b/appveyor.yml index 0c4f734..0febf72 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,6 +16,8 @@ install: - if "%nodejs_version%" equ "0.8" npm config set strict-ssl false - if "%nodejs_version%" equ "0.8" npm install -g --prefix "%npm_prefix:~0,-1%" npm@1.2.8000 - npm config set shrinkwrap false + # Remove all non-test dependencies + - npm rm --silent --save-dev nyc # Install Node.js modules - npm install build: off diff --git a/package.json b/package.json index 46f8401..666a158 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "walk": "2.3.14" }, "devDependencies": { - "istanbul": "0.4.5", "mocha": "2.5.3", + "nyc": "14.1.1", "rimraf": "2.7.1", "supertest": "1.1.0" }, @@ -30,6 +30,7 @@ "npm": "1.2.8000 || >= 1.4.16" }, "scripts": { - "test": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter spec test/*/index.js" + "test": "mocha --reporter spec test/*/index.js", + "test-cov": "nyc --reporter=html --reporter=text npm test" } }