Last active
October 23, 2015 08:05
-
-
Save electricessence/0a0076e86c436a2e5b03 to your computer and use it in GitHub Desktop.
Mocha Recusive Importer
This file contains hidden or 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
// How to use: | |
// 1) Place this in your test root for mocha. | |
// 2) Change the 'root' value below to match the path. | |
// 3) DO NOT configure mocha with --recursive | |
var fs = require("fs"); | |
var root = "./tests/mocha/"; | |
function getFilesAt(path, ext) { | |
return fs | |
.readdirSync(path) | |
.filter(function (name) { | |
return (!ext || name.lastIndexOf(ext) == name.length - ext.length) | |
&& fs.statSync(path + '/' + name).isFile(); | |
}); | |
} | |
function getDirectoriesAt(path) { | |
return fs | |
.readdirSync(path) | |
.filter(function (name) { return fs.statSync(path + '/' + name).isDirectory(); }); | |
} | |
function importRecursive(path, importFiles, base) { | |
if (path === void 0) { path = ""; } | |
if (importFiles === void 0) { importFiles = false; } | |
if (base === void 0) { base = ""; } | |
var dirPath = base + path; | |
if (importFiles) | |
console.log(dirPath); | |
getDirectoriesAt(root + dirPath) | |
.sort() | |
.forEach(function (dirname) { | |
describe(dirname, function () { | |
importRecursive(dirname, true, dirPath + '/'); | |
}); | |
}); | |
if (importFiles) { | |
getFilesAt(root + dirPath, '.js') | |
.sort() | |
.forEach(function (filename) { | |
var filePath = dirPath + '/' + filename; | |
console.log(" ", filename); | |
describe(filename.replace(/\.js$/, ''), function () { | |
require('./' + filePath); | |
}); | |
}); | |
} | |
} | |
console.log("Importing Tests:"); | |
importRecursive(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeScript source and in-use example.
https://github.com/electricessence/TypeScript.NET/blob/master/tests/mocha/import-tests.ts