Commit a1642c54 authored by Janka Uryga's avatar Janka Uryga

tests for metadata images

parent 644f6583
import { ImageResponse } from 'next/og'
export default function Icon() {
return new ImageResponse(
(
<div
style={{
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 88,
background: '#fff',
color: '#000',
}}
>
Icon
</div>
)
)
}
export const unstable_instant = { prefetch: 'static' }
export default function Page() {
return <main>This is a static page with an icon component.</main>
}
export const unstable_instant = { prefetch: 'static' }
export default function Page() {
return <main>This is a static page with a static icon.</main>
}
import { ImageResponse } from 'next/og'
export default function Icon() {
return new ImageResponse(
(
<div
style={{
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 88,
background: '#fff',
color: '#000',
}}
>
Favicon
</div>
)
)
}
export const unstable_instant = { prefetch: 'static' }
export default function Page() {
return (
<main>
This is a static page with an icon component that does not use params.
</main>
)
}
import { ImageResponse } from 'next/og'
export default async function Icon({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return new ImageResponse(
(
<div
style={{
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 88,
background: '#fff',
color: '#000',
}}
>
{slug}
</div>
)
)
}
import { Instant } from 'next'
import { connection } from 'next/server'
import { Suspense } from 'react'
export const unstable_instant: Instant = {
prefetch: 'static',
samples: [{ params: { slug: '123' } }],
}
export default function Page() {
return (
<main>
<p>
This is a page with an icon component that uses params. It has a dynamic
hole, because a static page can't have non-static metadata.
</p>
<Suspense>
<Dummy />
</Suspense>
</main>
)
}
async function Dummy() {
// TODO(instant-validation): this shouldn't need connection(), cookies should be enough
// await cookies()
await connection()
return null
}
export const unstable_instant = { prefetch: 'static' }
export default function Page() {
return <main>This is a static page with a static icon.</main>
}
......@@ -3345,6 +3345,83 @@ describe('instant validation', () => {
})
})
describe('metadata images', () => {
it('valid - static icon', async () => {
if (isNextDev) {
const browser = await navigateTo(
'/suspense-in-root/metadata-images/static-icon'
)
await expectNoDevValidationErrors(browser, await browser.url())
} else {
const result = await prerender(
'/suspense-in-root/metadata-images/static-icon'
)
expectNoBuildValidationErrors(result)
expect(result.exitCode).toBe(0)
}
})
it('valid - dynamic icon', async () => {
if (isNextDev) {
const browser = await navigateTo(
'/suspense-in-root/metadata-images/dynamic-icon'
)
await expectNoDevValidationErrors(browser, await browser.url())
} else {
const result = await prerender(
'/suspense-in-root/metadata-images/dynamic-icon'
)
expectNoBuildValidationErrors(result)
expect(result.exitCode).toBe(0)
}
})
it('valid - static icon with params', async () => {
if (isNextDev) {
const browser = await navigateTo(
'/suspense-in-root/metadata-images/with-params/123/static-icon'
)
await expectNoDevValidationErrors(browser, await browser.url())
} else {
const result = await prerender(
'/suspense-in-root/metadata-images/with-params/[slug]/static-icon'
)
expectNoBuildValidationErrors(result)
expect(result.exitCode).toBe(0)
}
})
it('valid - dynamic icon with unused params', async () => {
if (isNextDev) {
const browser = await navigateTo(
'/suspense-in-root/metadata-images/with-params/123/dynamic-icon-unused-params'
)
await expectNoDevValidationErrors(browser, await browser.url())
} else {
const result = await prerender(
'/suspense-in-root/metadata-images/with-params/[slug]/dynamic-icon-unused-params'
)
expectNoBuildValidationErrors(result)
expect(result.exitCode).toBe(0)
}
})
it('valid - dynamic icon used params', async () => {
if (isNextDev) {
const browser = await navigateTo(
'/suspense-in-root/metadata-images/with-params/123/dynamic-icon-used-params'
)
await expectNoDevValidationErrors(browser, await browser.url())
} else {
const result = await prerender(
'/suspense-in-root/metadata-images/with-params/[slug]/dynamic-icon-used-params'
)
expectNoBuildValidationErrors(result)
expect(result.exitCode).toBe(0)
}
})
})
describe('disabling validation', () => {
it('in a layout', async () => {
if (isNextDev) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment