@@ -38,6 +38,7 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
3838 utils . sendUsageReport ( bsConfig , args , message , messageType , errorCode , buildReportData , rawArgs ) ;
3939 return ;
4040 } else {
41+ logger . debug ( 'Received reports data from upstream.' ) ;
4142 try {
4243 build = JSON . parse ( body ) ;
4344 } catch ( error ) {
@@ -98,12 +99,16 @@ async function generateCypressBuildReport(report_data) {
9899 let resultsDir = path . join ( './' , 'results' ) ;
99100
100101 if ( ! fs . existsSync ( resultsDir ) ) {
101- logger . debug ( "results directory doesn't exists" ) ;
102- logger . info ( ) ;
103- logger . debug ( "creating results directory" ) ;
102+ logger . debug ( "Results directory doesn't exists." ) ;
103+ logger . debug ( "Creating results directory." ) ;
104104 fs . mkdirSync ( resultsDir ) ;
105105 }
106- await getReportResponse ( resultsDir , 'report.zip' , report_data . cypress_custom_report_url )
106+ getReportResponse ( resultsDir , 'report.zip' , report_data . cypress_custom_report_url ) . then ( ( message ) => {
107+ logger . debug ( message ) ;
108+ } ) . catch ( ( errorMessage ) => {
109+ logger . error ( errorMessage ) ;
110+ process . exitCode = Constants . ERROR_EXIT_CODE ;
111+ } ) ;
107112}
108113
109114function getReportResponse ( filePath , fileName , reportJsonUrl ) {
@@ -113,7 +118,8 @@ function getReportResponse(filePath, fileName, reportJsonUrl) {
113118 request . get ( reportJsonUrl ) . on ( 'response' , function ( response ) {
114119
115120 if ( response . statusCode != 200 ) {
116- reject ( ) ;
121+ let message = `Received non 200 response while fetching reports, code: ${ response . statusCode } ` ;
122+ reject ( message ) ;
117123 } else {
118124 //ensure that the user can call `then()` only when the file has
119125 //been downloaded entirely.
@@ -127,9 +133,14 @@ function getReportResponse(filePath, fileName, reportJsonUrl) {
127133 writer . on ( 'close' , async ( ) => {
128134 if ( ! error ) {
129135 logger . debug ( "Unzipping downloaded html and json reports." ) ;
130- await unzipFile ( filePath , fileName ) ;
136+ unzipFile ( filePath , fileName ) . then ( ( message ) => {
137+ logger . debug ( message ) ;
138+ } ) . catch ( ( err ) => {
139+ logger . debug ( `Unzipping html and json report failed. Error: ${ err } ` ) ;
140+ } ) ;
131141 fs . unlinkSync ( tmpFilePath ) ;
132- resolve ( true ) ;
142+ let message = "Successfully prepared json and html reports." ;
143+ resolve ( message ) ;
133144 }
134145 //no need to call the reject here, as it will have been called in the
135146 //'error' stream;
@@ -142,9 +153,11 @@ function getReportResponse(filePath, fileName, reportJsonUrl) {
142153const unzipFile = async ( filePath , fileName ) => {
143154 return new Promise ( async ( resolve , reject ) => {
144155 await unzipper . Open . file ( path . join ( filePath , fileName ) )
145- . then ( d => d . extract ( { path : filePath , concurrency : 5 } ) )
146- . catch ( ( err ) => reject ( err ) ) ;
147- resolve ( ) ;
156+ . then ( ( d ) => {
157+ d . extract ( { path : filePath , concurrency : 5 } ) ;
158+ } ) . catch ( ( err ) => reject ( err ) ) ;
159+ let message = "Unzipped the json and html successfully."
160+ resolve ( message ) ;
148161 } ) ;
149162}
150163
0 commit comments