forked from pnp/pnpjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.mocharc.js
67 lines (53 loc) · 1.83 KB
/
.mocharc.js
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
66
67
const yargs = require("yargs").argv;
const resolve = require("path").resolve;
const join = require("path").join;
const fs = require("fs");
const prettyjson = require("prettyjson");
function getAllPackageFolderNames() {
const root = resolve("./packages");
return fs.readdirSync(root).filter(dirName => {
const stat = fs.statSync(join(root, dirName));
return stat && stat.isDirectory();
});
}
let mode = "cmd";
let paths = ["./test/main.ts"];
// handle package specific config
if (yargs.packages || yargs.p) {
const packageNames = (yargs.packages || yargs.p).split(",").map(s => s.trim().toLowerCase());
const processingPackages = [];
for (let i = 0; i < packageNames.length; i++) {
// see of we have any package entries and pass them along as-is
const found = getAllPackageFolderNames().filter(p => {
return ((typeof p === "string" && p === packageNames[i]) || (p.name === packageNames[i]));
});
processingPackages.push(...found);
}
if (yargs.single || yargs.s) {
// and only a single set of tests
paths.push(resolve(`./test/${processingPackages[0]}/`, (yargs.single || yargs.s) + ".ts"));
} else {
paths.push(...processingPackages.map(p => `./test/${p}/**/*.ts`));
}
} else {
paths.push("./test/**/*.ts");
}
const reporter = yargs.verbose ? "spec" : "dot";
const config = {
package: "./package.json",
reporter: reporter,
slow: 3000,
timeout: 40000,
ui: "bdd",
retries: "2",
require: [
"tsconfig-paths/register",
"ts-node/register"
],
spec: paths,
};
console.info(`*****************************`);
console.info("pnp generated mocha config:");
console.info(prettyjson.render(config, null, 4, { noColor: true }));
console.info(`*****************************`);
module.exports = config;