Dygraph.dateString_: shows milliseconds if any. (#774)
[dygraphs.git] / scripts / generate-coverage.sh
CommitLineData
ff876d52
DV
1#!/bin/bash
2# Generate code coverage data for posting to Coveralls.
3# This requires dist/*.js to be in place.
4# Output is coverage/lcov.info
5
6set -o errexit
7set -x
8
9# Generate per-file ES6 --> ES5 transpilations
843b58d6
DV
10babel --retain-lines src --out-dir dist/src
11babel --retain-lines auto_tests/tests --out-dir dist/auto_tests/tests
ff876d52
DV
12
13# Instrument the source code with Istanbul's __coverage__ variable.
14rm -rf coverage/* # Clear out everything to ensure a hermetic run.
15mkdir -p coverage
16istanbul instrument --output coverage/src dist/src
17cp -r dist/auto_tests coverage/
18
19# Build a combined file for running the tests in-browser
20browserify coverage/auto_tests/tests/*.js -o coverage/tests.js
21
22# Run http-server and save its PID for cleanup
23http-server > /dev/null &
24SERVER_PID=$!
25function finish() {
26 kill -TERM $SERVER_PID
27}
28trap finish EXIT
29
30# Give the server a chance to start up
31sleep 1
32
33# Run the tests using mocha-phantomjs & mocha-phantomjs-istanbul
34# This produces coverage/coverage.json
35phantomjs \
36 ./node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee \
37 http://localhost:8080/auto_tests/coverage.html \
38 spec '{"hooks": "mocha-phantomjs-istanbul", "coverageFile": "coverage/coverage.json"}'
39
40if [ $CI ]; then
41 # Convert the JSON coverage to LCOV for coveralls.
42 istanbul report --include coverage/*.json lcovonly
43
44 # Monkey patch in the untransformed source paths.
843b58d6 45 perl -i -pe 's,dist/,,' coverage/lcov.info
ff876d52
DV
46 echo '' # reset exit code -- failure to post coverage shouldn't be an error.
47
48else
49
50 # Convert the JSON coverage to HTML for viewing
51 istanbul report --include coverage/*.json html
52 set +x
53
54 echo 'To browse coverage, run:'
55 echo
56 echo ' open coverage/index.html'
57 echo
58
59fi