From 4784ddd69a7906b90cabe10d2dd0c2d14634fc74 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Thu, 29 Jan 2026 21:56:51 +0000 Subject: [PATCH] test: verify referenced image file actually exists in output directory Improved test assertions to parse the actual src value from HTML and verify that the specific file exists in the output directory, rather than just checking that any file with the extension exists. Co-Authored-By: Claude Opus 4.5 --- test/regression/issue/26575.test.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/regression/issue/26575.test.ts b/test/regression/issue/26575.test.ts index d7e6c8b56f..bdc1a9768b 100644 --- a/test/regression/issue/26575.test.ts +++ b/test/regression/issue/26575.test.ts @@ -38,14 +38,15 @@ describe("issue #26575", () => { const cssContent = api.readFile("out/" + cssMatch![1]); expect(cssContent).toContain("data:image/webp;base64,"); - // The image file should still exist in the output directory for the HTML tag - const outputFiles = readdirSync(api.outdir); - const hasWebpFile = outputFiles.some(f => f.endsWith(".webp")); - expect(hasWebpFile).toBe(true); - // The HTML should reference the hashed image file (not inline it) - expect(htmlContent).toMatch(/src=".*\.webp"/); expect(htmlContent).not.toContain("data:image/webp"); + const imgSrcMatch = htmlContent.match(/src="(\.\/[^"]+\.webp)"/); + expect(imgSrcMatch).not.toBeNull(); + + // Verify the referenced image file actually exists in the output directory + const imgFilename = imgSrcMatch![1].replace("./", ""); + const outputFiles = readdirSync(api.outdir); + expect(outputFiles).toContain(imgFilename); }, }); @@ -78,13 +79,14 @@ describe("issue #26575", () => { expect(cssContent).not.toContain("data:image/png;base64,"); expect(cssContent).toMatch(/url\(".*\.png"\)/); - // The image file should exist in the output directory - const outputFiles = readdirSync(api.outdir); - const hasPngFile = outputFiles.some(f => f.endsWith(".png")); - expect(hasPngFile).toBe(true); - // The HTML should reference the hashed image file - expect(htmlContent).toMatch(/src=".*\.png"/); + const imgSrcMatch = htmlContent.match(/src="(\.\/[^"]+\.png)"/); + expect(imgSrcMatch).not.toBeNull(); + + // Verify the referenced image file actually exists in the output directory + const imgFilename = imgSrcMatch![1].replace("./", ""); + const outputFiles = readdirSync(api.outdir); + expect(outputFiles).toContain(imgFilename); }, }); });