Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize i18n fallback test #17957

Merged
merged 6 commits into from Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion test/integration/i18n-support/test/index.test.js
Expand Up @@ -672,7 +672,12 @@ function runTests(isDev) {
})

it('should render 404 for fallback page that returned 404', async () => {
const browser = await webdriver(appPort, '/en/not-found/fallback/first')
const browser = await webdriver(
appPort,
'/en/not-found/fallback/first',
true,
true
)
await browser.waitForElementByCss('h1')
await browser.eval('window.beforeNav = 1')

Expand Down
3 changes: 2 additions & 1 deletion test/lib/next-webdriver.d.ts
Expand Up @@ -24,5 +24,6 @@ interface Chain {
export default function (
appPort: number,
path: string,
waitHydration?: boolean
waitHydration?: boolean,
allowHydrationRetry?: boolean
): Promise<Chain>
50 changes: 36 additions & 14 deletions test/lib/next-webdriver.js
Expand Up @@ -152,7 +152,12 @@ const freshWindow = async () => {
await browser.switchTo().window(newWindow)
}

export default async (appPort, path, waitHydration = true) => {
export default async (
appPort,
path,
waitHydration = true,
allowHydrationRetry = false
) => {
if (!initialWindow) {
initialWindow = await browser.getWindowHandle()
}
Expand All @@ -176,24 +181,41 @@ export default async (appPort, path, waitHydration = true) => {
// Wait for application to hydrate
if (waitHydration) {
console.log(`\n> Waiting hydration for ${url}\n`)
await browser.executeAsyncScript(function () {
var callback = arguments[arguments.length - 1]

// if it's not a Next.js app return
if (document.documentElement.innerHTML.indexOf('__NEXT_DATA__') === -1) {
callback()
}
const checkHydrated = async () => {
await browser.executeAsyncScript(function () {
var callback = arguments[arguments.length - 1]

if (window.__NEXT_HYDRATED) {
callback()
} else {
var timeout = setTimeout(callback, 10 * 1000)
window.__NEXT_HYDRATED_CB = function () {
clearTimeout(timeout)
// if it's not a Next.js app return
if (
document.documentElement.innerHTML.indexOf('__NEXT_DATA__') === -1
) {
callback()
}

if (window.__NEXT_HYDRATED) {
callback()
} else {
var timeout = setTimeout(callback, 10 * 1000)
window.__NEXT_HYDRATED_CB = function () {
clearTimeout(timeout)
callback()
}
}
})
}

try {
await checkHydrated()
} catch (err) {
if (allowHydrationRetry) {
// re-try in case the page reloaded during check
await checkHydrated()
} else {
throw err
}
})
}

console.log(`\n> Hydration complete for ${url}\n`)
}

Expand Down