From 2cc30fc87aa3eec9c27cb528c2065ff4be99c4a6 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 22 Sep 2023 11:29:51 -0700 Subject: [PATCH] Update flakey next-image tests (#55838) x-ref: https://github.com/vercel/next.js/actions/runs/6277156082/job/17048498592 x-ref: https://github.com/vercel/next.js/actions/runs/6277508886/job/17049437197 --- .../base-path/test/index.test.ts | 40 ++++++++++----- .../default/test/index.test.ts | 50 +++++++++++++------ 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/test/integration/next-image-legacy/base-path/test/index.test.ts b/test/integration/next-image-legacy/base-path/test/index.test.ts index 07ab89fec5fa7..83de22dd8a751 100644 --- a/test/integration/next-image-legacy/base-path/test/index.test.ts +++ b/test/integration/next-image-legacy/base-path/test/index.test.ts @@ -176,9 +176,13 @@ function runTests(mode) { const height = 700 const delta = 250 const id = 'intrinsic1' - expect(await getSrc(browser, id)).toBe( - '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75' - ) + + await check(async () => { + expect(await getSrc(browser, id)).toBe( + '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75' + ) + return 'success' + }, 'success') expect(await browser.elementById(id).getAttribute('srcset')).toBe( '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=1200&q=75 1x, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75 2x' ) @@ -260,9 +264,13 @@ function runTests(mode) { const height = 350 const delta = 150 const id = 'fill1' - expect(await getSrc(browser, id)).toBe( - '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75' - ) + + await check(async () => { + expect(await getSrc(browser, id)).toBe( + '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75' + ) + return 'success' + }, 'success') expect(await browser.elementById(id).getAttribute('srcset')).toBe( '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=640&q=75 640w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=750&q=75 750w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=828&q=75 828w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=1080&q=75 1080w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=1200&q=75 1200w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=1920&q=75 1920w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=2048&q=75 2048w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75 3840w' ) @@ -300,9 +308,13 @@ function runTests(mode) { const width = await getComputed(browser, id, 'width') const height = await getComputed(browser, id, 'height') await browser.eval(`document.getElementById("${id}").scrollIntoView()`) - expect(await getSrc(browser, id)).toBe( - '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75' - ) + + await check(async () => { + expect(await getSrc(browser, id)).toBe( + '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75' + ) + return 'success' + }, 'success') expect(await browser.elementById(id).getAttribute('srcset')).toBe( '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=640&q=75 640w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=750&q=75 750w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=828&q=75 828w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=1080&q=75 1080w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=1200&q=75 1200w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=1920&q=75 1920w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=2048&q=75 2048w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75 3840w' ) @@ -350,9 +362,13 @@ function runTests(mode) { const height = 700 const delta = 250 const id = 'sizes1' - expect(await getSrc(browser, id)).toBe( - '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75' - ) + + await check(async () => { + expect(await getSrc(browser, id)).toBe( + '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75' + ) + return 'success' + }, 'success') expect(await browser.elementById(id).getAttribute('srcset')).toBe( '/docs/_next/image?url=%2Fdocs%2Fwide.png&w=16&q=75 16w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=32&q=75 32w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=48&q=75 48w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=64&q=75 64w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=96&q=75 96w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=128&q=75 128w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=256&q=75 256w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=384&q=75 384w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=640&q=75 640w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=750&q=75 750w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=828&q=75 828w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=1080&q=75 1080w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=1200&q=75 1200w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=1920&q=75 1920w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=2048&q=75 2048w, /docs/_next/image?url=%2Fdocs%2Fwide.png&w=3840&q=75 3840w' ) diff --git a/test/integration/next-image-legacy/default/test/index.test.ts b/test/integration/next-image-legacy/default/test/index.test.ts index c5889e83b49f8..35bb6eb3e0fb2 100644 --- a/test/integration/next-image-legacy/default/test/index.test.ts +++ b/test/integration/next-image-legacy/default/test/index.test.ts @@ -469,9 +469,13 @@ function runTests(mode) { const height = 700 const delta = 250 const id = 'fixed1' - expect(await getSrc(browser, id)).toBe( - '/_next/image?url=%2Fwide.png&w=3840&q=75' - ) + + await check(async () => { + expect(await getSrc(browser, id)).toBe( + '/_next/image?url=%2Fwide.png&w=3840&q=75' + ) + return 'success' + }, 'success') expect(await browser.elementById(id).getAttribute('srcset')).toBe( '/_next/image?url=%2Fwide.png&w=1200&q=75 1x, /_next/image?url=%2Fwide.png&w=3840&q=75 2x' ) @@ -503,9 +507,13 @@ function runTests(mode) { const height = 700 const delta = 250 const id = 'intrinsic1' - expect(await getSrc(browser, id)).toBe( - '/_next/image?url=%2Fwide.png&w=3840&q=75' - ) + + await check(async () => { + expect(await getSrc(browser, id)).toBe( + '/_next/image?url=%2Fwide.png&w=3840&q=75' + ) + return 'success' + }, 'success') expect(await browser.elementById(id).getAttribute('srcset')).toBe( '/_next/image?url=%2Fwide.png&w=1200&q=75 1x, /_next/image?url=%2Fwide.png&w=3840&q=75 2x' ) @@ -587,9 +595,13 @@ function runTests(mode) { const height = 350 const delta = 150 const id = 'fill1' - expect(await getSrc(browser, id)).toBe( - '/_next/image?url=%2Fwide.png&w=3840&q=75' - ) + + await check(async () => { + expect(await getSrc(browser, id)).toBe( + '/_next/image?url=%2Fwide.png&w=3840&q=75' + ) + return 'success' + }, 'success') expect(await browser.elementById(id).getAttribute('srcset')).toBe( '/_next/image?url=%2Fwide.png&w=640&q=75 640w, /_next/image?url=%2Fwide.png&w=750&q=75 750w, /_next/image?url=%2Fwide.png&w=828&q=75 828w, /_next/image?url=%2Fwide.png&w=1080&q=75 1080w, /_next/image?url=%2Fwide.png&w=1200&q=75 1200w, /_next/image?url=%2Fwide.png&w=1920&q=75 1920w, /_next/image?url=%2Fwide.png&w=2048&q=75 2048w, /_next/image?url=%2Fwide.png&w=3840&q=75 3840w' ) @@ -627,9 +639,13 @@ function runTests(mode) { const width = await getComputed(browser, id, 'width') const height = await getComputed(browser, id, 'height') await browser.eval(`document.getElementById("${id}").scrollIntoView()`) - expect(await getSrc(browser, id)).toBe( - '/_next/image?url=%2Fwide.png&w=3840&q=75' - ) + + await check(async () => { + expect(await getSrc(browser, id)).toBe( + '/_next/image?url=%2Fwide.png&w=3840&q=75' + ) + return 'success' + }, 'success') await check(() => { return browser.eval( @@ -694,9 +710,13 @@ function runTests(mode) { const height = 700 const delta = 250 const id = 'sizes1' - expect(await getSrc(browser, id)).toBe( - '/_next/image?url=%2Fwide.png&w=3840&q=75' - ) + + await check(async () => { + expect(await getSrc(browser, id)).toBe( + '/_next/image?url=%2Fwide.png&w=3840&q=75' + ) + return 'success' + }, 'success') expect(await browser.elementById(id).getAttribute('srcset')).toBe( '/_next/image?url=%2Fwide.png&w=16&q=75 16w, /_next/image?url=%2Fwide.png&w=32&q=75 32w, /_next/image?url=%2Fwide.png&w=48&q=75 48w, /_next/image?url=%2Fwide.png&w=64&q=75 64w, /_next/image?url=%2Fwide.png&w=96&q=75 96w, /_next/image?url=%2Fwide.png&w=128&q=75 128w, /_next/image?url=%2Fwide.png&w=256&q=75 256w, /_next/image?url=%2Fwide.png&w=384&q=75 384w, /_next/image?url=%2Fwide.png&w=640&q=75 640w, /_next/image?url=%2Fwide.png&w=750&q=75 750w, /_next/image?url=%2Fwide.png&w=828&q=75 828w, /_next/image?url=%2Fwide.png&w=1080&q=75 1080w, /_next/image?url=%2Fwide.png&w=1200&q=75 1200w, /_next/image?url=%2Fwide.png&w=1920&q=75 1920w, /_next/image?url=%2Fwide.png&w=2048&q=75 2048w, /_next/image?url=%2Fwide.png&w=3840&q=75 3840w' )