Skip to content

Commit

Permalink
wait for initial hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Jun 7, 2023
1 parent df33333 commit 3808842
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions test/development/acceptance/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ import {
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { NextInstance } from 'test/lib/next-modes/base'
import { BrowserInterface } from 'test/lib/browsers/base'

function waitForHydration(browser: BrowserInterface): Promise<void> {
return browser.evalAsync(function () {
var callback = arguments[arguments.length - 1]
if ((window as any).__NEXT_HYDRATED) {
callback()
} else {
var timeout = setTimeout(callback, 30 * 1000)
;(window as any).__NEXT_HYDRATED_CB = function () {
clearTimeout(timeout)
callback()
}
}
})
}

export async function sandbox(
next: NextInstance,
Expand All @@ -30,6 +46,7 @@ export async function sandbox(
}
await next.start()
const browser = await webdriver(next.url, '/')
await waitForHydration(browser)
return {
session: {
async write(filename, content) {
Expand Down Expand Up @@ -58,18 +75,7 @@ export async function sandbox(
await new Promise((resolve) => setTimeout(resolve, 750))

// Wait for application to re-hydrate:
await browser.evalAsync(function () {
var callback = arguments[arguments.length - 1]
if ((window as any).__NEXT_HYDRATED) {
callback()
} else {
var timeout = setTimeout(callback, 30 * 1000)
;(window as any).__NEXT_HYDRATED_CB = function () {
clearTimeout(timeout)
callback()
}
}
})
await waitForHydration(browser)

console.log('Application re-loaded.')
// Slow down tests a bit:
Expand Down

0 comments on commit 3808842

Please sign in to comment.