1
1
'use strict' ;
2
- const config = require ( "./config" ) ,
2
+ const Config = require ( "./config" ) ,
3
3
logger = require ( "./logger" ) . syncCliLogger ,
4
4
Constants = require ( "./constants" ) ,
5
5
utils = require ( "./utils" ) ,
6
- request = require ( 'request' ) ;
6
+ request = require ( 'request' ) ,
7
+ { table, getBorderCharacters } = require ( 'table' ) ,
8
+ chalk = require ( 'chalk' ) ;
7
9
8
10
exports . pollBuildStatus = ( bsConfig , buildId ) => {
9
11
logBuildDetails ( ) . then ( ( data ) => {
10
12
printSpecsStatus ( ) ;
11
13
} ) . then ( ( data ) => {
12
14
printSpecsRunSummary ( ) ;
13
15
} ) . then ( ( data ) => {
14
- printFailedSpecsDetails ( ) ;
15
- } ) . then ( ( data ) => {
16
- printBuildDashboardLink ( buildId ) ;
17
- } ) . then ( ( data ) => {
18
- // success case!
19
- return 0 ; // exit code 0
20
- } ) . catch ( ( err ) => {
21
- // failed case!
22
- return 1 ; // exit code 1
16
+ printFailedSpecsDetails ( data ) ;
17
+ } ) . then ( ( successExitCode ) => {
18
+ return resolveExitCode ( successExitCode ) ; // exit code 0
19
+ } ) . catch ( ( nonZeroExitCode ) => {
20
+ return resolveExitCode ( nonZeroExitCode ) ; // exit code 1
21
+ } ) . finally ( ( ) => {
22
+ logger . info ( Constants . userMessages . BUILD_REPORT_MESSAGE ) ;
23
+ logger . info ( `${ Config . dashboardUrl } ${ buildId } ` ) ;
23
24
} ) ;
24
25
} ;
25
26
@@ -35,13 +36,68 @@ let printSpecsRunSummary = () => {
35
36
36
37
} ;
37
38
38
- let printFailedSpecsDetails = ( ) => {
39
+ /**
40
+ *
41
+ * @param {Array.<{specName: string, status: string, combination: string, sessionId: string}> } data
42
+ * @returns {Promise.resolve || Promise.reject }
43
+ */
44
+ // Example:
45
+ // [
46
+ // {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
47
+ // {specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
48
+ // {specName: 'spec3.network.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
49
+ // {specName: 'spec6.utils.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
50
+ // {specName: 'spec8.alias.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
51
+ // ]
52
+ let printFailedSpecsDetails = ( data ) => {
53
+ return new Promise ( ( resolve , reject ) => {
54
+ if ( data . length === 0 ) resolve ( 0 ) ; // return if no failed/skipped tests.
39
55
40
- } ;
56
+ let failedSpecs = false ;
57
+ let specResultHeader = Constants . syncCLI . FAILED_SPEC_DETAILS_COL_HEADER . map ( ( col ) => {
58
+ return chalk . blueBright ( col ) ;
59
+ } ) ;
41
60
42
- let printBuildDashboardLink = ( buildId ) => {
43
- new Promise ( ( resolve , reject ) => {
44
- logger . info ( Constants . userMessages . BUILD_REPORT_MESSAGE ) ;
45
- logger . info ( `${ config . dashboardUrl } ${ buildId } ` ) ;
61
+ let specData = [ specResultHeader ] ; // 2-D array
62
+
63
+ data . forEach ( ( spec ) => {
64
+ if ( spec . status && spec . status . toLowerCase ( ) === 'failed' && ! failedSpecs )
65
+ failedSpecs = true ;
66
+
67
+ let specStatus = ( spec . status && spec . status . toLowerCase ( ) === 'failed' ) ?
68
+ chalk . red ( spec . status ) : chalk . yellow ( spec . status ) ;
69
+ specData . push ( [ spec . specName , specStatus , spec . combination , spec . sessionId ] ) ;
70
+ } ) ;
71
+
72
+ let config = {
73
+ border : getBorderCharacters ( 'ramac' ) ,
74
+ columns : {
75
+ 0 : { alignment : 'center' } ,
76
+ 1 : { alignment : 'center' } ,
77
+ 2 : { alignment : 'center' } ,
78
+ 3 : { alignment : 'center' } ,
79
+ } ,
80
+ /**
81
+ * @typedef {function } drawHorizontalLine
82
+ * @param {number } index
83
+ * @param {number } size
84
+ * @return {boolean }
85
+ */
86
+ drawHorizontalLine : ( index , size ) => {
87
+ return ( index === 0 || index === 1 || index === size ) ;
88
+ }
89
+ }
90
+
91
+ let result = table ( specData , config ) ;
92
+
93
+ logger . info ( 'Failed / skipped test report' ) ;
94
+ logger . info ( result ) ;
95
+
96
+ if ( failedSpecs ) reject ( 1 ) ; // specs failed, send exitCode as 1
97
+ resolve ( 0 ) ; // No Specs failed, maybe skipped, but not failed, send exitCode as 0
46
98
} ) ;
47
99
} ;
100
+
101
+ let resolveExitCode = ( exitCode ) => {
102
+ return new Promise ( ( resolve , _reject ) => { resolve ( exitCode ) } ) ;
103
+ } ;
0 commit comments