Skip to content

Commit

Permalink
Merge pull request #15 from piuccio/coverage
Browse files Browse the repository at this point in the history
Documentation on code coverage
  • Loading branch information
sideroad committed Apr 2, 2014
2 parents 821f04e + 9a55cf6 commit ccdb23b
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,5 @@ node_modules
.DS_Store
.gitignore
npm-debug.log
examples/coverage/tmp
examples/coverage/instrumented
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -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`.
54 changes: 54 additions & 0 deletions 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']);

};
18 changes: 18 additions & 0 deletions 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"
}
}
3 changes: 3 additions & 0 deletions examples/coverage/src/hello.js
@@ -0,0 +1,3 @@
function sayHello (name, capital) {
return "Hello " + (!!capital ? name.toUpperCase() : name);
}
20 changes: 20 additions & 0 deletions examples/coverage/test/index.html
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit Example</title>
<link rel="stylesheet" href="../../lib/qunit.css">
</head>
<body>
<div id="qunit"></div>
<script src="../../lib/qunit.js"></script>
<script src="/testem.js"></script>

<script src="../src/hello.js"></script>
<script>
test("say hello", function () {
equal(sayHello("testem-multi", true), "Hello TESTEM-MULTI");
})
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down

0 comments on commit ccdb23b

Please sign in to comment.