-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
81 lines (72 loc) · 2.41 KB
/
index.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"use strict";
const ezSpawn = require("@jsdevtools/ez-spawn");
const applyDefaults = require("./apply-defaults");
const normalizeResults = require("./normalize-results");
module.exports = chaiExecSync;
module.exports.chaiExecSync = chaiExecSync;
module.exports.chaiExecAsync = chaiExecAsync;
chaiExecSync.defaults = {};
chaiExecAsync.defaults = {};
/**
* The Chai-Exec plugin
*
* @param {object} chai - The ChaiJS module
* @param {object} util - ChaiJS utility functions
*/
function chaiExecPlugin (chai, util) {
// Add each of the Chai-Exec sub-modules to Chai
require("./exit-code")(chai, util);
require("./stdio")(chai, util);
}
/**
* Synchronously executes the specified CLI and returns the results
*
* @param {string|string[]} command - The command to execute
* @param {string[]} [args] - Command-line arguments to pass to the command
* @param {object} [options] - EZ-Spawn options
* @returns {object} - An EZ-Spawn Process object, or a ProcessError object
*/
function chaiExecSync (command, args, options) { // eslint-disable-line no-unused-vars
if (isChai(command)) {
// Just register the Chai-Exec plugin and exit
return chaiExecPlugin(...arguments);
}
try {
args = applyDefaults(chaiExecSync.defaults, arguments);
let process = ezSpawn.sync(...args);
return normalizeResults(process);
}
catch (error) {
return normalizeResults(error);
}
}
/**
* Asynchronously executes the specified CLI and returns the results via a Promise
*
* @param {string|string[]} command - The command to execute
* @param {string[]} [args] - Command-line arguments to pass to the command
* @param {object} [options] - EZ-Spawn options
* @returns {Promise} - A Promise that resolves with an EZ-Spawn Process object, or a ProcessError object
*/
function chaiExecAsync (command, args, options) { // eslint-disable-line no-unused-vars
if (isChai(command)) {
// Just register the Chai-Exec plugin and exit
return chaiExecPlugin(...arguments);
}
args = applyDefaults(chaiExecAsync.defaults, arguments);
return ezSpawn.async(...args)
.then(
(process) => normalizeResults(process),
(error) => normalizeResults(error)
);
}
/**
* Determines whether the given value is the ChaiJS module
*/
function isChai (chai) {
return chai &&
typeof chai === "object" &&
typeof chai.assert === "function" &&
typeof chai.expect === "function" &&
typeof chai.should === "function";
}