Debian Codegraph @

bin/tad.js

raw
1 #!/usr/bin/env node
2
3 "use strict";
4
5 require("essentials");
6
7 var compact = require("es5-ext/array/#/compact")
8 , flatten = require("es5-ext/array/#/flatten")
9 , endsWith = require("es5-ext/string/#/ends-with")
10 , deferred = require("deferred")
11 , path = require("path")
12 , findRoot = require("next/module/find-package-root")
13 , readdir = require("fs2/readdir")
14 , stat = require("fs2/stat")
15 , argv = require("optimist")
16 .usage("Usage: $0 [options] [paths]")
17 .boolean(["a", "m"])
18 .describe("a", "Display all tests names, including passed")
19 .describe("m", "Minimise output, verbose only for fails or errors").argv;
20
21 var extname = path.extname
22 , resolve = path.resolve
23 , initSuite = require("..");
24
25 if (!argv._.length) argv._ = ["."];
26
27 require("../lib/tad-ignore-mode");
28
29 deferred
30 .map(argv._, function (inputPath) {
31 if (inputPath !== ".") return inputPath;
32 inputPath = resolve(".");
33 return findRoot(resolve(inputPath, "x"))(function (root) {
34 if (root !== inputPath) return inputPath;
35 return readdir(inputPath, {
36 type: { file: true, directory: true },
37 ignoreRules: ["git", "tad"]
38 })
39 .map(function (name) {
40 var filename = resolve(inputPath, name);
41 return stat(resolve(inputPath, name))(function (stats) {
42 if (stats.isDirectory()) {
43 if (name === "node_modules") return null;
44 if (name === "bin") return null;
45 if (name === "test") return null;
46 if (name === "examples") return null;
47 return filename;
48 }
49 if (extname(name) !== ".js") return null;
50 if (name[0] === ".") return null;
51 if (endsWith.call(name, ".config.js")) return null;
52 return filename;
53 });
54 })
55 .invoke(compact);
56 });
57 })(function (paths) {
58 return initSuite(
59 flatten.call(paths), argv
60 )(function (suite) {
61 var suiteConsole = suite.console;
62 process.on("exit", function () {
63 if (suiteConsole.errored) process.exitCode = 2;
64 else if (suiteConsole.failed) process.exitCode = 1;
65 });
66 });
67 })
68 .done();