2020-07-15 01:29:15 +02:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2016-07-30 18:14:42 +02:00
|
|
|
|
2020-07-24 06:02:07 +02:00
|
|
|
const _ = require("underscore/underscore.js");
|
|
|
|
|
2016-07-30 18:14:42 +02:00
|
|
|
exports.find_files_to_run = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
let oneFileFilter = [];
|
|
|
|
let testsDifference = [];
|
2016-08-26 04:49:43 +02:00
|
|
|
if (process.argv[2]) {
|
2016-07-30 18:14:42 +02:00
|
|
|
oneFileFilter = process.argv
|
2018-05-07 01:50:14 +02:00
|
|
|
.slice(2)
|
2020-07-15 00:34:28 +02:00
|
|
|
.filter((filename) => /[.]js$/.test(filename))
|
2020-07-15 01:29:15 +02:00
|
|
|
.map((filename) => filename.replace(/\.js$/i, ""));
|
2016-07-30 18:14:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// tests_dir is where we find our specific unit tests (as opposed
|
|
|
|
// to framework code)
|
2020-07-15 01:29:15 +02:00
|
|
|
const tests_dir = __dirname.replace(/zjsunit/, "node_tests");
|
2016-07-30 18:14:42 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
let tests = fs
|
|
|
|
.readdirSync(tests_dir)
|
|
|
|
.filter((filename) => !/^\./i.test(filename))
|
|
|
|
.filter((filename) => /\.js$/i.test(filename))
|
2020-07-15 01:29:15 +02:00
|
|
|
.map((filename) => filename.replace(/\.js$/i, ""));
|
2016-07-30 18:14:42 +02:00
|
|
|
|
|
|
|
if (oneFileFilter.length > 0) {
|
2020-07-02 01:45:54 +02:00
|
|
|
tests = tests.filter((filename) => oneFileFilter.includes(filename));
|
2016-07-30 18:14:42 +02:00
|
|
|
testsDifference = _.difference(oneFileFilter, tests);
|
|
|
|
}
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
testsDifference.forEach((filename) => {
|
2018-06-06 18:19:09 +02:00
|
|
|
throw filename + ".js does not exist";
|
2016-07-30 18:14:42 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
tests.sort();
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
const files = tests.map((fn) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const obj = {};
|
2016-07-30 18:14:42 +02:00
|
|
|
obj.name = fn;
|
|
|
|
obj.full_name = path.join(tests_dir, fn);
|
|
|
|
return obj;
|
|
|
|
});
|
|
|
|
|
|
|
|
return files;
|
|
|
|
};
|