@@ -58,13 +58,13 @@ export async function newE2EPage(opts: pd.NewE2EPageOptions = {}): Promise<pd.E2
58
58
page . on ( 'requestfailed' , requestFailed ) ;
59
59
60
60
if ( typeof opts . html === 'string' ) {
61
- const errMsg = await e2eSetContent ( page , opts . html ) ;
61
+ const errMsg = await e2eSetContent ( page , opts . html , { waitUntil : opts . waitUntil } ) ;
62
62
if ( errMsg ) {
63
63
throw errMsg ;
64
64
}
65
65
66
66
} else if ( typeof opts . url === 'string' ) {
67
- const errMsg = await e2eGoTo ( page , opts . url ) ;
67
+ const errMsg = await e2eGoTo ( page , opts . url , { waitUntil : opts . waitUntil } ) ;
68
68
if ( errMsg ) {
69
69
throw errMsg ;
70
70
}
@@ -93,7 +93,7 @@ function failedPage() {
93
93
return page ;
94
94
}
95
95
96
- async function e2eGoTo ( page : pd . E2EPageInternal , url : string ) {
96
+ async function e2eGoTo ( page : pd . E2EPageInternal , url : string , options : puppeteer . NavigationOptions ) {
97
97
try {
98
98
if ( page . isClosed ( ) ) {
99
99
return 'e2eGoTo unavailable: page already closed' ;
@@ -120,7 +120,10 @@ async function e2eGoTo(page: pd.E2EPageInternal, url: string) {
120
120
121
121
const fullUrl = browserUrl + url . substring ( 1 ) ;
122
122
123
- const rsp = await page . _e2eGoto ( fullUrl , { waitUntil : 'networkidle0' } ) ;
123
+ if ( ! options . waitUntil ) {
124
+ options . waitUntil = DEFAULT_WAIT_FOR ;
125
+ }
126
+ const rsp = await page . _e2eGoto ( fullUrl , options ) ;
124
127
125
128
if ( ! rsp . ok ( ) ) {
126
129
await closePage ( page ) ;
@@ -140,7 +143,7 @@ async function e2eGoTo(page: pd.E2EPageInternal, url: string) {
140
143
}
141
144
142
145
143
- async function e2eSetContent ( page : pd . E2EPageInternal , html : string ) {
146
+ async function e2eSetContent ( page : pd . E2EPageInternal , html : string , options : puppeteer . NavigationOptions = { } ) {
144
147
try {
145
148
if ( page . isClosed ( ) ) {
146
149
return 'e2eSetContent unavailable: page already closed' ;
@@ -180,7 +183,10 @@ async function e2eSetContent(page: pd.E2EPageInternal, html: string) {
180
183
}
181
184
} ) ;
182
185
183
- const rsp = await page . _e2eGoto ( url , { waitUntil : 'networkidle0' } ) ;
186
+ if ( ! options . waitUntil ) {
187
+ options . waitUntil = DEFAULT_WAIT_FOR ;
188
+ }
189
+ const rsp = await page . _e2eGoto ( url , options ) ;
184
190
185
191
if ( ! rsp . ok ( ) ) {
186
192
await closePage ( page ) ;
@@ -310,3 +316,5 @@ function pageError(e: any) {
310
316
function requestFailed ( req : puppeteer . Request ) {
311
317
console . error ( 'requestfailed' , req . url ( ) ) ;
312
318
}
319
+
320
+ const DEFAULT_WAIT_FOR = 'load' ;
0 commit comments