diff --git a/example/test/e2e/imageSizeTest.spec.mjs b/example/test/e2e/imageSizeTest.spec.mjs index 136b410..9a5a017 100644 --- a/example/test/e2e/imageSizeTest.spec.mjs +++ b/example/test/e2e/imageSizeTest.spec.mjs @@ -169,7 +169,17 @@ const correctSrcRemoteImage = { 2048: `http://localhost:8080${basePath}/nextImageExportOptimizer/5206242668571649-opt-2048.WEBP`, 3840: `http://localhost:8080${basePath}/nextImageExportOptimizer/5206242668571649-opt-3840.WEBP`, }; - +const correctSrcRemoteImageWithQueryParams = { + 640: `http://localhost:8080${basePath}/nextImageExportOptimizer/6725071117443837-opt-640.WEBP`, + 750: `http://localhost:8080${basePath}/nextImageExportOptimizer/6725071117443837-opt-750.WEBP`, + 777: `http://localhost:8080${basePath}/nextImageExportOptimizer/6725071117443837-opt-777.WEBP`, + 828: `http://localhost:8080${basePath}/nextImageExportOptimizer/6725071117443837-opt-828.WEBP`, + 1080: `http://localhost:8080${basePath}/nextImageExportOptimizer/6725071117443837-opt-1080.WEBP`, + 1200: `http://localhost:8080${basePath}/nextImageExportOptimizer/6725071117443837-opt-1200.WEBP`, + 1920: `http://localhost:8080${basePath}/nextImageExportOptimizer/6725071117443837-opt-1920.WEBP`, + 2048: `http://localhost:8080${basePath}/nextImageExportOptimizer/6725071117443837-opt-2048.WEBP`, + 3840: `http://localhost:8080${basePath}/nextImageExportOptimizer/6725071117443837-opt-3840.WEBP`, +}; const correctSrcAnimatedPNGImage = { 640: `http://localhost:8080${basePath}/nextImageExportOptimizer/animated.c00e0188-opt-128.${ imagesWebP ? "WEBP" : "PNG" @@ -696,9 +706,30 @@ for (let index = 0; index < widths.length; index++) { // check the number of images on the page const images = await page.$$("img"); - expect(images.length).toBe(1); + expect(images.length).toBe(2); const srcset = generateSrcset(widths, correctSrcRemoteImage); expect(image.srcset).toBe(srcset); + + const img_query = await page.locator("#test_image_queryParam"); + await img_query.click(); + + const image_query = await getImageById(page, "test_image_queryParam"); + expect(image_query.currentSrc).toBe( + correctSrcRemoteImageWithQueryParams[width.toString()] + ); + expect(image_query.naturalWidth).toBe(width >= 2048 ? 2048 : width); + await expect(img_query).toHaveCSS("position", "absolute"); + await expect(img_query).not.toHaveCSS( + "background-image", + `url("/images/nextImageExportOptimizer/transparentImage-opt-10.WEBP")` + ); + await expect(img_query).not.toHaveCSS("background-repeat", "no-repeat"); + + const srcset_query = generateSrcset( + widths, + correctSrcRemoteImageWithQueryParams + ); + expect(image_query.srcset).toBe(srcset_query); }); test("should check the image size for the animated test page", async ({ page, diff --git a/test/__snapshots__/optimizeImages.test.js.snap b/test/__snapshots__/optimizeImages.test.js.snap index 83b3f4d..af89176 100644 --- a/test/__snapshots__/optimizeImages.test.js.snap +++ b/test/__snapshots__/optimizeImages.test.js.snap @@ -115,6 +115,24 @@ exports[`legacyConfig 2`] = ` "5206242668571649-opt-777.WEBP", "5206242668571649-opt-828.WEBP", "5206242668571649-opt-96.WEBP", + "6725071117443837-opt-10.WEBP", + "6725071117443837-opt-1080.WEBP", + "6725071117443837-opt-1200.WEBP", + "6725071117443837-opt-128.WEBP", + "6725071117443837-opt-16.WEBP", + "6725071117443837-opt-1920.WEBP", + "6725071117443837-opt-2048.WEBP", + "6725071117443837-opt-256.WEBP", + "6725071117443837-opt-32.WEBP", + "6725071117443837-opt-384.WEBP", + "6725071117443837-opt-3840.WEBP", + "6725071117443837-opt-48.WEBP", + "6725071117443837-opt-64.WEBP", + "6725071117443837-opt-640.WEBP", + "6725071117443837-opt-750.WEBP", + "6725071117443837-opt-777.WEBP", + "6725071117443837-opt-828.WEBP", + "6725071117443837-opt-96.WEBP", "animated.c00e0188-opt-10.PNG", "animated.c00e0188-opt-128.PNG", "animated.c00e0188-opt-16.PNG", @@ -313,6 +331,24 @@ exports[`legacyConfig 5`] = ` "5206242668571649-opt-777.WEBP", "5206242668571649-opt-828.WEBP", "5206242668571649-opt-96.WEBP", + "6725071117443837-opt-10.WEBP", + "6725071117443837-opt-1080.WEBP", + "6725071117443837-opt-1200.WEBP", + "6725071117443837-opt-128.WEBP", + "6725071117443837-opt-16.WEBP", + "6725071117443837-opt-1920.WEBP", + "6725071117443837-opt-2048.WEBP", + "6725071117443837-opt-256.WEBP", + "6725071117443837-opt-32.WEBP", + "6725071117443837-opt-384.WEBP", + "6725071117443837-opt-3840.WEBP", + "6725071117443837-opt-48.WEBP", + "6725071117443837-opt-64.WEBP", + "6725071117443837-opt-640.WEBP", + "6725071117443837-opt-750.WEBP", + "6725071117443837-opt-777.WEBP", + "6725071117443837-opt-828.WEBP", + "6725071117443837-opt-96.WEBP", "animated.c00e0188-opt-10.PNG", "animated.c00e0188-opt-128.PNG", "animated.c00e0188-opt-16.PNG", @@ -948,6 +984,96 @@ exports[`legacyConfig 8`] = ` exports[`legacyConfig 9`] = ` [ + [ + "webp", + 10, + 7, + ], + [ + "webp", + 1080, + 719, + ], + [ + "webp", + 1200, + 799, + ], + [ + "webp", + 128, + 85, + ], + [ + "webp", + 16, + 11, + ], + [ + "webp", + 1920, + 1278, + ], + [ + "webp", + 2048, + 1363, + ], + [ + "webp", + 256, + 170, + ], + [ + "webp", + 32, + 21, + ], + [ + "webp", + 384, + 256, + ], + [ + "webp", + 2048, + 1363, + ], + [ + "webp", + 48, + 32, + ], + [ + "webp", + 64, + 43, + ], + [ + "webp", + 640, + 426, + ], + [ + "webp", + 750, + 499, + ], + [ + "webp", + 777, + 517, + ], + [ + "webp", + 828, + 551, + ], + [ + "webp", + 96, + 64, + ], [ "webp", 10, @@ -1441,6 +1567,24 @@ exports[`newConfig 2`] = ` "5206242668571649-opt-777.WEBP", "5206242668571649-opt-828.WEBP", "5206242668571649-opt-96.WEBP", + "6725071117443837-opt-10.WEBP", + "6725071117443837-opt-1080.WEBP", + "6725071117443837-opt-1200.WEBP", + "6725071117443837-opt-128.WEBP", + "6725071117443837-opt-16.WEBP", + "6725071117443837-opt-1920.WEBP", + "6725071117443837-opt-2048.WEBP", + "6725071117443837-opt-256.WEBP", + "6725071117443837-opt-32.WEBP", + "6725071117443837-opt-384.WEBP", + "6725071117443837-opt-3840.WEBP", + "6725071117443837-opt-48.WEBP", + "6725071117443837-opt-64.WEBP", + "6725071117443837-opt-640.WEBP", + "6725071117443837-opt-750.WEBP", + "6725071117443837-opt-777.WEBP", + "6725071117443837-opt-828.WEBP", + "6725071117443837-opt-96.WEBP", "animated.c00e0188-opt-10.WEBP", "animated.c00e0188-opt-128.WEBP", "animated.c00e0188-opt-16.WEBP", @@ -1639,6 +1783,24 @@ exports[`newConfig 5`] = ` "5206242668571649-opt-777.WEBP", "5206242668571649-opt-828.WEBP", "5206242668571649-opt-96.WEBP", + "6725071117443837-opt-10.WEBP", + "6725071117443837-opt-1080.WEBP", + "6725071117443837-opt-1200.WEBP", + "6725071117443837-opt-128.WEBP", + "6725071117443837-opt-16.WEBP", + "6725071117443837-opt-1920.WEBP", + "6725071117443837-opt-2048.WEBP", + "6725071117443837-opt-256.WEBP", + "6725071117443837-opt-32.WEBP", + "6725071117443837-opt-384.WEBP", + "6725071117443837-opt-3840.WEBP", + "6725071117443837-opt-48.WEBP", + "6725071117443837-opt-64.WEBP", + "6725071117443837-opt-640.WEBP", + "6725071117443837-opt-750.WEBP", + "6725071117443837-opt-777.WEBP", + "6725071117443837-opt-828.WEBP", + "6725071117443837-opt-96.WEBP", "animated.c00e0188-opt-10.WEBP", "animated.c00e0188-opt-128.WEBP", "animated.c00e0188-opt-16.WEBP", @@ -2364,6 +2526,96 @@ exports[`newConfig 9`] = ` 96, 64, ], + [ + "webp", + 10, + 7, + ], + [ + "webp", + 1080, + 719, + ], + [ + "webp", + 1200, + 799, + ], + [ + "webp", + 128, + 85, + ], + [ + "webp", + 16, + 11, + ], + [ + "webp", + 1920, + 1278, + ], + [ + "webp", + 2048, + 1363, + ], + [ + "webp", + 256, + 170, + ], + [ + "webp", + 32, + 21, + ], + [ + "webp", + 384, + 256, + ], + [ + "webp", + 2048, + 1363, + ], + [ + "webp", + 48, + 32, + ], + [ + "webp", + 64, + 43, + ], + [ + "webp", + 640, + 426, + ], + [ + "webp", + 750, + 499, + ], + [ + "webp", + 777, + 517, + ], + [ + "webp", + 828, + 551, + ], + [ + "webp", + 96, + 64, + ], [ "webp", 10, @@ -2767,6 +3019,24 @@ exports[`newConfigBasePath 2`] = ` "5206242668571649-opt-777.WEBP", "5206242668571649-opt-828.WEBP", "5206242668571649-opt-96.WEBP", + "6725071117443837-opt-10.WEBP", + "6725071117443837-opt-1080.WEBP", + "6725071117443837-opt-1200.WEBP", + "6725071117443837-opt-128.WEBP", + "6725071117443837-opt-16.WEBP", + "6725071117443837-opt-1920.WEBP", + "6725071117443837-opt-2048.WEBP", + "6725071117443837-opt-256.WEBP", + "6725071117443837-opt-32.WEBP", + "6725071117443837-opt-384.WEBP", + "6725071117443837-opt-3840.WEBP", + "6725071117443837-opt-48.WEBP", + "6725071117443837-opt-64.WEBP", + "6725071117443837-opt-640.WEBP", + "6725071117443837-opt-750.WEBP", + "6725071117443837-opt-777.WEBP", + "6725071117443837-opt-828.WEBP", + "6725071117443837-opt-96.WEBP", "animated.c00e0188-opt-10.WEBP", "animated.c00e0188-opt-128.WEBP", "animated.c00e0188-opt-16.WEBP", @@ -2965,6 +3235,24 @@ exports[`newConfigBasePath 5`] = ` "5206242668571649-opt-777.WEBP", "5206242668571649-opt-828.WEBP", "5206242668571649-opt-96.WEBP", + "6725071117443837-opt-10.WEBP", + "6725071117443837-opt-1080.WEBP", + "6725071117443837-opt-1200.WEBP", + "6725071117443837-opt-128.WEBP", + "6725071117443837-opt-16.WEBP", + "6725071117443837-opt-1920.WEBP", + "6725071117443837-opt-2048.WEBP", + "6725071117443837-opt-256.WEBP", + "6725071117443837-opt-32.WEBP", + "6725071117443837-opt-384.WEBP", + "6725071117443837-opt-3840.WEBP", + "6725071117443837-opt-48.WEBP", + "6725071117443837-opt-64.WEBP", + "6725071117443837-opt-640.WEBP", + "6725071117443837-opt-750.WEBP", + "6725071117443837-opt-777.WEBP", + "6725071117443837-opt-828.WEBP", + "6725071117443837-opt-96.WEBP", "animated.c00e0188-opt-10.WEBP", "animated.c00e0188-opt-128.WEBP", "animated.c00e0188-opt-16.WEBP", @@ -3690,6 +3978,96 @@ exports[`newConfigBasePath 9`] = ` 96, 64, ], + [ + "webp", + 10, + 7, + ], + [ + "webp", + 1080, + 719, + ], + [ + "webp", + 1200, + 799, + ], + [ + "webp", + 128, + 85, + ], + [ + "webp", + 16, + 11, + ], + [ + "webp", + 1920, + 1278, + ], + [ + "webp", + 2048, + 1363, + ], + [ + "webp", + 256, + 170, + ], + [ + "webp", + 32, + 21, + ], + [ + "webp", + 384, + 256, + ], + [ + "webp", + 2048, + 1363, + ], + [ + "webp", + 48, + 32, + ], + [ + "webp", + 64, + 43, + ], + [ + "webp", + 640, + 426, + ], + [ + "webp", + 750, + 499, + ], + [ + "webp", + 777, + 517, + ], + [ + "webp", + 828, + 551, + ], + [ + "webp", + 96, + 64, + ], [ "webp", 10, @@ -4093,6 +4471,24 @@ exports[`newConfigExportFolderName 2`] = ` "5206242668571649-opt-777.WEBP", "5206242668571649-opt-828.WEBP", "5206242668571649-opt-96.WEBP", + "6725071117443837-opt-10.WEBP", + "6725071117443837-opt-1080.WEBP", + "6725071117443837-opt-1200.WEBP", + "6725071117443837-opt-128.WEBP", + "6725071117443837-opt-16.WEBP", + "6725071117443837-opt-1920.WEBP", + "6725071117443837-opt-2048.WEBP", + "6725071117443837-opt-256.WEBP", + "6725071117443837-opt-32.WEBP", + "6725071117443837-opt-384.WEBP", + "6725071117443837-opt-3840.WEBP", + "6725071117443837-opt-48.WEBP", + "6725071117443837-opt-64.WEBP", + "6725071117443837-opt-640.WEBP", + "6725071117443837-opt-750.WEBP", + "6725071117443837-opt-777.WEBP", + "6725071117443837-opt-828.WEBP", + "6725071117443837-opt-96.WEBP", "animated.c00e0188-opt-10.PNG", "animated.c00e0188-opt-128.PNG", "animated.c00e0188-opt-16.PNG", @@ -4291,6 +4687,24 @@ exports[`newConfigExportFolderName 5`] = ` "5206242668571649-opt-777.WEBP", "5206242668571649-opt-828.WEBP", "5206242668571649-opt-96.WEBP", + "6725071117443837-opt-10.WEBP", + "6725071117443837-opt-1080.WEBP", + "6725071117443837-opt-1200.WEBP", + "6725071117443837-opt-128.WEBP", + "6725071117443837-opt-16.WEBP", + "6725071117443837-opt-1920.WEBP", + "6725071117443837-opt-2048.WEBP", + "6725071117443837-opt-256.WEBP", + "6725071117443837-opt-32.WEBP", + "6725071117443837-opt-384.WEBP", + "6725071117443837-opt-3840.WEBP", + "6725071117443837-opt-48.WEBP", + "6725071117443837-opt-64.WEBP", + "6725071117443837-opt-640.WEBP", + "6725071117443837-opt-750.WEBP", + "6725071117443837-opt-777.WEBP", + "6725071117443837-opt-828.WEBP", + "6725071117443837-opt-96.WEBP", "animated.c00e0188-opt-10.PNG", "animated.c00e0188-opt-128.PNG", "animated.c00e0188-opt-16.PNG", @@ -4489,6 +4903,24 @@ exports[`newConfigJpeg 2`] = ` "5206242668571649-opt-777.WEBP", "5206242668571649-opt-828.WEBP", "5206242668571649-opt-96.WEBP", + "6725071117443837-opt-10.WEBP", + "6725071117443837-opt-1080.WEBP", + "6725071117443837-opt-1200.WEBP", + "6725071117443837-opt-128.WEBP", + "6725071117443837-opt-16.WEBP", + "6725071117443837-opt-1920.WEBP", + "6725071117443837-opt-2048.WEBP", + "6725071117443837-opt-256.WEBP", + "6725071117443837-opt-32.WEBP", + "6725071117443837-opt-384.WEBP", + "6725071117443837-opt-3840.WEBP", + "6725071117443837-opt-48.WEBP", + "6725071117443837-opt-64.WEBP", + "6725071117443837-opt-640.WEBP", + "6725071117443837-opt-750.WEBP", + "6725071117443837-opt-777.WEBP", + "6725071117443837-opt-828.WEBP", + "6725071117443837-opt-96.WEBP", "animated.c00e0188-opt-10.PNG", "animated.c00e0188-opt-128.PNG", "animated.c00e0188-opt-16.PNG", @@ -4687,6 +5119,24 @@ exports[`newConfigJpeg 5`] = ` "5206242668571649-opt-777.WEBP", "5206242668571649-opt-828.WEBP", "5206242668571649-opt-96.WEBP", + "6725071117443837-opt-10.WEBP", + "6725071117443837-opt-1080.WEBP", + "6725071117443837-opt-1200.WEBP", + "6725071117443837-opt-128.WEBP", + "6725071117443837-opt-16.WEBP", + "6725071117443837-opt-1920.WEBP", + "6725071117443837-opt-2048.WEBP", + "6725071117443837-opt-256.WEBP", + "6725071117443837-opt-32.WEBP", + "6725071117443837-opt-384.WEBP", + "6725071117443837-opt-3840.WEBP", + "6725071117443837-opt-48.WEBP", + "6725071117443837-opt-64.WEBP", + "6725071117443837-opt-640.WEBP", + "6725071117443837-opt-750.WEBP", + "6725071117443837-opt-777.WEBP", + "6725071117443837-opt-828.WEBP", + "6725071117443837-opt-96.WEBP", "animated.c00e0188-opt-10.PNG", "animated.c00e0188-opt-128.PNG", "animated.c00e0188-opt-16.PNG", @@ -5322,6 +5772,96 @@ exports[`newConfigJpeg 8`] = ` exports[`newConfigJpeg 9`] = ` [ + [ + "webp", + 10, + 7, + ], + [ + "webp", + 1080, + 719, + ], + [ + "webp", + 1200, + 799, + ], + [ + "webp", + 128, + 85, + ], + [ + "webp", + 16, + 11, + ], + [ + "webp", + 1920, + 1278, + ], + [ + "webp", + 2048, + 1363, + ], + [ + "webp", + 256, + 170, + ], + [ + "webp", + 32, + 21, + ], + [ + "webp", + 384, + 256, + ], + [ + "webp", + 2048, + 1363, + ], + [ + "webp", + 48, + 32, + ], + [ + "webp", + 64, + 43, + ], + [ + "webp", + 640, + 426, + ], + [ + "webp", + 750, + 499, + ], + [ + "webp", + 777, + 517, + ], + [ + "webp", + 828, + 551, + ], + [ + "webp", + 96, + 64, + ], [ "webp", 10,