diff --git a/.gitignore b/.gitignore index 319ae8d..a905ca8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ node_modules .DS_Store .gitignore npm-debug.log +examples/coverage/tmp +examples/coverage/instrumented diff --git a/README.md b/README.md index a22b8c9..c0298b6 100644 --- a/README.md +++ b/README.md @@ -49,3 +49,22 @@ TAP file path ### Options See also [Configuration File](https://github.com/airportyh/testem#configuration-file) +It also accepts an `output.coverage` option that is the folder path where coverage reports are written. + +```js +grunt.initConfig({ + 'testem': { + options : { + output: { + coverage : 'coverage-results/' + } + }, + main : { + src: [ 'examples/*.html' ], + dest: 'tests.tap' + } + } +}); +``` + +Source files must be instrumented before running tests. An example on how to do it in grunt is available inside `examples/coverage`. diff --git a/examples/coverage/Gruntfile.js b/examples/coverage/Gruntfile.js new file mode 100644 index 0000000..36f672b --- /dev/null +++ b/examples/coverage/Gruntfile.js @@ -0,0 +1,54 @@ +module.exports = function(grunt) { + "use strict"; + + grunt.initConfig({ + testem: { + options : { + launch_in_ci : ['Chrome'], + output: { + coverage: 'tmp/coverage/from_browsers/' + }, + routes: { + "/lib": "../lib", + "/src": "instrumented" + } + }, + all : { + files : { + 'tmp/result.tap': ['test/index.html'] + } + } + }, + + clean: { + tests: ['tmp'] + }, + + // This section is to instrument files from grunt + shell: { + instrument: { + command: "istanbul instrument --output instrumented src" + }, + report: { + command: "istanbul report --root tmp/coverage/from_browsers --dir tmp/coverage lcov" + }, + options: { + stdout: true, + failOnError: true + } + } + }); + + // In real life replace this line: + grunt.loadTasks('../../tasks'); + // with + // grunt.loadNpmTasks('grunt-testem'); + + grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-shell'); + + + grunt.registerTask('test', ['clean', 'shell:instrument', 'testem', 'shell:report']); + grunt.registerTask('default', ['test']); + +}; diff --git a/examples/coverage/package.json b/examples/coverage/package.json new file mode 100644 index 0000000..6092cb0 --- /dev/null +++ b/examples/coverage/package.json @@ -0,0 +1,18 @@ +{ + "name": "grunt-testem-coverage-example", + "description": "A grunt plugin for testem using code coverage.", + "version": "0.0.0-whatever", + "homepage": "https://github.com/sideroad/grunt-testem", + "repository": { + "type": "git", + "url": "git://github.com/sideroad/grunt-testem.git" + }, + "dependencies": { + "async": "~0.1.22", + "underscore": "~1.4.2", + "testem-multi": "~0.3.1", + "grunt-contrib-clean": "~0.4.0", + "grunt": "~0.4.2", + "grunt-shell": "~0.6.4" + } +} diff --git a/examples/coverage/src/hello.js b/examples/coverage/src/hello.js new file mode 100644 index 0000000..0bf72f1 --- /dev/null +++ b/examples/coverage/src/hello.js @@ -0,0 +1,3 @@ +function sayHello (name, capital) { + return "Hello " + (!!capital ? name.toUpperCase() : name); +} diff --git a/examples/coverage/test/index.html b/examples/coverage/test/index.html new file mode 100644 index 0000000..9f19a7f --- /dev/null +++ b/examples/coverage/test/index.html @@ -0,0 +1,20 @@ + + + + + QUnit Example + + + +
+ + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index c26968d..e871ccd 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "dependencies": { "async": "~0.1.22", "underscore": "~1.4.2", - "testem-multi": "~0.4.1" + "testem-multi": "~0.4.2" }, "devDependencies": { "grunt-contrib-clean": "~0.4.0",