Skip to content

Instantly share code, notes, and snippets.

@WolfgangKluge
Created October 27, 2011 23:34
Show Gist options
  • Save WolfgangKluge/1321202 to your computer and use it in GitHub Desktop.
Save WolfgangKluge/1321202 to your computer and use it in GitHub Desktop.
jshint code coverage
#!/usr/bin/env node
(function () {
"use strict";
var coveraje = require("coveraje").coveraje,
fs = require("fs"),
path = require("path"),
jshfilePath = path.resolve("../jshint.js");
fs.readFile(jshfilePath, 'utf-8', function (err, data) {
function runTests(file) {
return function (context) {
// hack: set cache value
require.cache[jshfilePath] = {
id: jshfilePath,
exports: context,
loaded: true
};
return coveraje.runHelper("expresso").run(file);
};
}
if (err) throw err;
var tests = {};
fs.readdir('./', function (err, files) {
files.forEach(function (f) {
if (f.length > 2 && f.substr(f.length - 3, 3) === ".js") {
tests[f] = runTests('./' + f);
}
});
coveraje.cover(data, tests, {
useServer: true
});
});
});
return this;
}());
@WolfgangKluge
Copy link
Author

Get https://github.com/coveraje/coveraje
don't forget the submodules
add it to node_modules
Add this gist into ./tests folder of jshint and run it... ;)

@WolfgangKluge
Copy link
Author

Alternative

// move to projects folder
git clone git://github.com/coveraje/coveraje.git
cd coveraje
git submodule update --init
npm link

Add this gist into ./tests folder of jshint and run it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment