Skip to content

Commit

Permalink
test: add test for notFound during streaming (#44078)
Browse files Browse the repository at this point in the history
Add test for notFound case added in #41735
  • Loading branch information
huozhi committed Dec 19, 2022
1 parent 13a9fb9 commit 9855fd7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/e2e/app-dir/app/app/not-found/suspense/page.js
@@ -0,0 +1,41 @@
import { Suspense } from 'react'
import { notFound } from 'next/navigation'

function createSuspenseyComponent(Component, { timeout = 0, expire = 10 }) {
let result
let promise
return function Data() {
if (result) return result
if (!promise)
promise = new Promise((resolve) => {
setTimeout(() => {
result = <Component />
setTimeout(() => {
result = undefined
promise = undefined
}, expire)
resolve()
}, timeout)
})
throw promise
}
}

function NotFound() {
notFound()
return <></>
}

const SuspenseyNotFound = createSuspenseyComponent(NotFound, {
timeout: 300,
})

export default function () {
return (
<div className="suspense">
<Suspense fallback="fallback">
<SuspenseyNotFound />
</Suspense>
</div>
)
}
14 changes: 14 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -2364,6 +2364,20 @@ createNextDescribe(
.getAttribute('content')
).toBe('noindex')
})
it('should trigger not-found while streaming', async () => {
const initialHtml = await next.render('/not-found/suspense')
expect(initialHtml).not.toContain('noindex')

const browser = await next.browser('/not-found/suspense')
expect(
await browser.waitForElementByCss('#not-found-component').text()
).toBe('Not Found!')
expect(
await browser
.waitForElementByCss('meta[name="robots"]')
.getAttribute('content')
).toBe('noindex')
})
})

describe('bots', () => {
Expand Down

0 comments on commit 9855fd7

Please sign in to comment.