Files
next.js/test/development/app-dir/async-request-warnings/async-request-warnings.test.ts
Arian Tron 61f56f997c
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
first commit
2026-03-10 19:37:31 +03:30

143 lines
5.7 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
describe('dynamic-requests warnings', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('warnings on sync cookie access', async () => {
const nextDevBootstrapOutputIndex = next.cliOutput.length
const browser = await next.browser('/request/cookies')
const browserLogs = await browser.log()
const browserConsoleWarnings = browserLogs
.filter((log) => log.source === 'warning')
.map((log) => log.message)
const terminalOutput = next.cliOutput.slice(nextDevBootstrapOutputIndex)
const terminalCookieErrors = terminalOutput.split('\n').filter((line) => {
return line.includes('Route "/request/cookies')
})
expect({ browserConsoleWarnings, terminalCookieErrors }).toEqual({
browserConsoleWarnings: [expect.stringContaining('`cookies().get`.')],
terminalCookieErrors: [expect.stringContaining('`cookies().get`.')],
})
})
it('warnings on sync draftMode access', async () => {
const nextDevBootstrapOutputIndex = next.cliOutput.length
const browser = await next.browser('/request/draftMode')
const browserLogs = await browser.log()
const browserConsoleWarnings = browserLogs
.filter((log) => log.source === 'warning')
.map((log) => log.message)
const terminalOutput = next.cliOutput.slice(nextDevBootstrapOutputIndex)
const terminalCookieErrors = terminalOutput.split('\n').filter((line) => {
return line.includes('Route "/request/draftMode')
})
expect({ browserConsoleWarnings, terminalCookieErrors }).toEqual({
browserConsoleWarnings: [
expect.stringContaining('`draftMode().isEnabled`.'),
],
terminalCookieErrors: [
expect.stringContaining('`draftMode().isEnabled`.'),
],
})
})
it('warnings on sync headers access', async () => {
const nextDevBootstrapOutputIndex = next.cliOutput.length
const browser = await next.browser('/request/headers')
const browserLogs = await browser.log()
const browserConsoleWarnings = browserLogs
.filter((log) => log.source === 'warning')
.map((log) => log.message)
const terminalOutput = next.cliOutput.slice(nextDevBootstrapOutputIndex)
const terminalCookieErrors = terminalOutput.split('\n').filter((line) => {
return line.includes('Route "/request/headers')
})
expect({ browserConsoleWarnings, terminalCookieErrors }).toEqual({
browserConsoleWarnings: [expect.stringContaining('`headers().get`.')],
terminalCookieErrors: [expect.stringContaining('`headers().get`.')],
})
})
it('warnings on sync params access', async () => {
const nextDevBootstrapOutputIndex = next.cliOutput.length
const browser = await next.browser('/request/params/[slug]')
const browserLogs = await browser.log()
const browserConsoleWarnings = browserLogs
.filter((log) => log.source === 'warning')
.map((log) => log.message)
const terminalOutput = next.cliOutput.slice(nextDevBootstrapOutputIndex)
const terminalCookieErrors = terminalOutput.split('\n').filter((line) => {
return line.includes('Route "/request/params/[slug]')
})
expect({ browserConsoleWarnings, terminalCookieErrors }).toEqual({
browserConsoleWarnings: [expect.stringContaining('`params.slug`.')],
terminalCookieErrors: [expect.stringContaining('`params.slug`.')],
})
})
it('warnings on sync searchParams access', async () => {
const nextDevBootstrapOutputIndex = next.cliOutput.length
const browser = await next.browser('/request/searchParams')
const browserLogs = await browser.log()
const browserConsoleWarnings = browserLogs
.filter((log) => log.source === 'warning')
.map((log) => log.message)
const terminalOutput = next.cliOutput.slice(nextDevBootstrapOutputIndex)
const terminalCookieErrors = terminalOutput.split('\n').filter((line) => {
return line.includes('Route "/request/searchParams')
})
expect({ browserConsoleWarnings, terminalCookieErrors }).toEqual({
browserConsoleWarnings: [expect.stringContaining('`searchParams.slug`.')],
terminalCookieErrors: [expect.stringContaining('`searchParams.slug`.')],
})
})
describe('no warnings', () => {
it('should have no warnings on normal rsc page without accessing params', async () => {
const browser = await next.browser('/no-access/normal')
const browserLogItems = await browser.log()
const browserConsoleWarnings = browserLogItems
.filter((log) => log.source === 'warning')
.map((log) => log.message)
expect(browserConsoleWarnings.length).toBe(0)
})
it('should only have hydration warnings on hydration mismatch page without accessing params', async () => {
const browser = await next.browser('/no-access/mismatch')
const browserLogItems = await browser.log()
console.log('browserLogItems', browserLogItems)
const browserConsoleWarnings = browserLogItems
.filter((log) => log.source === 'warning')
.map((log) => log.message)
// We assert there are zero logged errors but first we assert specific strings b/c we want a better
// failure message if these do appear
expect(browserConsoleWarnings).toEqual(
expect.not.arrayContaining([
expect.stringContaining('param property was accessed directly with'),
expect.stringContaining(
'searchParam property was accessed directly with'
),
])
)
// Even though there is a hydration error it does show up in the logs list b/c it is an
// uncaught Error not a console.error. We expect there to be no logged errors
expect(browserConsoleWarnings.length).toBe(0)
})
})
})