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

Type Webdriver options in sandbox #70398

Merged
merged 1 commit into from
Sep 24, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/lib/development-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getRedboxDescriptionWarning,
toggleCollapseComponentStack,
} from './next-test-utils'
import webdriver from './next-webdriver'
import webdriver, { WebdriverOptions } from './next-webdriver'
import { NextInstance } from './next-modes/base'
import { BrowserInterface } from './browsers/base'

Expand All @@ -35,7 +35,7 @@ export async function sandbox(
next: NextInstance,
initialFiles?: Map<string, string | ((contents: string) => string)>,
initialUrl: string = '/',
webDriverOptions: any = undefined
webDriverOptions: WebdriverOptions = undefined
) {
await next.stop()
await next.clean()
Expand Down
57 changes: 37 additions & 20 deletions test/lib/next-webdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,52 @@ if (typeof afterAll === 'function') {
})
}

export interface WebdriverOptions {
/**
* whether to wait for React hydration to finish
*/
waitHydration?: boolean
/**
* allow retrying hydration wait if reload occurs
*/
retryWaitHydration?: boolean
/**
* disable cache for page load
*/
disableCache?: boolean
/**
* the callback receiving page instance before loading page
* @param page
* @returns
*/
beforePageLoad?: (page: any) => void
/**
* browser locale
*/
locale?: string
/**
* disable javascript
*/
disableJavaScript?: boolean
headless?: boolean
/**
* ignore https errors
*/
ignoreHTTPSErrors?: boolean
cpuThrottleRate?: number
pushErrorAsConsoleLog?: boolean
}

/**
*
* @param appPortOrUrl can either be the port or the full URL
* @param url the path/query to append when using appPort
* @param options
* @param options.waitHydration whether to wait for React hydration to finish
* @param options.retryWaitHydration allow retrying hydration wait if reload occurs
* @param options.disableCache disable cache for page load
* @param options.beforePageLoad the callback receiving page instance before loading page
* @param options.locale browser locale
* @param options.disableJavaScript disable javascript
* @param options.ignoreHttpsErrors ignore https errors
* @returns thenable browser instance
*/
export default async function webdriver(
appPortOrUrl: string | number,
url: string,
options?: {
waitHydration?: boolean
retryWaitHydration?: boolean
disableCache?: boolean
beforePageLoad?: (page: any) => void
locale?: string
disableJavaScript?: boolean
headless?: boolean
ignoreHTTPSErrors?: boolean
cpuThrottleRate?: number
pushErrorAsConsoleLog?: boolean
}
options?: WebdriverOptions
): Promise<BrowserInterface> {
let CurrentInterface: new () => BrowserInterface

Expand Down
Loading