Skip to content

Commit

Permalink
fix client-cache deploy tests (vercel#66770)
Browse files Browse the repository at this point in the history
- Telemetry debugging isn't available when deployed
- The loading test had a race bug

Verified all of these passed when deployed locally.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
  • Loading branch information
ztanner authored Jun 11, 2024
1 parent a00555a commit 0c49daa
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 50 deletions.
2 changes: 0 additions & 2 deletions test/deploy-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
18 changes: 10 additions & 8 deletions test/e2e/app-dir/app-client-cache/client-cache.defaults.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
)
})
})

Expand Down
68 changes: 36 additions & 32 deletions test/e2e/app-dir/app-client-cache/client-cache.experimental.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
Expand Down Expand Up @@ -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 } },
Expand Down Expand Up @@ -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', () => {
Expand Down
18 changes: 10 additions & 8 deletions test/e2e/app-dir/app-client-cache/client-cache.original.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
)
})
})

Expand Down

0 comments on commit 0c49daa

Please sign in to comment.