Skip to content

Commit 7ee29f4

Browse files
committed
test(main): cover the download and copy error-status paths
Exercises the toBlob-fails and clipboard.write-rejects branches of download()/copyImage(), which were previously only reachable by inspection. Also scopes coverage collection to src/** so tooling config files don't skew the report.
1 parent 296ef57 commit 7ee29f4

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

test/main.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,35 @@ describe("app bootstrap and generate flow", () => {
230230
expect(writtenItems).not.toBeNull();
231231
expect(document.getElementById("output-status").textContent).toMatch(/copied/i);
232232
});
233+
234+
it("shows a designed error status when the download blob export fails", async () => {
235+
document.getElementById("before-input").value = "const x = 1;";
236+
document.getElementById("after-input").value = "const x = 2;";
237+
const { api } = await loadMain();
238+
api.generate();
239+
240+
HTMLCanvasElement.prototype.toBlob = function toBlob(callback) {
241+
callback(null);
242+
};
243+
244+
await api.download();
245+
246+
expect(document.getElementById("output-status").textContent).toMatch(/couldn't download/i);
247+
});
248+
249+
it("shows a designed error status when the clipboard write rejects", async () => {
250+
stubClipboardApis({
251+
write: async () => {
252+
throw new Error("clipboard denied");
253+
},
254+
});
255+
document.getElementById("before-input").value = "const x = 1;";
256+
document.getElementById("after-input").value = "const x = 2;";
257+
const { api } = await loadMain();
258+
api.generate();
259+
260+
await api.copyImage();
261+
262+
expect(document.getElementById("output-status").textContent).toMatch(/couldn't copy/i);
263+
});
233264
});

vitest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ export default defineConfig({
99
// vitest's default include glob would otherwise try (and fail) to
1010
// collect them as unit tests.
1111
exclude: ["**/node_modules/**", "e2e/**"],
12+
coverage: {
13+
// Coverage should measure app source, not tooling config files that
14+
// happen to sit at the repo root (vite/vitest/playwright configs).
15+
include: ["src/**"],
16+
},
1217
},
1318
});

0 commit comments

Comments
 (0)