Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 655c9f5

Browse files
feat: analyze command tests
1 parent 1cded23 commit 655c9f5

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/analyze.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { ACTION_ANALYZE } from "../utils/constants";
2+
import { executeCommand } from "./test-utils";
3+
4+
describe("codiga analyze", () => {
5+
test("should catch an invalid directory", async () => {
6+
// run the command
7+
await executeCommand([ACTION_ANALYZE, "invalid-directory"]).catch(
8+
({ stderr }) => {
9+
expect(stderr).toMatch(/No such file or directory to analyze/);
10+
}
11+
);
12+
});
13+
14+
test("should catch when a file is specified without rulesets", async () => {
15+
// run the command
16+
await executeCommand([ACTION_ANALYZE, "tests/test-utils.js"]).catch(
17+
({ stderr }) => {
18+
expect(stderr).toMatch(/No rulesets were given to analyze this file/);
19+
}
20+
);
21+
});
22+
23+
test("1 invalid ruleset; 0 valid ruleset; should catch error", async () => {
24+
// run the command
25+
await executeCommand([
26+
ACTION_ANALYZE,
27+
"tests/test-utils.js",
28+
"--ruleset invalid-ruleset",
29+
]).catch(({ stderr }) => {
30+
expect(stderr).toMatch(/No valid rulesets were found to continue/);
31+
});
32+
});
33+
34+
test("1 invalid ruleset; 1 valid ruleset; should have invalid notice", async () => {
35+
// run the command
36+
await executeCommand([
37+
ACTION_ANALYZE,
38+
"tests/test-utils.js",
39+
"--ruleset invalid-ruleset",
40+
"--ruleset testing-ruleset-1",
41+
]).catch(({ stdout }) => {
42+
expect(stdout).toMatch(
43+
/The following rulesets either don't exist or you lack the permissions to access it/
44+
);
45+
expect(stdout).toMatch(/- invalid-ruleset/);
46+
});
47+
});
48+
});

0 commit comments

Comments
 (0)