File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -974,6 +974,7 @@ async function untilConsoleLog(
974974 expectOrder = true ,
975975) : Promise < string [ ] > {
976976 const { promise, resolve, reject } = promiseWithResolvers < void > ( )
977+ let timeoutId : ReturnType < typeof setTimeout >
977978
978979 const logsMessages = [ ]
979980
@@ -1024,12 +1025,27 @@ async function untilConsoleLog(
10241025 }
10251026 }
10261027
1028+ timeoutId = setTimeout ( ( ) => {
1029+ const nextTarget = Array . isArray ( target )
1030+ ? expectOrder
1031+ ? target [ 0 ]
1032+ : target . join ( ', ' )
1033+ : target
1034+ reject (
1035+ new Error (
1036+ `Timeout waiting for console logs. Waiting for: ${ nextTarget } ` ,
1037+ ) ,
1038+ )
1039+ logsEmitter . off ( 'log' , handleMsg )
1040+ } , 5000 )
1041+
10271042 logsEmitter . on ( 'log' , handleMsg )
10281043 } catch ( err ) {
10291044 reject ( err )
10301045 }
10311046
10321047 await promise
1048+ clearTimeout ( timeoutId )
10331049
10341050 return logsMessages
10351051}
Original file line number Diff line number Diff line change @@ -274,6 +274,7 @@ async function untilBrowserLog(
274274 expectOrder = true ,
275275) : Promise < string [ ] > {
276276 const { promise, resolve, reject } = promiseWithResolvers < void > ( )
277+ let timeoutId : ReturnType < typeof setTimeout >
277278
278279 const logs = [ ]
279280
@@ -322,12 +323,27 @@ async function untilBrowserLog(
322323 }
323324 }
324325
326+ timeoutId = setTimeout ( ( ) => {
327+ const nextTarget = Array . isArray ( target )
328+ ? expectOrder
329+ ? target [ 0 ]
330+ : target . join ( ', ' )
331+ : target
332+ reject (
333+ new Error (
334+ `Timeout waiting for browser logs. Waiting for: ${ nextTarget } ` ,
335+ ) ,
336+ )
337+ page . off ( 'console' , handleMsg )
338+ } , 5000 )
339+
325340 page . on ( 'console' , handleMsg )
326341 } catch ( err ) {
327342 reject ( err )
328343 }
329344
330345 await promise
346+ clearTimeout ( timeoutId )
331347
332348 return logs
333349}
You can’t perform that action at this time.
0 commit comments