From 703322d72caabeb292bd9e9620047e9571a80310 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Tue, 7 Jul 2015 13:51:11 -0400 Subject: [PATCH] Generate coverage data using Istanbul --- .travis.yml | 4 +++- package.json | 3 +++ scripts/generate-coverage.sh | 34 ++++++++++++++++++++++++++++++++++ src/test/coverage.html | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100755 scripts/generate-coverage.sh diff --git a/.travis.yml b/.travis.yml index c085d860..7280bf79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,6 @@ script: > npm run build && npm run test && npm run flow-check && - npm run lint + npm run lint && + npm run coverage && + cat coverage/lcov.info | ./node_modules/.bin/coveralls diff --git a/package.json b/package.json index 1b1b0389..e8b61978 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "test": "./scripts/test.sh", "flow": "flow status", "flow-check": "flow check", + "coverage": "./scripts/generate-coverage.sh", "sniper": "biojs-sniper", "publish": "./scripts/publish.sh", "build": "npm run jstransform && npm run browserify-all && npm run uglify" @@ -78,6 +79,7 @@ "es5-shim": "^4.1.0", "flow-bin": "^0.12.0", "http-server": "^0.8.0", + "istanbul": "^0.3.17", "jscoverage": "^0.5.9", "jstransform": "^11.0.2", "jstransformify": "^1.0.0", @@ -86,6 +88,7 @@ "mocha": "^2.1.0", "mocha-lcov-reporter": ">=0.0.2", "mocha-phantomjs": "^3.5.3", + "mocha-phantomjs-istanbul": "0.0.2", "parse-data-uri": "^0.2.0", "phantomjs": "^1.9.17", "prepush-hook": "^0.1.0", diff --git a/scripts/generate-coverage.sh b/scripts/generate-coverage.sh new file mode 100755 index 00000000..90d0f258 --- /dev/null +++ b/scripts/generate-coverage.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Generate code coverage data for posting to Coveralls. +# This requires dist/*.js to be in place. +# Output is coverage/lcov.info + +set -o errexit +set -x + +# Instrument the source code with Istanbul's __coverage__ variable. +# We clear out everything to ensure a hermetic run. +rm -rf coverage/* +istanbul instrument --output coverage/main dist/main +istanbul instrument --output coverage/test dist/test + +# Build a combined file for running the tests in-browser +browserify coverage/**/*.js -o coverage/tests.js + +# Run http-server and save its PID for cleanup +npm run http-server > /dev/null & +SERVER_PID=$! +function finish() { + pkill -TERM -P $SERVER_PID +} +trap finish EXIT + +# Run the tests using mocha-phantomjs & mocha-phantomjs-istanbul +# This produces coverage/coverage.json +phantomjs \ + ./node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee \ + http://localhost:8080/src/test/coverage.html \ + spec '{"hooks": "mocha-phantomjs-istanbul", "coverageFile": "coverage/coverage.json"}' + +# Convert the JSON coverage to LCOV for coveralls. +istanbul report --include coverage/*.json lcovonly diff --git a/src/test/coverage.html b/src/test/coverage.html index 5df68415..ebf83eff 100644 --- a/src/test/coverage.html +++ b/src/test/coverage.html @@ -17,7 +17,7 @@ - +