Skip to content

Commit 4ee1275

Browse files
test(jsweep): add comprehensive tests for error_codes.cjs (#30935)
1 parent 52f789b commit 4ee1275

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// @ts-check
2+
import { describe, it, expect } from "vitest";
3+
const { ERR_VALIDATION, ERR_PERMISSION, ERR_API, ERR_CONFIG, ERR_NOT_FOUND, ERR_PARSE, ERR_SYSTEM, SAFE_OUTPUT_E001, SAFE_OUTPUT_E099 } = require("./error_codes.cjs");
4+
5+
describe("error_codes", () => {
6+
describe("module exports", () => {
7+
it("exports all expected error codes", () => {
8+
expect(ERR_VALIDATION).toBeDefined();
9+
expect(ERR_PERMISSION).toBeDefined();
10+
expect(ERR_API).toBeDefined();
11+
expect(ERR_CONFIG).toBeDefined();
12+
expect(ERR_NOT_FOUND).toBeDefined();
13+
expect(ERR_PARSE).toBeDefined();
14+
expect(ERR_SYSTEM).toBeDefined();
15+
expect(SAFE_OUTPUT_E001).toBeDefined();
16+
expect(SAFE_OUTPUT_E099).toBeDefined();
17+
});
18+
19+
it("exports string values only", () => {
20+
const codes = [ERR_VALIDATION, ERR_PERMISSION, ERR_API, ERR_CONFIG, ERR_NOT_FOUND, ERR_PARSE, ERR_SYSTEM, SAFE_OUTPUT_E001, SAFE_OUTPUT_E099];
21+
for (const code of codes) {
22+
expect(typeof code).toBe("string");
23+
}
24+
});
25+
});
26+
27+
describe("primary error codes", () => {
28+
it("ERR_VALIDATION is 'ERR_VALIDATION'", () => {
29+
expect(ERR_VALIDATION).toBe("ERR_VALIDATION");
30+
});
31+
32+
it("ERR_PERMISSION is 'ERR_PERMISSION'", () => {
33+
expect(ERR_PERMISSION).toBe("ERR_PERMISSION");
34+
});
35+
36+
it("ERR_API is 'ERR_API'", () => {
37+
expect(ERR_API).toBe("ERR_API");
38+
});
39+
40+
it("ERR_CONFIG is 'ERR_CONFIG'", () => {
41+
expect(ERR_CONFIG).toBe("ERR_CONFIG");
42+
});
43+
44+
it("ERR_NOT_FOUND is 'ERR_NOT_FOUND'", () => {
45+
expect(ERR_NOT_FOUND).toBe("ERR_NOT_FOUND");
46+
});
47+
48+
it("ERR_PARSE is 'ERR_PARSE'", () => {
49+
expect(ERR_PARSE).toBe("ERR_PARSE");
50+
});
51+
52+
it("ERR_SYSTEM is 'ERR_SYSTEM'", () => {
53+
expect(ERR_SYSTEM).toBe("ERR_SYSTEM");
54+
});
55+
});
56+
57+
describe("legacy safe-output codes", () => {
58+
it("SAFE_OUTPUT_E001 is 'E001'", () => {
59+
expect(SAFE_OUTPUT_E001).toBe("E001");
60+
});
61+
62+
it("SAFE_OUTPUT_E099 is 'E099'", () => {
63+
expect(SAFE_OUTPUT_E099).toBe("E099");
64+
});
65+
});
66+
67+
describe("usage as error message prefixes", () => {
68+
it("can be used as a prefix in an Error message", () => {
69+
const err = new Error(`${ERR_VALIDATION}: Missing required field: title`);
70+
expect(err.message).toBe("ERR_VALIDATION: Missing required field: title");
71+
});
72+
73+
it("can be used as a prefix in a setFailed-style string", () => {
74+
const msg = `${ERR_CONFIG}: GH_AW_PROMPT environment variable is not set`;
75+
expect(msg).toBe("ERR_CONFIG: GH_AW_PROMPT environment variable is not set");
76+
});
77+
78+
it("all primary codes are distinct from each other", () => {
79+
const primary = [ERR_VALIDATION, ERR_PERMISSION, ERR_API, ERR_CONFIG, ERR_NOT_FOUND, ERR_PARSE, ERR_SYSTEM];
80+
const unique = new Set(primary);
81+
expect(unique.size).toBe(primary.length);
82+
});
83+
84+
it("legacy codes are distinct from primary codes", () => {
85+
const all = [ERR_VALIDATION, ERR_PERMISSION, ERR_API, ERR_CONFIG, ERR_NOT_FOUND, ERR_PARSE, ERR_SYSTEM, SAFE_OUTPUT_E001, SAFE_OUTPUT_E099];
86+
const unique = new Set(all);
87+
expect(unique.size).toBe(all.length);
88+
});
89+
});
90+
});

0 commit comments

Comments
 (0)