Files
next.js/test/e2e/app-dir/ppr-metadata-streaming/ppr-metadata-streaming.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

196 lines
7.1 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import cheerio from 'cheerio'
import { assertNoConsoleErrors, retry } from 'next-test-utils'
function countSubstring(str: string, substr: string): number {
return str.split(substr).length - 1
}
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('ppr-metadata-streaming', () => {
const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname,
})
// No dynamic APIs used in metadata
describe('static metadata', () => {
it('should generate metadata in head when page is fully static', async () => {
const rootSelector = isNextDev ? 'body' : 'head'
const $ = await next.render$('/fully-static')
expect($(`${rootSelector} title`).text()).toBe('fully static')
expect(countSubstring($.html(), '<title>')).toBe(1)
const browser = await next.browser('/fully-static', {
pushErrorAsConsoleLog: true,
})
expect(
await browser
.waitForElementByCss(`${rootSelector} title`, { state: 'attached' })
.text()
).toBe('fully static')
await assertNoConsoleErrors(browser)
})
it('should insert metadata in body when page is dynamic page content', async () => {
const $ = await next.render$('/dynamic-page')
expect($(`body title`).text()).toBe('dynamic page')
expect(countSubstring($.html(), '<title>')).toBe(1)
const browser = await next.browser('/dynamic-page', {
pushErrorAsConsoleLog: true,
})
expect(
await browser
.waitForElementByCss('body title', { state: 'attached' })
.text()
).toBe('dynamic page')
await assertNoConsoleErrors(browser)
})
})
// Dynamic APIs used in metadata, metadata should be suspended and inserted into body
describe('dynamic metadata', () => {
it('should generate metadata in body when page is fully dynamic', async () => {
const $ = await next.render$('/fully-dynamic')
expect($('body title').text()).toBe('fully dynamic')
expect(countSubstring($.html(), '<title>')).toBe(1)
const browser = await next.browser('/fully-dynamic', {
pushErrorAsConsoleLog: true,
})
expect(
await browser
.waitForElementByCss('body title', { state: 'attached' })
.text()
).toBe('fully dynamic')
await assertNoConsoleErrors(browser)
})
it('should generate metadata in body when page content is static', async () => {
const $ = await next.render$('/dynamic-metadata')
expect($('body title').text()).toBe('dynamic metadata')
expect(countSubstring($.html(), '<title>')).toBe(1)
const browser = await next.browser('/dynamic-metadata')
expect(
await browser
.waitForElementByCss('body title', { state: 'attached' })
.text()
).toBe('dynamic metadata')
await assertNoConsoleErrors(browser)
})
})
describe('partial shell', () => {
it('should insert metadata into body with dynamic metadata and wrapped under layout Suspense boundary', async () => {
const $ = await next.render$('/dynamic-metadata/partial')
expect($('body title').text()).toBe('dynamic-metadata - partial')
expect(countSubstring($.html(), '<title>')).toBe(1)
const browser = await next.browser('/dynamic-metadata/partial', {
pushErrorAsConsoleLog: true,
})
expect(
await browser
.waitForElementByCss('body title', { state: 'attached' })
.text()
).toBe('dynamic-metadata - partial')
await assertNoConsoleErrors(browser)
})
it('should insert metadata into head with dynamic metadata and dynamic page wrapped under layout Suspense boundary', async () => {
const rootSelector = isNextDev ? 'body' : 'head'
const $ = await next.render$('/dynamic-page/partial')
expect($(`${rootSelector} title`).text()).toBe('dynamic-page - partial')
expect(countSubstring($.html(), '<title>')).toBe(1)
const browser = await next.browser('/dynamic-page/partial', {
pushErrorAsConsoleLog: true,
})
expect(
await browser
.waitForElementByCss(`${rootSelector} title`, { state: 'attached' })
.text()
).toBe('dynamic-page - partial')
await assertNoConsoleErrors(browser)
})
it('should not yield hydration errors after revalidation', async () => {
const browser = await next.browser('/partially-static', {
pushErrorAsConsoleLog: true,
})
const initialDate = await browser.elementById('date').text()
// Wait for the background revalidation to complete.
await retry(async () => {
await browser.refresh()
expect(await browser.elementById('date').text()).not.toBe(initialDate)
})
// There should be no hydration errors after the revalidation.
await assertNoConsoleErrors(browser)
})
})
// Skip the deployment tests for html limited bots
if (!isNextDev && !isNextDeploy) {
// This test is only relevant in production mode, as it's testing PPR results
describe('html limited bots', () => {
it('should serve partial static shell when normal UA requests the PPR page', async () => {
const res1 = await next.fetch('/dynamic-page/partial')
const res2 = await next.fetch('/dynamic-page/partial')
const $1 = cheerio.load(await res1.text())
const $2 = cheerio.load(await res2.text())
const attribute1 = parseInt($1('[data-date]').attr('data-date'))
const attribute2 = parseInt($2('[data-date]').attr('data-date'))
// Normal UA should still get the partial static shell produced by PPR
expect(attribute1).toBe(attribute2)
expect(attribute1).toBeTruthy()
const headers = res1.headers
// Static render should have postponed header
expect(headers.get('x-nextjs-postponed')).toBe('1')
})
it('should perform blocking and dynamic rendering when html limited bots requests the PPR page', async () => {
const htmlLimitedBotUA = 'Discordbot'
const res1 = await next.fetch('/dynamic-page/partial', {
headers: {
'User-Agent': htmlLimitedBotUA,
},
})
const res2 = await next.fetch('/dynamic-page/partial', {
headers: {
'User-Agent': htmlLimitedBotUA,
},
})
// Dynamic render should not have postponed header
const headers = res1.headers
expect(headers.get('x-nextjs-postponed')).toBe(null)
const $1 = cheerio.load(await res1.text())
const $2 = cheerio.load(await res2.text())
const attribute1 = parseInt($1('[data-date]').attr('data-date'))
const attribute2 = parseInt($2('[data-date]').attr('data-date'))
// Two requests are dynamic and should not have the same data-date attribute
expect(attribute2).toBeGreaterThan(attribute1)
expect(attribute1).toBeTruthy()
// Should contain resolved suspense content
const bodyHtml = $1('body').html()
expect(bodyHtml).toContain('outer suspended component')
expect(bodyHtml).toContain('nested suspended component')
})
})
}
})