-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
48 lines (42 loc) · 1.28 KB
/
index.test.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
const test = require("ava");
const fs = require("fs");
const path = require("path");
const { CommandBuilder, run } = require("./index.js");
test("exports CommandBuilder class and run() function", (t) => {
t.truthy(isClass(CommandBuilder));
t.is(typeof run, "function");
});
test("builds command with args", (t) => {
const command = new CommandBuilder("foo", [
"file.text",
"--flag-1",
"--flag-2",
"-a",
]);
t.is(String(command), "foo file.text --flag-1 --flag-2 -a");
});
test("adds flag with arg() method", (t) => {
const command = new CommandBuilder("foo");
command.arg("--hello");
t.is(String(command), "foo --hello");
});
test("arg() adds flag only when provided condition is truthy", (t) => {
const watch = true;
const quiet = false;
const command = new CommandBuilder("foo");
command.arg("--watch", watch);
command.arg("--quiet", quiet);
t.is(String(command), "foo --watch");
});
test("runs command", async (t) => {
const command = new CommandBuilder("echo 'hello, world!'");
const { stdout } = await command.run();
t.is(stdout, "hello, world!");
});
// https://zaiste.net/posts/javascript-class-function/
function isClass(value) {
return (
typeof value === "function" &&
/^class\s/.test(Function.prototype.toString.call(value))
);
}