2016-07-30 18:14:42 +02:00
|
|
|
var finder = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2017-01-08 09:36:18 +01:00
|
|
|
var _ = require('node_modules/underscore/underscore.js');
|
2016-07-30 18:14:42 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
exports.find_files_to_run = function () {
|
|
|
|
var oneFileFilter = [];
|
|
|
|
var 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)
|
|
|
|
.filter(function (filename) {return (/[.]js$/).test(filename);})
|
|
|
|
.map(function (filename) {return 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)
|
|
|
|
var tests_dir = __dirname.replace(/zjsunit/, 'node_tests');
|
|
|
|
|
|
|
|
var tests = fs.readdirSync(tests_dir)
|
2018-05-07 01:50:14 +02:00
|
|
|
.filter(function (filename) {return !(/^\./i).test(filename);})
|
|
|
|
.filter(function (filename) {return (/\.js$/i).test(filename);})
|
|
|
|
.map(function (filename) {return filename.replace(/\.js$/i, '');});
|
2016-07-30 18:14:42 +02:00
|
|
|
|
|
|
|
if (oneFileFilter.length > 0) {
|
|
|
|
tests = tests.filter(function (filename) {
|
|
|
|
return oneFileFilter.indexOf(filename) !== -1;
|
|
|
|
});
|
|
|
|
testsDifference = _.difference(oneFileFilter, tests);
|
|
|
|
}
|
|
|
|
|
|
|
|
testsDifference.forEach(function (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();
|
|
|
|
|
|
|
|
var files = tests.map(function (fn) {
|
|
|
|
var obj = {};
|
|
|
|
obj.name = fn;
|
|
|
|
obj.full_name = path.join(tests_dir, fn);
|
|
|
|
return obj;
|
|
|
|
});
|
|
|
|
|
|
|
|
return files;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
module.exports = finder;
|