diff --git a/.gitignore b/.gitignore index 588aee54..3ebd08b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules build/ sftp-config.json +coverage/ +temp/ diff --git a/Gruntfile.js b/Gruntfile.js index 7500d85c..f774df6f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,3 +1,5 @@ +/* global module */ + module.exports = function(grunt) { // ---------- @@ -5,7 +7,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks("grunt-contrib-concat"); grunt.loadNpmTasks("grunt-contrib-jshint"); grunt.loadNpmTasks("grunt-contrib-uglify"); - grunt.loadNpmTasks("grunt-contrib-qunit"); + grunt.loadNpmTasks("grunt-qunit-istanbul"); grunt.loadNpmTasks("grunt-contrib-connect"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks("grunt-contrib-clean"); @@ -72,6 +74,7 @@ module.exports = function(grunt) { clean: { build: ["build"], package: [packageDir], + coverage: ["coverage"], release: { src: [releaseRoot], options: { @@ -137,10 +140,26 @@ module.exports = function(grunt) { } }, qunit: { + normal: { + options: { + urls: [ "http://localhost:8000/test/test.html" ] + } + }, + coverage: { + options: { + urls: [ "http://localhost:8000/test/coverage.html" ], + coverage: { + src: ['src/*.js'], + htmlReport: 'coverage/html/', + instrumentedFiles: 'temp/', + baseUrl: '.', + disposeCollector: true + } + } + }, all: { options: { - timeout: 10000, - urls: [ "http://localhost:8000/test/test.html" ] + timeout: 10000 } } }, @@ -248,7 +267,12 @@ module.exports = function(grunt) { // ---------- // Test task. // Builds and runs unit tests. - grunt.registerTask("test", ["build", "connect", "qunit"]); + grunt.registerTask("test", ["build", "connect", "qunit:normal"]); + + // ---------- + // Coverage task. + // Outputs unit test code coverage report. + grunt.registerTask("coverage", ["clean:coverage", "connect", "qunit:coverage"]); // ---------- // Package task. diff --git a/README.md b/README.md index 71fafeca..75fc5c92 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,12 @@ and open `http://localhost:8000/test/test.html` in your browser. Another good page, if you want to interactively test out your changes, is `http://localhost:8000/test/demo/basic.html`. +You can also get a report of the tests' code coverage: + + grunt coverage + +The report shows up at `coverage/html/index.html` viewable in a browser. + ### Contributing OpenSeadragon is truly a community project; we welcome your involvement! diff --git a/package.json b/package.json index 486d8743..2b102600 100644 --- a/package.json +++ b/package.json @@ -10,11 +10,11 @@ "grunt-git-describe": "^2.3.2", "grunt-contrib-uglify": "^0.4.0", "grunt-contrib-watch": "^0.6.1", - "grunt-contrib-qunit": "^0.5.1", "grunt-contrib-jshint": "^0.10.0", "grunt-contrib-compress": "^0.9.1", "grunt-contrib-connect": "^0.7.1", - "qunitjs": "^1.14.0" + "qunitjs": "^1.14.0", + "grunt-qunit-istanbul": "^0.4.5" }, "scripts": { "test": "grunt test" diff --git a/test/coverage.html b/test/coverage.html new file mode 100644 index 00000000..ee23c1c5 --- /dev/null +++ b/test/coverage.html @@ -0,0 +1,76 @@ + + +
+ +