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.
This commit is contained in:
daniel-lxs 2025-10-28 13:46:11 -05:00
parent c445cfe4c7
commit f3b31d7a53
No known key found for this signature in database
GPG key ID: 21C74479048B3AA6

View file

@ -18,6 +18,33 @@ describe("normalizeImageRefsToDataUrls", () => {
expect(result).toEqual([dataUrl])
})
it("should convert CDN webview URIs to data URLs", async () => {
const cdnUri = "https://file+.vscode-resource.vscode-cdn.net/path/to/test.png"
const mockBuffer = Buffer.from("test image data")
vi.mocked(fs.readFile).mockResolvedValue(mockBuffer)
const result = await normalizeImageRefsToDataUrls([cdnUri])
expect(result).toHaveLength(1)
expect(result[0]).toMatch(/^data:image\/png;base64,/)
expect(fs.readFile).toHaveBeenCalledWith("/path/to/test.png")
})
it("should handle mixed arrays of data URLs and CDN URIs", async () => {
const dataUrl = "data:image/jpeg;base64,test123"
const cdnUri = "https://file+.vscode-resource.vscode-cdn.net/path/to/test.png"
const mockBuffer = Buffer.from("test image data")
vi.mocked(fs.readFile).mockResolvedValue(mockBuffer)
const result = await normalizeImageRefsToDataUrls([dataUrl, cdnUri])
expect(result).toHaveLength(2)
expect(result[0]).toBe(dataUrl) // Data URL unchanged
expect(result[1]).toMatch(/^data:image\/png;base64,/) // CDN URI converted
})
it("should handle errors gracefully by skipping problematic images", async () => {
const validDataUrl = "data:image/png;base64,valid"
const invalidCdnUri = "vscode-file://vscode-app/nonexistent/test.png"