Skip to content

Commit

Permalink
Type Webdriver options in sandbox (#70398)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Sep 24, 2024
1 parent 0539477 commit d54ed5d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
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

0 comments on commit d54ed5d

Please sign in to comment.