@@ -127,11 +127,7 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, cb) => {
127
127
if ( resp . statusCode == 299 ) {
128
128
messageType = Constants . messageTypes . INFO ;
129
129
errorCode = 'api_deprecated' ;
130
-
131
- if ( build ) {
132
- message = build . message ;
133
- logger . info ( message ) ;
134
- } else {
130
+ if ( ! build ) {
135
131
message = Constants . userMessages . API_DEPRECATED ;
136
132
logger . info ( message ) ;
137
133
}
@@ -175,87 +171,83 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, cb) => {
175
171
176
172
async function renderReportHTML ( report_data ) {
177
173
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
-
191
174
192
175
if ( ! fs . existsSync ( resultsDir ) ) {
193
176
fs . mkdirSync ( resultsDir ) ;
194
177
}
195
178
196
179
// 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 )
198
181
fs . writeFileSync (
199
182
`${ resultsDir } /browserstack-cypress-report.json` ,
200
- JSON . stringify ( reportData ) ,
183
+ JSON . stringify ( jsonReportData ) ,
201
184
( ) => {
202
185
if ( err ) {
203
186
return logger . error ( err ) ;
204
187
}
205
188
logger . info ( "The JSON file is saved" ) ;
206
189
}
207
190
) ;
208
-
191
+
192
+ let htmlReportData = await getHtmlReportResponse ( report_data . cypress_custom_html_report_url )
209
193
// 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 , ( ) => {
211
195
if ( err ) {
212
196
return logger . error ( err ) ;
213
197
}
214
198
logger . info ( "The HTML file was saved!" ) ;
215
199
} ) ;
216
200
}
217
201
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
+ }
229
222
}
230
223
}
231
- }
232
- }
233
- await Promise . all ( combinationPromises ) ;
234
- return report_data ;
224
+ resolve ( reportHtmlResponse ) ;
225
+ } ) ;
226
+ } ) ;
235
227
}
236
228
237
- function getConfigJsonResponse ( combination ) {
229
+ function getJsonReportResponse ( reportJsonUrl ) {
238
230
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 ) {
242
233
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 ( { } ) ;
245
237
} else {
246
238
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 ( { } ) ;
249
241
} else {
250
242
try {
251
- configJsonResponse = JSON . parse ( body ) ;
243
+ reportJsonResponse = JSON . parse ( body ) ;
252
244
} catch ( err ) {
253
- configJsonError = true
254
- reject ( [ configJsonResponse , configJsonError ] ) ;
245
+ logger . error ( `Report json response parsing failed. Error: ${ inspect ( err ) } ` )
246
+ reject ( { } ) ;
255
247
}
256
248
}
257
249
}
258
- resolve ( [ configJsonResponse , configJsonError ] ) ;
250
+ resolve ( reportJsonResponse ) ;
259
251
} ) ;
260
252
} ) ;
261
253
}
0 commit comments