Skip to content

Commit

Permalink
test(vercel#39993): add a failed case
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 27, 2022
1 parent 34e10f3 commit 46b8959
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/integration/script-loader/base/next.config.js
@@ -0,0 +1,3 @@
module.exports = {
reactStrictMode: true,
}
23 changes: 23 additions & 0 deletions test/integration/script-loader/base/pages/page10.js
@@ -0,0 +1,23 @@
import Script from 'next/script'
import Link from 'next/link'

if (typeof window !== 'undefined') {
window.onReadyCalls ??= 0
}

const Page = () => {
return (
<div className="container">
<Link href="/page9">Page 9</Link>
<div id="text"></div>
<Script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"
onReady={() => {
window.onReadyCalls++
}}
/>
</div>
)
}

export default Page
24 changes: 24 additions & 0 deletions test/integration/script-loader/test/index.test.js
Expand Up @@ -8,6 +8,9 @@ import {
stopApp,
nextBuild,
waitFor,
findPort,
launchApp,
killApp,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import cheerio from 'cheerio'
Expand Down Expand Up @@ -214,6 +217,27 @@ describe('Next.js Script - Primary Strategies', () => {
}
})

// https://github.com/vercel/next.js/issues/39993
it('onReady should only fires once after load event in dev mode (issue #39993)', async () => {
let browser
// we will start a dedicated dev server for this test case only (scoped)
let devAppPort
let devApp

try {
devAppPort = await findPort()
devApp = await launchApp(appDir, devAppPort)
browser = await webdriver(devAppPort, '/page10')

// wait for jQuery to be loaded
await waitFor(1000)
expect(await browser.eval(`window.onReadyCalls`)).toBe(1)
} finally {
if (browser) await browser.close()
if (devApp) await killApp(devApp)
}
})

it('priority beforeInteractive with inline script', async () => {
const html = await renderViaHTTP(appPort, '/page5')
const $ = cheerio.load(html)
Expand Down

0 comments on commit 46b8959

Please sign in to comment.