Repository navigation
Expand file tree
/
Copy pathcli.test.js
More file actions
62 lines (53 loc) · 1.82 KB
/
Copy pathcli.test.js
File metadata and controls
62 lines (53 loc) · 1.82 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
import { test, expect } from "vitest";
import fs from "node:fs/promises";
import { createRequire } from "node:module";
import path from "node:path";
import { git } from "@commitlint/test";
import { x } from "tinyexec";
const require = createRequire(import.meta.url);
const bin = require.resolve("./cli.js");
const cli = (args, options) => {
return (input = "") => {
const result = x(bin, args, {
nodeOptions: {
cwd: options.cwd,
env: options.env,
},
});
result.process.stdin.write(input);
result.process.stdin.end();
return result;
};
};
test("should print warning if stage is empty", async () => {
const cwd = await git.bootstrap();
const actual = await cli([], { cwd })("foo: bar");
expect(actual.stdout).toContain("Nothing to commit.");
expect(actual.stderr).toBe("");
}, 10000);
const stage = async (cwd) => {
await fs.writeFile(path.join(cwd, "file.txt"), "content");
await x("git", ["add", "file.txt"], { nodeOptions: { cwd } });
};
test.each(["--config", "-g"])(
"should show the resolved path of a missing %s file",
async (flag) => {
const cwd = await git.bootstrap();
await stage(cwd);
const actual = await cli([flag, "missing.config.js"], { cwd })();
expect(actual.stderr).toContain(path.join(cwd, "missing.config.js"));
},
10000,
);
test("should apply the rules of the config file given via --config", async () => {
const cwd = await git.bootstrap();
await stage(cwd);
// Not one of the places a config is searched in by default.
await fs.mkdir(path.join(cwd, "config"));
await fs.writeFile(
path.join(cwd, "config", "custom.config.mjs"),
`export default { rules: { "type-enum": [2, "always", ["alpha", "beta"]] } };`,
);
const actual = await cli(["--config", "config/custom.config.mjs"], { cwd })("wrong\n");
expect(actual.stdout).toContain("must be one of alpha, beta");
}, 10000);