@@ -14,6 +14,9 @@ function log(...args) {
14
14
function out ( ...args ) {
15
15
process . stderr . write ( `\x1b[2m\x1b[196m${ args } \x1b[0m` ) ;
16
16
}
17
+ function warn ( ...args ) {
18
+ process . stderr . write ( `\x1b[2m\x1b[91m${ args } \x1b[0m` ) ;
19
+ }
17
20
function err ( ...args ) {
18
21
process . stderr . write ( `\x1b[0;31m${ args } \x1b[0m` ) ;
19
22
}
@@ -63,7 +66,7 @@ async function createPage(headless, ignoreHTTPSErrors) {
63
66
const context = await browser . newContext ( { ignoreHTTPSErrors : ignoreHTTPSErrors } ) ;
64
67
const page = await context . newPage ( ) ;
65
68
page . on ( 'console' , msg => out ( "> CONSOLE:" , ( msg . text ( ) + ' - ' + msg . location ( ) . url ) . replace ( / \s + / g, ' ' ) , '\n' ) ) ;
66
- page . on ( 'pageerror' , e => err ( "> PAGEERROR :" , ( '' + e ) . replace ( / \s + / g, ' ' ) , '\n' ) ) ;
69
+ page . on ( 'pageerror' , e => warn ( "> JSERROR :" , ( '' + e ) . replace ( / \s + / g, ' ' ) , '\n' ) ) ;
67
70
page . browser = browser ;
68
71
return page ;
69
72
}
@@ -80,7 +83,7 @@ async function takeScreenshot(page, name, descr) {
80
83
const file = `${ screenshots } /${ scr } -${ cnt } -${ descr } .png` ;
81
84
await page . waitForTimeout ( 1000 ) ;
82
85
await page . screenshot ( { path : file } ) ;
83
- out ( `Screenshot taken: ${ file } \n` ) ;
86
+ out ( ` 📸 Screenshot taken: ${ file } \n` ) ;
84
87
}
85
88
86
89
// Wait for the server to be ready and to get a valid response
@@ -93,29 +96,31 @@ async function waitForServerReady(page, url, options = {}) {
93
96
log ( `Opening ${ url } \n` ) ;
94
97
for ( let attempt = 0 ; attempt < maxRetries ; attempt ++ ) {
95
98
try {
96
- const response = await page . goto ( url ) ;
99
+ const response = await page . goto ( url , { timeou : 120000 } ) ;
97
100
// Check if the response status is not 503
98
101
if ( response && response . status ( ) < 400 ) {
99
- out ( `Attempt ${ attempt } Server is ready and returned a valid response. ${ response . status ( ) } \n` ) ;
102
+ out ( ` ⏲ Attempt ${ attempt } Server is ready and returned a valid response. ${ response . status ( ) } \n` ) ;
100
103
return response ;
101
104
} else {
102
- out ( `Attempt ${ attempt } Server is not ready yet. ${ response . status ( ) } \n` ) ;
105
+ out ( ` ⏲ Attempt ${ attempt } Server is not ready yet. ${ response . status ( ) } \n` ) ;
103
106
}
104
107
} catch ( error ) {
105
108
if ( error . message . includes ( 'net::ERR_CERT_AUTHORITY_INVALID' ) ) {
106
- err ( `Attempt ${ attempt } Server has not a valid certificate, install it for ${ url } or use --notls flag\n` ) ;
109
+ err ( ` ⏲ Attempt ${ attempt } Server has not a valid certificate, install it for ${ url } or use --notls flag\n` ) ;
107
110
} else {
108
- err ( `Attempt ${ attempt } Server failed with error: ${ error . message } \n` ) ;
111
+ err ( ` ⏲ Attempt ${ attempt } Server failed with error: ${ error . message } \n` ) ;
112
+ }
113
+ if ( attempt >= 10 ) {
114
+ throw new Error ( `Server Error ${ error } .\n` ) ;
109
115
}
110
- throw new Error ( `Server Error ${ error } .\n` ) ;
111
116
}
112
117
await page . waitForTimeout ( retryInterval ) ;
113
118
}
114
119
throw new Error ( `Server did not become ready after ${ maxRetries } attempts.\n` ) ;
115
120
}
116
121
117
122
module . exports = {
118
- log, out, err,
123
+ log, out, err, warn ,
119
124
run,
120
125
args,
121
126
createPage,
0 commit comments