-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.js
44 lines (38 loc) · 1.25 KB
/
util.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
"use strict";
const chai = require("chai");
const flag = chai.util.flag;
const util = module.exports = {
/**
* Determines whether the given value is a CLI object
*/
isCLI (cli) {
return cli &&
typeof cli === "object" &&
typeof cli.command === "string" &&
Array.isArray(cli.args);
},
/**
* Sets multiple assertion flags at once, and returns commonly-used flags
*
* @param {chai.Assertion} assertion - The Assertion to get/set flags for
* @param {object} [flags] - A map of flag names and values to set
* @returns {object} - A map of flag names and values, including commonly-used flags
*/
flags (assertion, flags = {}) {
// Set all the flags
for (let key of Object.keys(flags)) {
flag(assertion, key, flags[key]);
}
// Always return these flags
flags.object = flags.object || flag(assertion, "object");
flags.cli = flags.cli || flag(assertion, "cli");
flags.message = flags.message || flag(assertion, "message");
// If the "cli" flag isn't set, and the "object" flag is a CLI object,
// then go ahead and set the "cli" flag
if (!flags.cli && util.isCLI(flags.object)) {
flag(assertion, "cli", flags.object);
flags.cli = flags.object;
}
return flags;
},
};