-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
·51 lines (42 loc) · 1.23 KB
/
run
File metadata and controls
executable file
·51 lines (42 loc) · 1.23 KB
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
#!/usr/bin/env node
var fs = require("fs");
var path = require("path");
var program = require("commander");
program
.version("0.1.0")
.option("-t, --trials <n>", "Trials for each test (who support it)", 200, parseInt)
.option("-f, --functions <functions>", "Run only some function codes", "")
.option("-r, --reporter <reporter>", "Set test reporter", "progress")
.parse(process.argv);
exports.trials = function () {
return program.trials;
};
program.functions = (program.functions.length ? program.functions.trim().split(/\s*,\s*/) : []);
start();
function start() {
var Mocha = require("mocha");
var mocha = new Mocha({
reporter: program.reporter
});
var location = path.normalize(__dirname);
var added = 0;
fs.readdirSync(location).filter(function (file) {
if (file.substr(-3) != '.js') {
return false;
}
if (program.functions.length) {
return (program.functions.indexOf(file.substr(0, file.length - 3)) >= 0);
}
return true;
}).forEach(function (file) {
mocha.addFile(path.join(location, file));
added += 1;
});
if (added === 0) {
process.stderr.write("No tests runned. Remove or broad your filters.\n");
process.exit(1);
}
mocha.run(function (failures) {
process.exit(failures);
});
}