@@ -25,7 +25,6 @@ export type E2EPage = Page & {
25
25
* Shortcut for main frame's [frame.goto(url[, options])](https://playwright.dev/docs/api/class-frame#frame-goto)
26
26
* @param url URL to navigate page to. The url should include scheme, e.g. `https://`. When a `baseURL` via the context options was provided and the passed URL is a path, it gets merged via the
27
27
* [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor.
28
- * @param options
29
28
*/
30
29
goto : ( url : string ) => Promise < null | Response > ;
31
30
/**
@@ -168,35 +167,31 @@ export const test = base.extend<CustomFixtures>({
168
167
}
169
168
await page . evaluate ( ( ) => {
170
169
// BROWSER CONTEXT
171
- return new Promise < void > ( ( resolve ) => {
172
- const promises : Promise < any > [ ] = [ ] ;
170
+ return new Promise < void > ( resolve => {
171
+ const promiseChain : Promise < any > [ ] = [ ] ;
173
172
174
173
const waitComponentOnReady = ( elm : Element | ShadowRoot , promises : Promise < any > [ ] ) => {
175
- if ( elm != null ) {
176
- if ( 'shadowRoot' in elm && elm . shadowRoot instanceof ShadowRoot ) {
177
- waitComponentOnReady ( elm . shadowRoot , promises ) ;
178
- }
179
- const children = elm . children ;
180
- const len = children . length ;
181
- for ( let i = 0 ; i < len ; i ++ ) {
182
- const childElm = children [ i ] ;
183
- if ( childElm != null ) {
184
- const childStencilElm = childElm as HostElement ;
185
- if (
186
- childElm . tagName . includes ( '-' ) &&
187
- typeof childStencilElm . componentOnReady === 'function'
188
- ) {
189
- promises . push ( childStencilElm . componentOnReady ( ) ) ;
190
- }
191
- waitComponentOnReady ( childElm , promises ) ;
192
- }
174
+ if ( 'shadowRoot' in elm && elm . shadowRoot instanceof ShadowRoot ) {
175
+ waitComponentOnReady ( elm . shadowRoot , promises ) ;
176
+ }
177
+ const children = elm . children ;
178
+ const len = children . length ;
179
+ for ( let i = 0 ; i < len ; i ++ ) {
180
+ const childElm = children [ i ] ;
181
+ const childStencilElm = childElm as HostElement ;
182
+ if (
183
+ childElm . tagName . includes ( '-' ) &&
184
+ typeof childStencilElm . componentOnReady === 'function'
185
+ ) {
186
+ promises . push ( childStencilElm . componentOnReady ( ) ) ;
193
187
}
188
+ waitComponentOnReady ( childElm , promises ) ;
194
189
}
195
190
} ;
196
191
197
- waitComponentOnReady ( document . documentElement , promises ) ;
192
+ waitComponentOnReady ( document . documentElement , promiseChain ) ;
198
193
199
- Promise . all ( promises )
194
+ Promise . all ( promiseChain )
200
195
. then ( ( ) => resolve ( ) )
201
196
. catch ( ( ) => resolve ( ) )
202
197
} ) ;
@@ -205,29 +200,31 @@ export const test = base.extend<CustomFixtures>({
205
200
return ;
206
201
}
207
202
await page . waitForTimeout ( 100 ) ;
208
- } catch { }
203
+ } catch ( e ) {
204
+ console . error ( e ) ;
205
+ }
209
206
}
210
207
211
208
page . waitForCustomEvent = async ( eventName : string ) => {
212
209
const timeoutMs = 5000 ;
213
- const ev = await page . evaluate ( ( { eventName , timeoutMs } ) => {
210
+ const ev = await page . evaluate ( ( { type , timeout } ) => {
214
211
return new Promise < any > ( ( resolve , reject ) => {
215
212
const tmr = setTimeout ( ( ) => {
216
213
reject ( new Error ( `waitForCustomEvent() timeout, eventName: ${ eventName } ` ) ) ;
217
- } , timeoutMs ) ;
214
+ } , timeout ) ;
218
215
219
216
window . addEventListener (
220
- eventName ,
221
- ( ev : any ) => {
217
+ type ,
218
+ ( event : any ) => {
222
219
clearTimeout ( tmr ) ;
223
- resolve ( ( window as any ) . stencilSerializeEvent ( ev ) )
220
+ resolve ( ( window as any ) . stencilSerializeEvent ( event ) )
224
221
} ,
225
222
{ once : true }
226
223
)
227
224
} ) ;
228
225
} , {
229
- eventName,
230
- timeoutMs
226
+ type : eventName ,
227
+ timeout : timeoutMs
231
228
} ) ;
232
229
233
230
await page . waitForChanges ( ) ;
0 commit comments