-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.test.js
More file actions
80 lines (68 loc) · 2.25 KB
/
cli.test.js
File metadata and controls
80 lines (68 loc) · 2.25 KB
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
import { match, ok, strictEqual } from "node:assert";
import { execFile } from "node:child_process";
import { resolve } from "node:path";
import test from "node:test";
import { promisify } from "node:util";
const execFileAsync = promisify(execFile);
const cli = resolve(import.meta.dirname, "cli.js");
const fixture = (name) => resolve(import.meta.dirname, "__test__", name);
const run = (...args) =>
execFileAsync("node", [cli, ...args], { cwd: import.meta.dirname });
test("cli validate (default) with --valid and valid schema", async () => {
const { stdout } = await run(fixture("simple.schema.json"), "--valid");
ok(stdout.includes("valid"));
});
test("cli validate with test data and --valid", async () => {
const { stdout } = await run(
fixture("simple.schema.json"),
"-d",
fixture("simple.data.json"),
"--valid",
);
ok(stdout.includes("valid"));
});
test("cli validate with invalid data and --invalid", async () => {
const { stdout } = await run(
fixture("simple.schema.json"),
"-d",
fixture("invalid.data.json"),
"--invalid",
);
ok(stdout.includes("invalid"));
});
test("cli transpile command", async () => {
const { stdout } = await run("transpile", fixture("simple.schema.json"));
ok(stdout.length > 0);
});
test("cli deref command", async () => {
const { stdout } = await run("deref", fixture("simple.schema.json"));
ok(stdout.length > 0);
});
test("cli sast command with secure schema", async () => {
const { stdout } = await run("sast", fixture("secure.schema.json"));
ok(stdout.length > 0);
});
test("cli sast command with insecure schema and --fail should exit 1", async () => {
try {
await run("sast", fixture("insecure.schema.json"), "--fail");
throw new Error("Expected process to exit with code 1");
} catch (e) {
strictEqual(e.code, 1);
}
});
test("cli ftl command", async () => {
const { stdout } = await run("ftl", fixture("hello.ftl"), "--locale", "en");
ok(stdout.length > 0);
});
test("cli missing input file should error", async () => {
try {
await run(fixture("nonexistent.json"), "--valid");
throw new Error("Expected process to exit with non-zero code");
} catch (e) {
ok(e.code !== 0);
}
});
test("cli --help should print usage", async () => {
const { stdout } = await run("--help");
match(stdout, /Usage/);
});