Skip to content

Commit

Permalink
force headed mode for test; use window.history.state instead of initi…
Browse files Browse the repository at this point in the history
…alTree
  • Loading branch information
ztanner committed Aug 16, 2023
1 parent d49ecff commit 6ee7015
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/client/components/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ function Router({
dispatch({
type: ACTION_RESTORE,
url: new URL(window.location.href),
tree: initialTree,
tree: window.history.state,
})
}

Expand Down
3 changes: 2 additions & 1 deletion test/lib/browsers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export abstract class BrowserInterface implements PromiseLike<any> {
async setup(
browserName: string,
locale: string,
javaScriptEnabled: boolean
javaScriptEnabled: boolean,
headless: boolean
): Promise<void> {}
async close(): Promise<void> {}
async quit(): Promise<void> {}
Expand Down
8 changes: 6 additions & 2 deletions test/lib/browsers/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ export class Playwright extends BrowserInterface {
this.eventCallbacks[event]?.delete(cb)
}

async setup(browserName: string, locale: string, javaScriptEnabled: boolean) {
const headless = !!process.env.HEADLESS
async setup(
browserName: string,
locale: string,
javaScriptEnabled: boolean,
headless: boolean
) {
let device

if (process.env.DEVICE_NAME) {
Expand Down
10 changes: 7 additions & 3 deletions test/lib/browsers/selenium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
BROWSERSTACK,
BROWSERSTACK_USERNAME,
BROWSERSTACK_ACCESS_KEY,
HEADLESS,
CHROME_BIN,
LEGACY_SAFARI,
SKIP_LOCAL_SELENIUM_SERVER,
Expand Down Expand Up @@ -46,7 +45,12 @@ export class Selenium extends BrowserInterface {
private browserName: string

// TODO: support setting locale
async setup(browserName: string, locale: string, javaScriptEnabled: boolean) {
async setup(
browserName: string,
locale: string,
javaScriptEnabled: boolean,
headless: boolean
) {
if (browser) return
this.browserName = browserName

Expand Down Expand Up @@ -155,7 +159,7 @@ export class Selenium extends BrowserInterface {
let firefoxOptions = new FireFoxOptions()
let safariOptions = new SafariOptions()

if (HEADLESS) {
if (headless) {
const screenSize = { width: 1280, height: 720 }
chromeOptions = chromeOptions.headless().windowSize(screenSize) as any
firefoxOptions = firefoxOptions.headless().windowSize(screenSize)
Expand Down
10 changes: 9 additions & 1 deletion test/lib/next-webdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default async function webdriver(
beforePageLoad?: (page: any) => void
locale?: string
disableJavaScript?: boolean
headless?: boolean
}
): Promise<BrowserInterface> {
let CurrentInterface: new () => BrowserInterface
Expand All @@ -82,6 +83,7 @@ export default async function webdriver(
beforePageLoad,
locale,
disableJavaScript,
headless,
} = options

// we import only the needed interface
Expand All @@ -101,7 +103,13 @@ export default async function webdriver(

const browser = new CurrentInterface()
const browserName = process.env.BROWSER_NAME || 'chrome'
await browser.setup(browserName, locale, !disableJavaScript)
await browser.setup(
browserName,
locale,
!disableJavaScript,
// allow headless to be overwritten for a particular test
typeof headless !== 'undefined' ? headless : !!process.env.HEADLESS
)
;(global as any).browserName = browserName

const fullUrl = getFullUrl(
Expand Down
11 changes: 8 additions & 3 deletions test/production/export-routing/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ describe('export-routing', () => {
})

it('should not suspend indefinitely when page is restored from bfcache after an mpa navigation', async () => {
const browser = await webdriver(port, '/index.html', {
waitHydration: false,
})
// bfcache is not currently supported by CDP, so we need to run this particular test in headed mode
// https://bugs.chromium.org/p/chromium/issues/detail?id=1317959
if (!process.env.CI && process.env.HEADLESS) {
console.warn('This test can only run in headed mode. Skipping...')
return
}

const browser = await webdriver(port, '/index.html', { headless: false })

await browser.elementByCss('a[href="https://example.vercel.sh"]').click()
await browser.waitForCondition(
Expand Down

0 comments on commit 6ee7015

Please sign in to comment.