@@ -56,10 +56,16 @@ export async function newE2EPage(opts: pd.NewE2EPageOptions = {}): Promise<pd.E2
5656 page . on ( 'requestfailed' , requestFailed ) ;
5757
5858 if ( typeof opts . html === 'string' ) {
59- await e2eSetContent ( page , opts . html ) ;
59+ const errMsg = await e2eSetContent ( page , opts . html ) ;
60+ if ( errMsg ) {
61+ throw errMsg ;
62+ }
6063
6164 } else if ( typeof opts . url === 'string' ) {
62- await e2eGoTo ( page , opts . url ) ;
65+ const errMsg = await e2eGoTo ( page , opts . url ) ;
66+ if ( errMsg ) {
67+ throw errMsg ;
68+ }
6369
6470 } else {
6571 page . goto = e2eGoTo . bind ( null , page ) ;
@@ -73,83 +79,68 @@ export async function newE2EPage(opts: pd.NewE2EPageOptions = {}): Promise<pd.E2
7379async function e2eGoTo ( page : pd . E2EPageInternal , url : string ) {
7480 try {
7581 if ( page . isClosed ( ) ) {
76- console . error ( 'e2eGoTo unavailable: page already closed' ) ;
77- return ;
82+ return 'e2eGoTo unavailable: page already closed' ;
7883 }
7984 } catch ( e ) {
80- return ;
85+ return null ;
8186 }
8287
8388 if ( typeof url !== 'string' ) {
84- console . error ( 'invalid gotoTest() url' ) ;
8589 await closePage ( page ) ;
86- return ;
90+ return 'invalid gotoTest() url' ;
8791 }
8892
8993 if ( ! url . startsWith ( '/' ) ) {
90- console . error ( 'gotoTest() url must start with /' ) ;
9194 await closePage ( page ) ;
92- return ;
95+ return 'gotoTest() url must start with /' ;
9396 }
9497
9598 const browserUrl = ( process . env as d . E2EProcessEnv ) . __STENCIL_BROWSER_URL__ ;
9699 if ( typeof browserUrl !== 'string' ) {
97- console . error ( 'invalid gotoTest() browser url' ) ;
98100 await closePage ( page ) ;
99- return ;
101+ return 'invalid gotoTest() browser url' ;
100102 }
101103
102- // resolves once the stencil app has finished loading
103- const appLoaded = page . waitForFunction ( 'window.stencilAppLoaded' ) ;
104-
105104 const fullUrl = browserUrl + url . substring ( 1 ) ;
106105
107- let timedOut = false ;
108- try {
109- await page . _e2eGoto ( fullUrl , {
110- waitUntil : 'load'
111- } ) ;
106+ const rsp = await page . _e2eGoto ( fullUrl ) ;
112107
113- const tmr = setTimeout ( async ( ) => {
114- timedOut = true ;
115- console . error ( `App did not load in allowed time. Please ensure the url ${ url } loads a stencil application.` ) ;
116- await closePage ( page ) ;
117- } , 4500 ) ;
108+ if ( ! rsp . ok ( ) ) {
109+ await closePage ( page ) ;
110+ return `Testing unable to load ${ url } , HTTP status: ${ rsp . status ( ) } ` ;
111+ }
118112
119- await appLoaded ;
113+ const tmr = setTimeout ( async ( ) => {
114+ await closePage ( page ) ;
115+ throw new Error ( `App did not load in allowed time. Please ensure the url ${ url } loads a stencil application.` ) ;
116+ } , 4500 ) ;
120117
121- clearTimeout ( tmr ) ;
118+ await page . waitForFunction ( 'window.stencilAppLoaded' ) ;
122119
123- } catch ( e ) {
124- if ( ! timedOut ) {
125- console . error ( `error goto: ${ url } , ${ e } ` ) ;
126- await closePage ( page ) ;
127- }
128- }
120+ clearTimeout ( tmr ) ;
121+
122+ return null ;
129123}
130124
131125
132126async function e2eSetContent ( page : pd . E2EPageInternal , html : string ) {
133127 try {
134128 if ( page . isClosed ( ) ) {
135- console . error ( 'e2eSetContent unavailable: page already closed' ) ;
136- return ;
129+ return 'e2eSetContent unavailable: page already closed' ;
137130 }
138131 } catch ( e ) {
139- return ;
132+ return null ;
140133 }
141134
142135 if ( typeof html !== 'string' ) {
143- console . error ( 'invalid e2eSetContent() html' ) ;
144136 await closePage ( page ) ;
145- return ;
137+ return 'invalid e2eSetContent() html' ;
146138 }
147139
148140 const loaderUrl = ( process . env as d . E2EProcessEnv ) . __STENCIL_LOADER_URL__ ;
149141 if ( typeof loaderUrl !== 'string' ) {
150- console . error ( 'invalid e2eSetContent() loader script url' ) ;
151142 await closePage ( page ) ;
152- return ;
143+ return 'invalid e2eSetContent() loader script url' ;
153144 }
154145
155146 const url = [
@@ -158,20 +149,23 @@ async function e2eSetContent(page: pd.E2EPageInternal, html: string) {
158149 html
159150 ] ;
160151
161- try {
162- // resolves once the stencil app has finished loading
163- const appLoaded = page . waitForFunction ( 'window.stencilAppLoaded' ) ;
164-
165- await page . _e2eGoto ( url . join ( '' ) , {
166- waitUntil : 'load'
167- } ) ;
152+ const rsp = await page . _e2eGoto ( url . join ( '' ) ) ;
168153
169- await appLoaded ;
170-
171- } catch ( e ) {
172- console . error ( `e2eSetContent: ${ e } ` ) ;
154+ if ( ! rsp . ok ( ) ) {
173155 await closePage ( page ) ;
156+ return `Testing unable to load content` ;
174157 }
158+
159+ const tmr = setTimeout ( async ( ) => {
160+ await closePage ( page ) ;
161+ throw new Error ( `App did not load in allowed time. Please ensure the content loads a stencil application.` ) ;
162+ } , 4500 ) ;
163+
164+ await page . waitForFunction ( 'window.stencilAppLoaded' ) ;
165+
166+ clearTimeout ( tmr ) ;
167+
168+ return null ;
175169}
176170
177171
0 commit comments