@@ -127,11 +127,7 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, cb) => {
127127 if ( resp . statusCode == 299 ) {
128128 messageType = Constants . messageTypes . INFO ;
129129 errorCode = 'api_deprecated' ;
130-
131- if ( build ) {
132- message = build . message ;
133- logger . info ( message ) ;
134- } else {
130+ if ( ! build ) {
135131 message = Constants . userMessages . API_DEPRECATED ;
136132 logger . info ( message ) ;
137133 }
@@ -175,87 +171,83 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, cb) => {
175171
176172async function renderReportHTML ( report_data ) {
177173 let resultsDir = 'results' ;
178- let metaCharSet = `<meta charset="utf-8">` ;
179- let metaViewPort = `<meta name="viewport" content="width=device-width, initial-scale=1"> ` ;
180- let pageTitle = `<title> BrowserStack Cypress Report </title>` ;
181- let inlineCss = `<style type="text/css"> ${ loadInlineCss ( ) } </style>` ;
182- let head = `<head> ${ metaCharSet } ${ metaViewPort } ${ pageTitle } ${ inlineCss } </head>` ;
183- let htmlOpenTag = `<!DOCTYPE HTML><html>` ;
184- let htmlClosetag = `</html>` ;
185- let bodyBuildHeader = createBodyBuildHeader ( report_data ) ;
186- let bodyBuildTable = createBodyBuildTable ( report_data ) ;
187- let bodyReporterContainer = `<div class='report-container'> ${ bodyBuildHeader } ${ bodyBuildTable } </div>` ;
188- let body = `<body> ${ bodyReporterContainer } </body>` ;
189- let html = `${ htmlOpenTag } ${ head } ${ body } ${ htmlClosetag } ` ;
190-
191174
192175 if ( ! fs . existsSync ( resultsDir ) ) {
193176 fs . mkdirSync ( resultsDir ) ;
194177 }
195178
196179 // Writing the JSON used in creating the HTML file.
197- let reportData = await cypressReportData ( report_data ) ;
180+ let jsonReportData = await getJsonReportResponse ( report_data . cypress_custom_json_report_url )
198181 fs . writeFileSync (
199182 `${ resultsDir } /browserstack-cypress-report.json` ,
200- JSON . stringify ( reportData ) ,
183+ JSON . stringify ( jsonReportData ) ,
201184 ( ) => {
202185 if ( err ) {
203186 return logger . error ( err ) ;
204187 }
205188 logger . info ( "The JSON file is saved" ) ;
206189 }
207190 ) ;
208-
191+
192+ let htmlReportData = await getHtmlReportResponse ( report_data . cypress_custom_html_report_url )
209193 // Writing the HTML file generated from the JSON data.
210- fs . writeFileSync ( `${ resultsDir } /browserstack-cypress-report.html` , html , ( ) => {
194+ fs . writeFileSync ( `${ resultsDir } /browserstack-cypress-report.html` , htmlReportData , ( ) => {
211195 if ( err ) {
212196 return logger . error ( err ) ;
213197 }
214198 logger . info ( "The HTML file was saved!" ) ;
215199 } ) ;
216200}
217201
218- async function cypressReportData ( report_data ) {
219- specFiles = Object . keys ( report_data . rows ) ;
220- combinationPromises = [ ] ;
221- for ( let spec of specFiles ) {
222- let specSessions = report_data . rows [ spec ] [ "sessions" ] ;
223- if ( specSessions . length > 0 ) {
224- for ( let combination of specSessions ) {
225- if ( utils . isUndefined ( report_data . cypress_version ) || report_data . cypress_version < "6" ) {
226- combinationPromises . push ( generateCypressCombinationSpecReportDataWithoutConfigJson ( combination ) ) ;
227- } else {
228- combinationPromises . push ( generateCypressCombinationSpecReportDataWithConfigJson ( combination ) ) ;
202+ function getHtmlReportResponse ( htmlReportUrl ) {
203+ return new Promise ( async ( resolve , reject ) => {
204+ let reportHtmlResponse = null ;
205+ request . get ( htmlReportUrl , function ( err , resp , body ) {
206+ if ( err ) {
207+ logger . error ( 'Failed to download html report' )
208+ logger . error ( utils . formatRequest ( err , resp , body ) ) ;
209+ reject ( { } ) ;
210+ } else {
211+ if ( resp . statusCode != 200 ) {
212+ logger . error ( `Non 200 response while downloading html report. Response code: ${ resp . statusCode } ` )
213+ reject ( { } ) ;
214+ } else {
215+ try {
216+ reportHtmlResponse = body ;
217+ console . log ( `roshan1: the getHtmlReportResponse ${ inspect ( reportHtmlResponse ) } ::` ) ;
218+ } catch ( err ) {
219+ logger . error ( `Report html response parsing failed. Error: ${ inspect ( err ) } ` )
220+ reject ( { } ) ;
221+ }
229222 }
230223 }
231- }
232- }
233- await Promise . all ( combinationPromises ) ;
234- return report_data ;
224+ resolve ( reportHtmlResponse ) ;
225+ } ) ;
226+ } ) ;
235227}
236228
237- function getConfigJsonResponse ( combination ) {
229+ function getJsonReportResponse ( reportJsonUrl ) {
238230 return new Promise ( async ( resolve , reject ) => {
239- configJsonResponse = null ;
240- configJsonError = false
241- request . get ( combination . tests . config_json , function ( err , resp , body ) {
231+ let reportJsonResponse = null ;
232+ request . get ( reportJsonUrl , function ( err , resp , body ) {
242233 if ( err ) {
243- configJsonError = true ;
244- reject ( [ configJsonResponse , configJsonError ] ) ;
234+ logger . error ( 'Failed to download json report' )
235+ logger . error ( utils . formatRequest ( err , resp , body ) ) ;
236+ reject ( { } ) ;
245237 } else {
246238 if ( resp . statusCode != 200 ) {
247- configJsonError = true ;
248- reject ( [ configJsonResponse , configJsonError ] ) ;
239+ logger . error ( `Non 200 response while downloading json report. Response code: ${ resp . statusCode } ` )
240+ reject ( { } ) ;
249241 } else {
250242 try {
251- configJsonResponse = JSON . parse ( body ) ;
243+ reportJsonResponse = JSON . parse ( body ) ;
252244 } catch ( err ) {
253- configJsonError = true
254- reject ( [ configJsonResponse , configJsonError ] ) ;
245+ logger . error ( `Report json response parsing failed. Error: ${ inspect ( err ) } ` )
246+ reject ( { } ) ;
255247 }
256248 }
257249 }
258- resolve ( [ configJsonResponse , configJsonError ] ) ;
250+ resolve ( reportJsonResponse ) ;
259251 } ) ;
260252 } ) ;
261253}
0 commit comments