Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Mar 4, 2021
1 parent f115d13 commit 00ab1bf
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/integration/getserversideprops/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const Page = ({ world, time, url }) => {
<a id="normal">to normal</a>
</Link>
<br />
<Link href="/slow">
<a id="slow">to slow</a>
</Link>
<br />
<Link href="/blog/[post]" as="/blog/post-1">
<a id="post-1">to dynamic</a>
</Link>
Expand Down
26 changes: 26 additions & 0 deletions test/integration/getserversideprops/pages/slow/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Link from 'next/link'

let serverHitCount = 0

export async function getServerSideProps() {
await new Promise((resolve) => setTimeout(resolve, 500))
return {
props: {
count: ++serverHitCount,
},
}
}

export default ({ count }) => (
<>
<p>a slow page</p>
<p id="hit">hit: {count}</p>
<Link href="/">
<a id="home">to home</a>
</Link>
<br />
<Link href="/something">
<a id="something">to something</a>
</Link>
</>
)
26 changes: 26 additions & 0 deletions test/integration/getserversideprops/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,32 @@ const runTests = (dev = false) => {
expect(curRandom).toBe(initialRandom + '')
})

it('should dedupe server data requests', async () => {
const browser = await webdriver(appPort, '/')
await waitFor(2000)

// Keep clicking on the link
await browser.elementByCss('#slow').click()
await browser.elementByCss('#slow').click()
await browser.elementByCss('#slow').click()
await browser.elementByCss('#slow').click()

await check(() => getBrowserBodyText(browser), /a slow page/)

// Requests should be deduped
const hitCount = await browser.elementByCss('#hit').text()
expect(hitCount).toBe('hit: 1')

// Should send request again
await browser.elementByCss('#home').click()
await browser.waitForElementByCss('#slow')
await browser.elementByCss('#slow').click()
await check(() => getBrowserBodyText(browser), /a slow page/)

const newHitCount = await browser.elementByCss('#hit').text()
expect(newHitCount).toBe('hit: 2')
})

if (dev) {
it('should not show warning from url prop being returned', async () => {
const urlPropPage = join(appDir, 'pages/url-prop.js')
Expand Down

0 comments on commit 00ab1bf

Please sign in to comment.