From: Dan Vanderkam Date: Sat, 6 Dec 2014 19:14:41 +0000 (-0500) Subject: Add tools and instructions for code coverage X-Git-Tag: v2.0.0~81^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=refs%2Fheads%2Fjstd-coverage;p=dygraphs.git Add tools and instructions for code coverage --- diff --git a/auto_tests/README b/auto_tests/README index d07f2e5..d0f34f4 100644 --- a/auto_tests/README +++ b/auto_tests/README @@ -56,3 +56,37 @@ reference for ensuring Dygraphs automated tests pass. http://code.google.com/p/js-test-driver/wiki/GettingStarted. They're listed as a courtesy, but you really should get to understand js-test-driver, which has lots of powerful features.) + + +Code Coverage +------------- + +To generate code coverage data, start the jstd test server: + + $ java -jar ./auto_tests/lib/JsTestDriver-1.3.3c.jar --port 9876 + +Then run the tests with the --outputCoverage option: + + $ java -jar ./auto_tests/lib/JsTestDriver-1.3.3c.jar --tests all --testOutput . + +This can take a few minutes. It will spew out gobs of XML files, which should +be deleted. The one file you care about is jsTestDriver.conf-coverage.dat. It +contains LCOV-format coverage data. It contains coverage data for _all_ JS +files, including the tests themselves and library code which is irrelevant for +coverage analysis. So you need to filter it down: + + $ cat jsTestDriver.conf-coverage.dat | ./auto_tests/misc/filter-lcov.py + +To post the coverage data to coveralls, you'll need to export a few environment +variables and install node-coveralls: + + $ npm install # installs node-coveralls, which is listed in package.json + $ export COVERALLS_SERVICE_NAME=jstd + $ export COVERALLS_REPO_TOKEN=... # get this by visiting http://coveralls.io + $ export COVERALLS_GIT_COMMIT=$(git rev-parse HEAD) + $ cat jsTestDriver.conf-coverage.dat \ + | ./auto_tests/misc/filter-lcov.py \ + | ./node_modules/coveralls/bin/coveralls.js + +If all goes well, you should see your coverage data posted at +https://coveralls.io/r/danvk/dygraphs. diff --git a/auto_tests/lib/coverage-1.3.5.jar b/auto_tests/lib/coverage-1.3.5.jar new file mode 100644 index 0000000..a54010d Binary files /dev/null and b/auto_tests/lib/coverage-1.3.5.jar differ diff --git a/auto_tests/misc/filter-lcov.py b/auto_tests/misc/filter-lcov.py new file mode 100755 index 0000000..2d95a3a --- /dev/null +++ b/auto_tests/misc/filter-lcov.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +"""Remove unwanted files from LCOV data. + +jstd and node-coveralls won't do this themselves, so we have to! + +Usage: + cat lcov.dat | ./filter-lcov.py > filtered-lcov.dat +""" + +import fileinput +import re + +# Exclude paths which match any of these regular expressions. +exclude_res = [ + re.compile(r'auto_tests') +] + +def is_ok(path): + for regex in exclude_res: + if re.search(regex, path): + return False + return True + + +writing = False +for line in fileinput.input(): + line = line.strip(); + if line.startswith('SF:'): + path = line[3:] + writing = is_ok(path) + if writing: + print line diff --git a/jsTestDriver.conf b/jsTestDriver.conf index b735bda..ec581b3 100644 --- a/jsTestDriver.conf +++ b/jsTestDriver.conf @@ -24,5 +24,11 @@ load: - datahandler/bars-error.js - datahandler/bars-custom.js - datahandler/bars-fractions.js + - extras/smooth-plotter.js - auto_tests/tests/*.js - auto_tests/lib/jquery-1.4.2.js + +plugin: + - name: "coverage" + jar: "auto_tests/lib/coverage-1.3.5.jar" + module: "com.google.jstestdriver.coverage.CoverageModule" diff --git a/package.json b/package.json index 84948e9..25aff77 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "homepage": "https://github.com/danvk/dygraphs", "devDependencies": { "closure-compiler": "^0.2.6", + "coveralls": "^2.11.2", "jshint": "^2.5.10", "obvious-closure-library": "^20140401.0.2", "phantomjs": "^1.9.7-8",