Skip to content

Instantly share code, notes, and snippets.

@domenic
Created March 16, 2012 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domenic/2050479 to your computer and use it in GitHub Desktop.
Save domenic/2050479 to your computer and use it in GitHub Desktop.
Drop-in coveraje
"use strict";
var coveraje = require("coveraje");
var fs = require("fs");
var path = require("path");
var rel = path.relative(process.cwd(), __dirname);
function moduleId(filename) {
return filename.slice(0, -1 * ".js".length);
}
function getTestsMap() {
function runTests(file) {
return function (context) {
return coveraje.runHelper("mocha", {
// TODO: read these from mocha.opts.
reporter: "spec",
require: ["test/testSetup"]
}).run(path.join(rel, file));
};
}
// TODO: these manual exclusions are stupid, except perhaps mocha.opts.
var nonTestFileNames = ["mocha.opts", "coveraje.js", "testSetup.js"];
var testFileNames = fs.readdirSync(__dirname).filter(function (fileName) {
return nonTestFileNames.indexOf(fileName) === -1;
});
var tests = {};
testFileNames.forEach(function (fileName) {
tests[moduleId(fileName)] = runTests(fileName);
});
return tests;
}
function getLibRequiresString() {
// TODO: need to recurse, handle subdirectories.
var libFileNames = fs.readdirSync(path.resolve(__dirname, "..", "lib"));
return libFileNames.map(function (fileName) {
return "require('../lib/" + moduleId(fileName) + "');";
}).join("\n");
}
coveraje.cover(
getLibRequiresString(),
getTestsMap(),
{
useServer: true,
globals: "node",
resolveRequires: ["*"]
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment