Skip to content

Commit f3b31d7

Browse files
committed
test(images): add CDN URI conversion tests for normalizeImageRefsToDataUrls
Add test coverage for HTTPS CDN URL conversion (e.g., https://file+.vscode-resource.vscode-cdn.net/...) to base64 data URLs. This covers the critical URI-to-base64 conversion flow that was previously only tested with legacy file:// URIs.
1 parent c445cfe commit f3b31d7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/integrations/misc/__tests__/imageDataUrl.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@ describe("normalizeImageRefsToDataUrls", () => {
1818
expect(result).toEqual([dataUrl])
1919
})
2020

21+
it("should convert CDN webview URIs to data URLs", async () => {
22+
const cdnUri = "https://file+.vscode-resource.vscode-cdn.net/path/to/test.png"
23+
const mockBuffer = Buffer.from("test image data")
24+
25+
vi.mocked(fs.readFile).mockResolvedValue(mockBuffer)
26+
27+
const result = await normalizeImageRefsToDataUrls([cdnUri])
28+
29+
expect(result).toHaveLength(1)
30+
expect(result[0]).toMatch(/^data:image\/png;base64,/)
31+
expect(fs.readFile).toHaveBeenCalledWith("/path/to/test.png")
32+
})
33+
34+
it("should handle mixed arrays of data URLs and CDN URIs", async () => {
35+
const dataUrl = "data:image/jpeg;base64,test123"
36+
const cdnUri = "https://file+.vscode-resource.vscode-cdn.net/path/to/test.png"
37+
const mockBuffer = Buffer.from("test image data")
38+
39+
vi.mocked(fs.readFile).mockResolvedValue(mockBuffer)
40+
41+
const result = await normalizeImageRefsToDataUrls([dataUrl, cdnUri])
42+
43+
expect(result).toHaveLength(2)
44+
expect(result[0]).toBe(dataUrl) // Data URL unchanged
45+
expect(result[1]).toMatch(/^data:image\/png;base64,/) // CDN URI converted
46+
})
47+
2148
it("should handle errors gracefully by skipping problematic images", async () => {
2249
const validDataUrl = "data:image/png;base64,valid"
2350
const invalidCdnUri = "vscode-file://vscode-app/nonexistent/test.png"

0 commit comments

Comments
 (0)