1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
"use strict";
var fs = require("fs");
var path = require("path");
module.exports = {
/**
* Loads the list of all available tests
*
* @param {string} rootDir
* @returns {Object.<string, string[]>}
*/
loadAllTests: function (rootDir) {
var testSuite = {};
var self = this;
this.getAllDirectories(rootDir).forEach(
function (language) {
testSuite[language] = self.getAllFiles(path.join(rootDir, language));
}
);
return testSuite;
},
/**
* Returns a list of all (sub)directories (just the directory names, not full paths)
* in the given src directory
*
* @param {string} src
* @returns {Array.<string>}
*/
getAllDirectories: function (src) {
return fs.readdirSync(src).filter(
function (file) {
return fs.statSync(path.join(src, file)).isDirectory();
}
);
},
/**
* Returns a list of all full file paths to all files in the given src directory
*
* @private
* @param {string} src
* @returns {Array.<string>}
*/
getAllFiles: function (src) {
return fs.readdirSync(src).filter(
function (fileName) {
// only find files that have the ".test" extension
return ".test" === path.extname(fileName) &&
fs.statSync(path.join(src, fileName)).isFile();
}
).map(
function (fileName) {
return path.join(src, fileName);
}
);
}
};