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

Commit 5125caa

Browse files
feat: add yaml parsing tests
1 parent f8cf53f commit 5125caa

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

tests/test-utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ export const TEST_USER = {
1212
accountType: "Github",
1313
};
1414

15+
export const CODIGA_CONFIG_MISSING_RULESETS = `
16+
`;
17+
18+
export const CODIGA_CONFIG_MISSING_RULESETS_LIST = `
19+
rulesets:
20+
`;
21+
22+
export const CODIGA_CONFIG_MISSING_RULESETS_VALID = `
23+
rulesets:
24+
- react-best-practices
25+
- jsx-a11y
26+
`;
27+
1528
export const executeCommand = async (args) => {
1629
try {
1730
return child_process.execSync(`codiga ${args.join(" ")}`, {

tests/yaml.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { parseYamlFile } from "../utils/file";
2+
import {
3+
CODIGA_CONFIG_MISSING_RULESETS,
4+
CODIGA_CONFIG_MISSING_RULESETS_LIST,
5+
CODIGA_CONFIG_MISSING_RULESETS_VALID,
6+
} from "./test-utils";
7+
8+
test("parse missing `rulesets:` correctly", async () => {
9+
expect(parseYamlFile(CODIGA_CONFIG_MISSING_RULESETS)).toBe(null);
10+
});
11+
12+
test("parse missing rulesets list correctly", async () => {
13+
expect(parseYamlFile(CODIGA_CONFIG_MISSING_RULESETS_LIST)).toEqual({
14+
rulesets: null,
15+
});
16+
});
17+
18+
test("parse a valid file accurately", async () => {
19+
expect(parseYamlFile(CODIGA_CONFIG_MISSING_RULESETS_VALID)).toEqual({
20+
rulesets: ["react-best-practices", "jsx-a11y"],
21+
});
22+
});

0 commit comments

Comments
 (0)