Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
4,299 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
module.exports = function (grunt) { | ||
|
||
var istanbul = require('istanbul'); | ||
|
||
grunt.loadNpmTasks('grunt-mocha'); | ||
|
||
grunt.initConfig({ | ||
|
||
mocha: { | ||
test: { | ||
src: 'test/index.html', | ||
options: { | ||
reporter: 'Spec', | ||
run: false, | ||
log: true | ||
} | ||
} | ||
}, | ||
|
||
test: { | ||
options: { | ||
template: 'test/index.template.html', | ||
runner: 'test/index.html', | ||
files: 'test/spec/**/*' | ||
} | ||
}, | ||
|
||
coverage: { | ||
|
||
// when the coverage object is received | ||
// from grunt-mocha it will be saved here | ||
coverage: null, | ||
|
||
instrument: { | ||
|
||
// files to NOT instrument eg. libs | ||
// these files will be copied "as is" | ||
ignore: [ | ||
'src/js/lib/**/*' | ||
], | ||
|
||
// files to instrument | ||
files: [ | ||
{ | ||
src: '**/*.js', | ||
expand: true, | ||
cwd: 'dist', | ||
dest: 'test/src' | ||
} | ||
] | ||
}, | ||
|
||
// task for generating reports | ||
report: { | ||
reports: ['html', 'text-summary'], | ||
dest: 'test/reports' | ||
} | ||
} | ||
|
||
}); | ||
|
||
grunt.event.on('coverage', function (coverage) { | ||
grunt.config('coverage.coverage', coverage); | ||
}); | ||
|
||
grunt.registerMultiTask('coverage', 'Generates coverage reports for JS using Istanbul', function () { | ||
|
||
if (this.target === 'instrument') { | ||
|
||
var ignore = this.data.ignore || []; | ||
var instrumenter = new istanbul.Instrumenter(); | ||
|
||
this.files.forEach(function (file) { | ||
|
||
var src = file.src[0], | ||
instrumented = grunt.file.read(src); | ||
|
||
// only instrument this file if it is not in ignored list | ||
if (!grunt.file.isMatch(ignore, src)) { | ||
instrumented = instrumenter.instrumentSync(instrumented, src); | ||
} | ||
|
||
// write | ||
grunt.file.write(file.dest, instrumented); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
if (this.target === 'report') { | ||
|
||
this.requiresConfig('coverage.coverage'); | ||
|
||
var Report = istanbul.Report; | ||
var Collector = istanbul.Collector; | ||
var reporters = this.data.reports; | ||
var dest = this.data.dest; | ||
var collector = new Collector(); | ||
|
||
// fetch the coverage object we saved earlier | ||
collector.add(grunt.config('coverage.coverage')); | ||
|
||
reporters.forEach(function (reporter) { | ||
|
||
Report.create(reporter, { | ||
dir: dest + '/' + reporter | ||
}).writeReport(collector, true); | ||
|
||
}); | ||
|
||
return; | ||
} | ||
|
||
grunt.warn('Unknown target - valid targets are "instrument" and "report"'); | ||
}); | ||
|
||
grunt.registerTask('test', 'Run JS Unit tests', function () { | ||
|
||
var options = this.options(); | ||
|
||
var tests = grunt.file.expand(options.files).map(function(file) { | ||
return '../' + file; | ||
}); | ||
|
||
// build the template | ||
var template = grunt.file.read(options.template) | ||
.replace('{{ tests }}', JSON.stringify(tests)); | ||
|
||
// write template to tests directory and run tests | ||
grunt.file.write(options.runner, template); | ||
grunt.task.run('coverage:instrument', 'mocha', 'coverage:report'); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Mocha</title> | ||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css"> | ||
<script src="../node_modules/mocha/mocha.js"></script> | ||
<script src="../node_modules/expect.js/index.js"></script> | ||
<script src="../node_modules/sinon/pkg/sinon.js"></script> | ||
<script src="../node_modules/requirejs/require.js"></script> | ||
</head> | ||
<body> | ||
|
||
<div id="mocha"></div> | ||
|
||
<script> | ||
|
||
mocha.setup('bdd'); | ||
|
||
require.config({ | ||
|
||
baseUrl: 'src', | ||
|
||
deps: ["../test/spec/test.js"], | ||
|
||
callback: mocha.run | ||
|
||
}); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Mocha</title> | ||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css"> | ||
<script src="../node_modules/mocha/mocha.js"></script> | ||
<script src="../node_modules/expect.js/index.js"></script> | ||
<script src="../node_modules/sinon/pkg/sinon.js"></script> | ||
<script src="../node_modules/requirejs/require.js"></script> | ||
</head> | ||
<body> | ||
|
||
<div id="mocha"></div> | ||
|
||
<script> | ||
|
||
mocha.setup('bdd'); | ||
|
||
require.config({ | ||
|
||
baseUrl: 'src', | ||
|
||
deps: {{ tests }}, | ||
|
||
callback: mocha.run | ||
|
||
}); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.