From 0c49daad3c8eaa1140c2225c915afb7c39cfa2fc Mon Sep 17 00:00:00 2001 From: Zack Tanner <1939140+ztanner@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:17:44 -0700 Subject: [PATCH] fix client-cache deploy tests (#66770) - Telemetry debugging isn't available when deployed - The loading test had a race bug Verified all of these passed when deployed locally. --- test/deploy-tests-manifest.json | 2 - .../client-cache.defaults.test.ts | 18 ++--- .../client-cache.experimental.test.ts | 68 ++++++++++--------- .../client-cache.original.test.ts | 18 ++--- 4 files changed, 56 insertions(+), 50 deletions(-) diff --git a/test/deploy-tests-manifest.json b/test/deploy-tests-manifest.json index 62e9475d67139..1d1a13ee8c4b4 100644 --- a/test/deploy-tests-manifest.json +++ b/test/deploy-tests-manifest.json @@ -7,7 +7,6 @@ "test/production/**/*.test.{t,j}s{,x}" ], "exclude": [ - "test/e2e/app-dir/app-client-cache/client-cache.original.test.ts", "test/e2e/app-dir/app-routes/app-custom-routes.test.ts", "test/e2e/app-dir/next-after-app/index.test.ts", "test/e2e/app-dir/scss/nm-module-nested/nm-module-nested.test.ts", @@ -32,7 +31,6 @@ "test/e2e/third-parties/index.test.ts", "test/e2e/useselectedlayoutsegment-s-in-pages-router/useselectedlayoutsegment-s-in-pages-router.test.ts", "test/e2e/app-dir/app-prefetch-false-loading/app-prefetch-false-loading.test.ts", - "test/e2e/app-dir/app-client-cache/client-cache.experimental.test.ts", "test/e2e/app-dir/app-routes-client-component/app-routes-client-component.test.ts", "test/e2e/app-dir/app-routes/app-custom-route-base-path.test.ts", "test/e2e/app-dir/mdx/mdx.test.ts", diff --git a/test/e2e/app-dir/app-client-cache/client-cache.defaults.test.ts b/test/e2e/app-dir/app-client-cache/client-cache.defaults.test.ts index 8801cc50b63ab..459e5c87d7ec1 100644 --- a/test/e2e/app-dir/app-client-cache/client-cache.defaults.test.ts +++ b/test/e2e/app-dir/app-client-cache/client-cache.defaults.test.ts @@ -1,5 +1,5 @@ import { nextTestSetup } from 'e2e-utils' -import { check } from 'next-test-utils' +import { check, retry } from 'next-test-utils' import { BrowserInterface } from 'next-webdriver' import { browserConfigWithFixedTime, @@ -316,18 +316,20 @@ describe('app dir client cache semantics (default semantics)', () => { await browser.elementByCss('[href="/null-loading"]').click() // the page content should disappear immediately - expect( - await browser.hasElementByCssSelector('[href="/null-loading"]') - ).toBeFalse() + await retry(async () => { + expect( + await browser.hasElementByCssSelector('[href="/null-loading"]') + ).toBe(false) + }) // the root layout should still be visible - expect(await browser.hasElementByCssSelector('#root-layout')).toBeTrue() + expect(await browser.hasElementByCssSelector('#root-layout')).toBe(true) // the dynamic content should eventually appear await browser.waitForElementByCss('#random-number') - expect( - await browser.hasElementByCssSelector('#random-number') - ).toBeTrue() + expect(await browser.hasElementByCssSelector('#random-number')).toBe( + true + ) }) }) diff --git a/test/e2e/app-dir/app-client-cache/client-cache.experimental.test.ts b/test/e2e/app-dir/app-client-cache/client-cache.experimental.test.ts index b865df7202ec6..19fc74ba094b6 100644 --- a/test/e2e/app-dir/app-client-cache/client-cache.experimental.test.ts +++ b/test/e2e/app-dir/app-client-cache/client-cache.experimental.test.ts @@ -5,7 +5,7 @@ import path from 'path' describe('app dir client cache semantics (experimental staleTimes)', () => { describe('dynamic: 0', () => { - const { next, isNextDev } = nextTestSetup({ + const { next, isNextDev, isNextDeploy } = nextTestSetup({ files: path.join(__dirname, 'fixtures', 'regular'), nextConfig: { experimental: { staleTimes: { dynamic: 0 } }, @@ -222,27 +222,29 @@ describe('app dir client cache semantics (experimental staleTimes)', () => { }) }) - describe('telemetry', () => { - it('should send staleTimes feature usage event', async () => { - const events = findAllTelemetryEvents( - next.cliOutput, - 'NEXT_CLI_SESSION_STARTED' - ) + if (!isNextDeploy) { + describe('telemetry', () => { + it('should send staleTimes feature usage event', async () => { + const events = findAllTelemetryEvents( + next.cliOutput, + 'NEXT_CLI_SESSION_STARTED' + ) - expect(events).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - staticStaleTime: null, - dynamicStaleTime: 0, - }), - ]) - ) + expect(events).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + staticStaleTime: null, + dynamicStaleTime: 0, + }), + ]) + ) + }) }) - }) + } }) describe('static: 180', () => { - const { next, isNextDev } = nextTestSetup({ + const { next, isNextDev, isNextDeploy } = nextTestSetup({ files: path.join(__dirname, 'fixtures', 'regular'), nextConfig: { experimental: { staleTimes: { static: 180 } }, @@ -341,22 +343,24 @@ describe('app dir client cache semantics (experimental staleTimes)', () => { }) }) - describe('telemetry', () => { - it('should send staleTimes feature usage event', async () => { - const events = findAllTelemetryEvents( - next.cliOutput, - 'NEXT_CLI_SESSION_STARTED' - ) - expect(events).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - staticStaleTime: 180, - dynamicStaleTime: null, - }), - ]) - ) + if (!isNextDeploy) { + describe('telemetry', () => { + it('should send staleTimes feature usage event', async () => { + const events = findAllTelemetryEvents( + next.cliOutput, + 'NEXT_CLI_SESSION_STARTED' + ) + expect(events).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + staticStaleTime: 180, + dynamicStaleTime: null, + }), + ]) + ) + }) }) - }) + } }) describe('dynamic: 0, static: 0', () => { diff --git a/test/e2e/app-dir/app-client-cache/client-cache.original.test.ts b/test/e2e/app-dir/app-client-cache/client-cache.original.test.ts index 8740e0fa75918..d8fd2ab6c5b26 100644 --- a/test/e2e/app-dir/app-client-cache/client-cache.original.test.ts +++ b/test/e2e/app-dir/app-client-cache/client-cache.original.test.ts @@ -1,5 +1,5 @@ import { nextTestSetup } from 'e2e-utils' -import { check } from 'next-test-utils' +import { check, retry } from 'next-test-utils' import { BrowserInterface } from 'next-webdriver' import { browserConfigWithFixedTime, @@ -421,18 +421,20 @@ describe('app dir client cache semantics (30s/5min)', () => { await browser.elementByCss('[href="/null-loading"]').click() // the page content should disappear immediately - expect( - await browser.hasElementByCssSelector('[href="/null-loading"]') - ).toBeFalse() + await retry(async () => { + expect( + await browser.hasElementByCssSelector('[href="/null-loading"]') + ).toBe(false) + }) // the root layout should still be visible - expect(await browser.hasElementByCssSelector('#root-layout')).toBeTrue() + expect(await browser.hasElementByCssSelector('#root-layout')).toBe(true) // the dynamic content should eventually appear await browser.waitForElementByCss('#random-number') - expect( - await browser.hasElementByCssSelector('#random-number') - ).toBeTrue() + expect(await browser.hasElementByCssSelector('#random-number')).toBe( + true + ) }) })