Skip to content

Commit dbcf5e9

Browse files
[jsweep] Clean missing_messages_helper.cjs (#31161)
1 parent 9b622c2 commit dbcf5e9

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

actions/setup/js/missing_messages_helper.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
/**
23
* Missing Messages Helper
34
*

actions/setup/js/missing_messages_helper.test.cjs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { readFileSync } from "node:fs";
12
import { describe, it, expect, beforeEach } from "vitest";
23

34
describe("missing_messages_helper.cjs", () => {
@@ -9,6 +10,14 @@ describe("missing_messages_helper.cjs", () => {
910
helper.setCollectedMissings(null);
1011
});
1112

13+
describe("source metadata", () => {
14+
it("should keep TypeScript checking enabled", () => {
15+
const source = readFileSync(new URL("./missing_messages_helper.cjs", import.meta.url), "utf8");
16+
17+
expect(source.split(/\r?\n/, 1)[0]).toBe("// @ts-check");
18+
});
19+
});
20+
1221
describe("setCollectedMissings and getCollectedMissings", () => {
1322
it("should store and retrieve missing messages", () => {
1423
const { setCollectedMissings, getCollectedMissings } = helper;
@@ -115,5 +124,68 @@ describe("missing_messages_helper.cjs", () => {
115124
expect(result).toContain("Missing Data");
116125
expect(result).toContain("config");
117126
});
127+
128+
it("should handle noopMessages", () => {
129+
const { setCollectedMissings, getMissingInfoSections } = helper;
130+
const missings = {
131+
missingTools: [],
132+
missingData: [],
133+
noopMessages: [{ message: "No action needed" }],
134+
reportIncomplete: [],
135+
};
136+
137+
setCollectedMissings(missings);
138+
const result = getMissingInfoSections();
139+
140+
expect(result).toContain("No action needed");
141+
});
142+
143+
it("should handle reportIncomplete messages", () => {
144+
const { setCollectedMissings, getMissingInfoSections } = helper;
145+
const missings = {
146+
missingTools: [],
147+
missingData: [],
148+
reportIncomplete: [{ reason: "Task not finished" }],
149+
};
150+
151+
setCollectedMissings(missings);
152+
const result = getMissingInfoSections();
153+
154+
expect(result).toContain("Task not finished");
155+
});
156+
157+
it("should handle all fields simultaneously", () => {
158+
const { setCollectedMissings, getMissingInfoSections } = helper;
159+
const missings = {
160+
missingTools: [{ tool: "docker", reason: "Containers needed" }],
161+
missingData: [{ data_type: "token", reason: "Auth required" }],
162+
noopMessages: [{ message: "Skipped step" }],
163+
reportIncomplete: [{ reason: "Partial completion" }],
164+
};
165+
166+
setCollectedMissings(missings);
167+
const result = getMissingInfoSections();
168+
169+
expect(result).toContain("Missing Tools");
170+
expect(result).toContain("Missing Data");
171+
expect(result).toContain("No-Op Messages");
172+
expect(result).toContain("Incomplete Signals");
173+
expect(result).toContain("docker");
174+
expect(result).toContain("token");
175+
expect(result).toContain("Skipped step");
176+
expect(result).toContain("Partial completion");
177+
});
178+
179+
it("should reflect updates after setCollectedMissings is called again", () => {
180+
const { setCollectedMissings, getMissingInfoSections } = helper;
181+
182+
setCollectedMissings({ missingTools: [{ tool: "npm", reason: "Build tool" }], missingData: [] });
183+
const first = getMissingInfoSections();
184+
expect(first).toContain("npm");
185+
186+
setCollectedMissings({ missingTools: [], missingData: [] });
187+
const second = getMissingInfoSections();
188+
expect(second).toBe("");
189+
});
118190
});
119191
});

0 commit comments

Comments
 (0)