@@ -4,7 +4,8 @@ const fs = require('fs'),
4
4
logger = require ( './logger' ) . winstonLogger ,
5
5
utils = require ( "./utils" ) ,
6
6
Constants = require ( './constants' ) ,
7
- config = require ( "./config" ) ;
7
+ config = require ( "./config" ) ,
8
+ axios = require ( "axios" ) ;
8
9
9
10
let templatesDir = path . join ( __dirname , '../' , 'templates' ) ;
10
11
@@ -173,7 +174,7 @@ let reportGenerator = (bsConfig, buildId, args, cb) => {
173
174
} ) ;
174
175
}
175
176
176
- function renderReportHTML ( report_data ) {
177
+ async function renderReportHTML ( report_data ) {
177
178
let resultsDir = 'results' ;
178
179
let metaCharSet = `<meta charset="utf-8">` ;
179
180
let metaViewPort = `<meta name="viewport" content="width=device-width, initial-scale=1"> ` ;
@@ -194,12 +195,17 @@ function renderReportHTML(report_data) {
194
195
}
195
196
196
197
// Writing the JSON used in creating the HTML file.
197
- fs . writeFileSync ( `${ resultsDir } /browserstack-cypress-report.json` , JSON . stringify ( report_data ) , ( ) => {
198
- if ( err ) {
199
- return logger . error ( err ) ;
198
+ let reportData = await cypressReportData ( report_data ) ;
199
+ fs . writeFileSync (
200
+ `${ resultsDir } /browserstack-cypress-report.json` ,
201
+ JSON . stringify ( reportData ) ,
202
+ ( ) => {
203
+ if ( err ) {
204
+ return logger . error ( err ) ;
205
+ }
206
+ logger . info ( "The JSON file is saved" ) ;
200
207
}
201
- logger . info ( "The JSON file is saved" ) ;
202
- } ) ;
208
+ ) ;
203
209
204
210
// Writing the HTML file generated from the JSON data.
205
211
fs . writeFileSync ( `${ resultsDir } /browserstack-cypress-report.html` , html , ( ) => {
@@ -210,4 +216,54 @@ function renderReportHTML(report_data) {
210
216
} ) ;
211
217
}
212
218
219
+ async function cypressReportData ( report_data ) {
220
+ specFiles = Object . keys ( report_data . rows ) ;
221
+ combinationPromises = [ ] ;
222
+ for ( let spec of specFiles ) {
223
+ let specSessions = report_data . rows [ spec ] [ "sessions" ] ;
224
+ if ( specSessions . length > 0 ) {
225
+ for ( let combination of specSessions ) {
226
+ combinationPromises . push ( generateCypressCombinationSpecReportData ( combination ) ) ;
227
+ }
228
+ }
229
+ }
230
+ await Promise . all ( combinationPromises ) ;
231
+ return report_data ;
232
+ }
233
+
234
+ function generateCypressCombinationSpecReportData ( combination ) {
235
+ return new Promise ( async ( resolve , reject ) => {
236
+ try {
237
+ let [ configJsonResponse , resultsJsonResponse ] = await axios . all ( [
238
+ axios . get ( combination . tests . config_json ) ,
239
+ axios . get ( combination . tests . result_json )
240
+ ] ) ;
241
+ let tests = { } ;
242
+ let configJson = configJsonResponse . data ;
243
+ let resultsJson = resultsJsonResponse . data ;
244
+ configJson . tests . forEach ( ( test ) => {
245
+ tests [ test [ "clientId" ] ] = test ;
246
+ } ) ;
247
+ resultsJson . tests . forEach ( ( test ) => {
248
+ tests [ test [ "clientId" ] ] = Object . assign (
249
+ tests [ test [ "clientId" ] ] ,
250
+ test
251
+ ) ;
252
+ } ) ;
253
+ let sessionTests = [ ] ;
254
+ Object . keys ( tests ) . forEach ( ( testId ) => {
255
+ sessionTests . push ( {
256
+ name : tests [ testId ] [ "title" ] . pop ( ) ,
257
+ status : tests [ testId ] [ "state" ] ,
258
+ duration : parseFloat (
259
+ tests [ testId ] [ "attempts" ] . pop ( ) [ "wallClockDuration" ] / 1000
260
+ ) . toFixed ( 2 ) ,
261
+ } ) ;
262
+ } ) ;
263
+ combination . tests = sessionTests ;
264
+ resolve ( combination . tests ) ;
265
+ } catch ( error ) { reject ( error ) }
266
+ } )
267
+ }
268
+
213
269
exports . reportGenerator = reportGenerator ;
0 commit comments