@@ -654,47 +654,92 @@ it.effect("a desktop page that loaded before the server attached reports its loa
654654 ) . pipe ( Effect . provide ( layer ) ) ,
655655) ;
656656
657- it . live ( "Stop settles an initial navigation before its request event" , ( ) =>
658- Effect . scoped (
659- Effect . gen ( function * ( ) {
660- const { browser } = yield * ready ;
661- const manager = yield * Manager . PreviewManager ;
662- const events = yield * manager . subscribeEvents ;
663- const started = Promise . withResolvers < void > ( ) ;
664- const committed = Promise . withResolvers < void > ( ) ;
665- initialNavigation = ( ) => {
666- started . resolve ( ) ;
667- return committed . promise ;
668- } ;
669- yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => committed . resolve ( ) ) ) ;
670- const { tabId } = yield * manager . open ( {
671- threadId : scope . thread . threadId ,
672- runtime : "server" ,
673- url : "https://example.com/pending" ,
674- } ) ;
675- const viewer = yield * browser . attachViewer ( viewerInput ( tabId , true ) ) ;
676- yield * Effect . promise ( ( ) => started . promise ) ;
677- const cdp = contexts . at ( - 1 ) ! . sessions . at ( - 1 ) ! ;
678- const send = cdp . send . getMockImplementation ( ) ! ;
679- cdp . send . mockImplementation ( async ( operation , input ) => {
680- if ( operation === "Page.stopLoading" ) committed . reject ( new Error ( "net::ERR_ABORTED" ) ) ;
681- return send ( operation , input ) ;
682- } ) ;
683- yield * viewer . input ( { type : "stopLoading" } ) ;
684- let settled = yield * PubSub . take ( events ) ;
685- while (
686- settled . type !== "navigated" ||
687- settled . tabId !== tabId ||
688- settled . snapshot . navStatus . _tag !== "Idle"
689- ) {
690- settled = yield * PubSub . take ( events ) ;
691- }
692- const { sessions } = yield * manager . list ( { threadId : scope . thread . threadId } ) ;
693- expect ( sessions . find ( ( session ) => session . tabId === tabId ) ?. navStatus ) . toEqual ( {
694- _tag : "Idle" ,
695- } ) ;
696- } ) ,
697- ) . pipe ( Effect . provide ( layer ) ) ,
657+ it . live . each ( [ "none" , "during" , "after" , "after-fragment" , "corrected" , "same-url" ] ) (
658+ "Stop settles an initial navigation with its request event $0" ,
659+ ( requestTiming ) =>
660+ Effect . scoped (
661+ Effect . gen ( function * ( ) {
662+ const { browser, broker } = yield * ready ;
663+ const manager = yield * Manager . PreviewManager ;
664+ const events = yield * manager . subscribeEvents ;
665+ const started = Promise . withResolvers < void > ( ) ;
666+ const committed = Promise . withResolvers < void > ( ) ;
667+ initialNavigation = ( ) => {
668+ started . resolve ( ) ;
669+ return committed . promise ;
670+ } ;
671+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => committed . resolve ( ) ) ) ;
672+ const { tabId } = yield * manager . open ( {
673+ threadId : scope . thread . threadId ,
674+ runtime : "server" ,
675+ url :
676+ requestTiming === "after-fragment"
677+ ? "https://example.com/pending#section"
678+ : "https://example.com/pending" ,
679+ } ) ;
680+ const viewer = yield * browser . attachViewer ( viewerInput ( tabId , true ) ) ;
681+ yield * Effect . promise ( ( ) => started . promise ) ;
682+ const page = contexts . at ( - 1 ) ! . page ;
683+ const request = {
684+ url : ( ) => "https://example.com/pending" ,
685+ method : ( ) => "GET" ,
686+ isNavigationRequest : ( ) => true ,
687+ frame : ( ) => page ,
688+ failure : ( ) => ( { errorText : "net::ERR_ABORTED" } ) ,
689+ } ;
690+ const cdp = contexts . at ( - 1 ) ! . sessions . at ( - 1 ) ! ;
691+ const send = cdp . send . getMockImplementation ( ) ! ;
692+ cdp . send . mockImplementation ( async ( operation , input ) => {
693+ if ( operation === "Page.stopLoading" ) {
694+ committed . reject ( new Error ( "net::ERR_ABORTED" ) ) ;
695+ if ( requestTiming === "during" ) page . emit ( "request" , request ) ;
696+ }
697+ return send ( operation , input ) ;
698+ } ) ;
699+ yield * viewer . input ( { type : "stopLoading" } ) ;
700+ const stopped = yield * broker . invoke < PreviewAutomationStatus > ( {
701+ scope,
702+ tabId,
703+ operation : "status" ,
704+ input : { } ,
705+ } ) ;
706+ expect ( stopped . loading ) . toBe ( false ) ;
707+ let settled = yield * PubSub . take ( events ) ;
708+ while (
709+ settled . type !== "navigated" ||
710+ settled . tabId !== tabId ||
711+ settled . snapshot . navStatus . _tag !== "Idle"
712+ ) {
713+ settled = yield * PubSub . take ( events ) ;
714+ }
715+ const corrected = requestTiming === "corrected" || requestTiming === "same-url" ;
716+ using timeout = vi . spyOn ( globalThis , "setTimeout" ) ;
717+ if ( corrected ) {
718+ const url = requestTiming === "same-url" ? request . url ( ) : "https://example.com/fixed" ;
719+ page . goto . mockImplementationOnce ( async ( ) => {
720+ page . emit ( "request" , { ...request , url : ( ) => url } ) ;
721+ } ) ;
722+ yield * viewer . input ( { type : "navigate" , url } ) ;
723+ } else if ( requestTiming !== "none" ) {
724+ if ( requestTiming . startsWith ( "after" ) ) page . emit ( "request" , request ) ;
725+ page . emit ( "requestfailed" , request ) ;
726+ }
727+ const status = yield * broker . invoke < PreviewAutomationStatus > ( {
728+ scope,
729+ tabId,
730+ operation : "status" ,
731+ input : { } ,
732+ } ) ;
733+ expect ( status . loading ) . toBe ( corrected ) ;
734+ expect ( timeout ) . not . toHaveBeenCalledWith ( expect . any ( Function ) , 5_000 ) ;
735+ if ( ! corrected ) {
736+ const { sessions } = yield * manager . list ( { threadId : scope . thread . threadId } ) ;
737+ expect ( sessions . find ( ( session ) => session . tabId === tabId ) ?. navStatus ) . toEqual ( {
738+ _tag : "Idle" ,
739+ } ) ;
740+ }
741+ } ) ,
742+ ) . pipe ( Effect . provide ( layer ) ) ,
698743) ;
699744
700745it . live . each ( [
@@ -780,7 +825,9 @@ it.live.each([
780825 if ( abortEvent === "none" && ! blank ) committed . resolve ( ) ;
781826 yield * viewer . input ( { type : "stopLoading" } ) ;
782827 expect ( cancelled ) . toBe ( true ) ;
828+ using timeout = vi . spyOn ( globalThis , "setTimeout" ) ;
783829 if ( abortEvent === "after" ) page . emit ( "requestfailed" , request ) ;
830+ expect ( timeout ) . not . toHaveBeenCalledWith ( expect . any ( Function ) , 5_000 ) ;
784831 const status = yield * broker . invoke < PreviewAutomationStatus > ( {
785832 scope,
786833 tabId,
0 commit comments