Created
March 16, 2012 15:11
-
-
Save domenic/2050479 to your computer and use it in GitHub Desktop.
Drop-in coveraje
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
"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