From: Dan Vanderkam Date: Fri, 23 Oct 2015 23:20:54 +0000 (-0400) Subject: Generate code coverage with Istanbul X-Git-Tag: v2.0.0~38^2~7 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=ff876d52415b6d4299771c751a9f0267dec9791c;p=dygraphs.git Generate code coverage with Istanbul --- diff --git a/.gitignore b/.gitignore index 01b10ac..b904bed 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ docs/options.html node_modules env dist +coverage diff --git a/.travis.yml b/.travis.yml index a2ac109..a16a7b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,6 @@ script: > npm run build && npm run build-tests && npm run test && + npm run coverage && curl -O https://raw.githubusercontent.com/danvk/travis-weigh-in/master/weigh_in.py && python weigh_in.py dist/dygraph-combined.js diff --git a/auto_tests/chrome.karma.conf.js b/auto_tests/chrome.karma.conf.js deleted file mode 100644 index 0caceb6..0000000 --- a/auto_tests/chrome.karma.conf.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = function (config) { - config.set({ - basePath: '../', - frameworks: [ - 'mocha', - 'chai' - ], - files: [ - 'dist/dygraph-combined-dev.js', - 'src/extras/smooth-plotter.js', - 'src/extras/synchronizer.js', - 'auto_tests/data/*.js', - 'auto_tests/tests/*.js', - ], - autoWatch: true, - singleRun: false, - reporters: ['mocha'], // or 'dots', 'mocha', 'spec' - browsers: ['Chrome'], // or 'Firefox', 'Safari', etc. - plugins: [ - 'karma-mocha', - 'karma-chai-plugins', - 'karma-chrome-launcher', - 'karma-firefox-launcher', - 'karma-spec-reporter', - 'karma-mocha-reporter' - ] - }); -}; diff --git a/auto_tests/coverage.html b/auto_tests/coverage.html new file mode 100644 index 0000000..0457347 --- /dev/null +++ b/auto_tests/coverage.html @@ -0,0 +1,66 @@ + + + + dygraphs tests + + + +
+
+ + + + + + + + + + + + + + + + + + + + + diff --git a/auto_tests/karma.conf.js b/auto_tests/karma.conf.js deleted file mode 100644 index 09d0596..0000000 --- a/auto_tests/karma.conf.js +++ /dev/null @@ -1,38 +0,0 @@ -module.exports = function (config) { - config.set({ - basePath: '../', - frameworks: [ - 'mocha', - 'chai' - ], - files: [ - 'dist/dygraph-combined-dev.js', - 'src/extras/smooth-plotter.js', - 'src/extras/synchronizer.js', - 'auto_tests/data/*.js', - 'auto_tests/tests/*.js', - ], - autoWatch: false, - singleRun: true, - reporters: ['mocha', 'coverage'], // or 'dots', 'mocha', 'spec' - preprocessors: { - 'dist/dygraph-combined-dev.js': ['coverage'] - }, - coverageReporter: { - dir: 'dist/coverage', - reporters: [ - { type: 'html', subdir: 'report-html' }, - { type: 'lcovonly', subdir: 'report-lcov' }, - ] - }, - browsers: ['PhantomJS'], - plugins: [ - 'karma-mocha', - 'karma-chai-plugins', - 'karma-phantomjs-launcher', - 'karma-coverage', - 'karma-spec-reporter', - 'karma-mocha-reporter' - ] - }); -}; diff --git a/auto_tests/runner.html b/auto_tests/runner.html index 7102a95..c3a3d87 100644 --- a/auto_tests/runner.html +++ b/auto_tests/runner.html @@ -56,7 +56,11 @@ diff --git a/package.json b/package.json index b60a8fb..9250bb7 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ }, "homepage": "https://github.com/danvk/dygraphs", "devDependencies": { + "babel": "^5.8.23", "babel-core": "^5.8.25", "babelify": "^6.3.0", "browserify": "^11.2.0", @@ -35,10 +36,12 @@ "envify": "^3.4.0", "exorcist": "^0.4.0", "http-server": "^0.8.5", + "istanbul": "^0.4.0", "jshint": "^2.5.10", "lcov-parse": "0.0.9", "mocha": "^2.1.0", - "mocha-phantomjs": "^4.0.1", + "mocha-phantomjs": "3.5.3", + "mocha-phantomjs-istanbul": "0.0.2", "obvious-closure-library": "^20140401.0.2", "parse-data-uri": "^0.2.0", "phantomjs": "^1.9.7-8", @@ -49,6 +52,7 @@ }, "scripts": { "build": "./scripts/build.sh", + "coverage": "./scripts/generate-coverage.sh", "watch": "./scripts/watch.sh", "build-tests": "./scripts/build-tests.sh", "test": "./scripts/run-tests.sh", diff --git a/scripts/generate-coverage.sh b/scripts/generate-coverage.sh new file mode 100755 index 0000000..e2343de --- /dev/null +++ b/scripts/generate-coverage.sh @@ -0,0 +1,59 @@ +#!/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 + +# Generate per-file ES6 --> ES5 transpilations +babel src --out-dir dist/src +babel auto_tests/tests --out-dir dist/auto_tests/tests + +# Instrument the source code with Istanbul's __coverage__ variable. +rm -rf coverage/* # Clear out everything to ensure a hermetic run. +mkdir -p coverage +istanbul instrument --output coverage/src dist/src +cp -r dist/auto_tests coverage/ + +# Build a combined file for running the tests in-browser +browserify coverage/auto_tests/tests/*.js -o coverage/tests.js + +# Run http-server and save its PID for cleanup +http-server > /dev/null & +SERVER_PID=$! +function finish() { + kill -TERM $SERVER_PID +} +trap finish EXIT + +# Give the server a chance to start up +sleep 1 + +# 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/auto_tests/coverage.html \ + spec '{"hooks": "mocha-phantomjs-istanbul", "coverageFile": "coverage/coverage.json"}' + +if [ $CI ]; then + # 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 + echo '' # reset exit code -- failure to post coverage shouldn't be an error. + +else + + # Convert the JSON coverage to HTML for viewing + istanbul report --include coverage/*.json html + set +x + + echo 'To browse coverage, run:' + echo + echo ' open coverage/index.html' + echo + +fi diff --git a/src/dygraph-combined.js b/src/dygraph-combined.js deleted file mode 100644 index e6380de..0000000 --- a/src/dygraph-combined.js +++ /dev/null @@ -1,7 +0,0 @@ -This is not the file you are looking for. -A reasonably up-to-date version can be found at http://dygraphs.com/dygraph-combined.js - -dygraph-combined.js is a "packed" version of the larger dygraphs JS files. It is -smaller and loads more quickly, but is harder to debug. - -To generate this file, run "make" or generate-combined.sh.