Skip to content

Commit

Permalink
Merge pull request #218 from hammerlab/restore-coverage
Browse files Browse the repository at this point in the history
Generate coverage data using Istanbul
  • Loading branch information
armish committed Jul 7, 2015
2 parents 37b082a + 7d27c7a commit 69a58b4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
36 changes: 36 additions & 0 deletions scripts/generate-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/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.
rm -rf coverage/* # Clear out everything to ensure a hermetic run.
istanbul instrument --output coverage/main dist/main
cp -r dist/test coverage/test # test code needn't be covered

# 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

# Monkey patch in the untransformed source paths.
perl -i -pe 's,dist/main,src/main,' coverage/lcov.info
2 changes: 1 addition & 1 deletion src/test/coverage.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<!-- Mocha -->
<script src="../../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="../../dist/cov/tests.js"></script>
<script src="../../coverage/tests.js"></script>

<script>
mocha.checkLeaks();
Expand Down

0 comments on commit 69a58b4

Please sign in to comment.