Skip to content

Commit dddb84c

Browse files
committed
[test] Add test for dev rendering indicator
1 parent 1429d72 commit dddb84c

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Link from 'next/link'
2+
import { connection } from 'next/server'
3+
import { setTimeout } from 'timers/promises'
4+
5+
export default async function Page() {
6+
await connection()
7+
await setTimeout(100)
8+
9+
return (
10+
<>
11+
<Link href="/app/rendering/b" id="to-b">
12+
Go to b
13+
</Link>
14+
</>
15+
)
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Link from 'next/link'
2+
import { connection } from 'next/server'
3+
import { setTimeout } from 'timers/promises'
4+
5+
export default async function Page() {
6+
await connection()
7+
await setTimeout(100)
8+
return (
9+
<>
10+
<Link href="/app/rendering/a" id="to-a">
11+
Go to a
12+
</Link>
13+
</>
14+
)
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function RootLayout({ children }) {
2+
return (
3+
<html lang="en">
4+
<body>{children}</body>
5+
</html>
6+
)
7+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* eslint-env jest */
2+
3+
import { nextTestSetup } from 'e2e-utils'
4+
import { retry } from 'next-test-utils'
5+
6+
const installCheckVisible = (browser) => {
7+
return browser.eval(`(function() {
8+
window.checkInterval = setInterval(function() {
9+
const root = document.querySelector('nextjs-portal').shadowRoot;
10+
const indicator = root.querySelector('[data-next-mark]')
11+
window.showedBuilder = window.showedBuilder || (
12+
indicator.getAttribute('data-next-mark-loading') === 'true'
13+
)
14+
if (window.showedBuilder) clearInterval(window.checkInterval)
15+
}, 5)
16+
})()`)
17+
}
18+
19+
describe('Dev Rendering Indicator', () => {
20+
const { next } = nextTestSetup({
21+
files: __dirname,
22+
})
23+
24+
it('Shows build indicator when page is built from modifying', async () => {
25+
// Ensure both pages are built first so that we don't confuse it with build indicator
26+
await Promise.all([
27+
next.fetch('/app/rendering/a'),
28+
next.fetch('/app/rendering/b'),
29+
])
30+
const browser = await next.browser('/app/rendering/a')
31+
await installCheckVisible(browser)
32+
await browser.eval('window.showedBuilder = false')
33+
34+
await browser.elementByCss('[href="/app/rendering/b"]').click()
35+
await retry(async () => {
36+
await browser.elementByCss('[href="/app/rendering/a"]')
37+
})
38+
39+
const showedRenderingIndicator = await browser.eval('window.showedBuilder')
40+
expect({ showedRenderingIndicator }).toEqual({
41+
showedRenderingIndicator: true,
42+
})
43+
})
44+
})

0 commit comments

Comments
 (0)