Unverified Commit d044c554 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

ci: fix javascript-urls test to account for React 18 (#88249)

This was caught by our React 18 tests which only run on `canary`. There
was a console error about breaking `javascript:` urls in an upcoming
React release but it didn't actually block them.
parent d99021e9
......@@ -7,6 +7,8 @@ import {
} from 'next-test-utils'
import type { Page, Request } from 'playwright'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('javascript-urls', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
......@@ -247,6 +249,8 @@ describe('javascript-urls', () => {
expect(safePageUrl).toContain('/app/safe')
})
// React 18 did not block JavaScript URLs, it was just a console error.
if (!isReact18) {
it('should prevent javascript URLs in pages router Link component', async () => {
const { beforePageLoad, getNavigationRequests } =
createNavigationInterceptor()
......@@ -259,7 +263,11 @@ describe('javascript-urls', () => {
await browser.elementByCss('a').click()
await expectJavascriptUrlBlocked(browser, initialUrl, getNavigationRequests)
await expectJavascriptUrlBlocked(
browser,
initialUrl,
getNavigationRequests
)
if (isNextDev) {
await waitForRedbox(browser)
......@@ -281,6 +289,7 @@ describe('javascript-urls', () => {
const safePageUrl = await browser.url()
expect(safePageUrl).toContain('/pages/safe')
})
}
it('should prevent javascript URLs in pages router Link as prop', async () => {
const { beforePageLoad, getNavigationRequests } =
......
......@@ -4,8 +4,7 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url'
export default function Page() {
return (
<html>
<body>
<div>
<main>
<p>
Clicking this link should result in an error where React blocks a
......@@ -18,7 +17,6 @@ export default function Page() {
<footer>
<Link href="/pages/safe">Safe Page</Link>
</footer>
</body>
</html>
</div>
)
}
......@@ -4,8 +4,7 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url'
export default function Page() {
return (
<html>
<body>
<div>
<main>
<p>
Clicking this link should result in an error where React blocks a
......@@ -18,7 +17,6 @@ export default function Page() {
<footer>
<Link href="/pages/safe">Safe Page</Link>
</footer>
</body>
</html>
</div>
)
}
......@@ -6,12 +6,11 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url'
export default function Page() {
const router = useRouter()
return (
<html>
<body>
<div>
<main>
<p>
Clicking this button should result in an error where Next.js blocks
a javascript URL
Clicking this button should result in an error where Next.js blocks a
javascript URL
</p>
<button onClick={() => router.push(DANGEROUS_JAVASCRIPT_URL)}>
push javascript URL
......@@ -20,7 +19,6 @@ export default function Page() {
<footer>
<Link href="/pages/safe">Safe Page</Link>
</footer>
</body>
</html>
</div>
)
}
......@@ -6,12 +6,11 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url'
export default function Page() {
const router = useRouter()
return (
<html>
<body>
<div>
<main>
<p>
Clicking this button should result in an error where Next.js blocks
a javascript URL
Clicking this button should result in an error where Next.js blocks a
javascript URL
</p>
<button onClick={() => router.replace(DANGEROUS_JAVASCRIPT_URL)}>
replace javascript URL
......@@ -20,7 +19,6 @@ export default function Page() {
<footer>
<Link href="/pages/safe">Safe Page</Link>
</footer>
</body>
</html>
</div>
)
}
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