@@ -4,6 +4,7 @@ const request = require("request"),
4
4
utils = require ( "../utils" ) ,
5
5
logger = require ( "../logger" ) . syncCliLogger ,
6
6
async = require ( 'async' ) ,
7
+ Constants = require ( "../constants" ) ,
7
8
tableStream = require ( 'table' ) . createStream ,
8
9
chalk = require ( 'chalk' ) ;
9
10
@@ -30,26 +31,7 @@ let getOptions = (auth, build_id) => {
30
31
31
32
let getTableConfig = ( ) => {
32
33
return {
33
- border : {
34
- topBody : `-` ,
35
- topJoin : `` ,
36
- topLeft : `` ,
37
- topRight : `` ,
38
-
39
- bottomBody : `-` ,
40
- bottomJoin : `` ,
41
- bottomLeft : `` ,
42
- bottomRight : `` ,
43
-
44
- bodyLeft : `` ,
45
- bodyRight : `` ,
46
- bodyJoin : `` ,
47
-
48
- joinBody : `` ,
49
- joinLeft : `` ,
50
- joinRight : `` ,
51
- joinJoin : ``
52
- } ,
34
+ border : getBorderConfig ( ) ,
53
35
singleLine : true ,
54
36
columns : {
55
37
0 : { alignment : 'right' }
@@ -61,33 +43,52 @@ let getTableConfig = () => {
61
43
} ;
62
44
}
63
45
46
+ let getBorderConfig = ( ) => {
47
+ return {
48
+ topBody : `-` ,
49
+ topJoin : `` ,
50
+ topLeft : `` ,
51
+ topRight : `` ,
52
+
53
+ bottomBody : `-` ,
54
+ bottomJoin : `` ,
55
+ bottomLeft : `` ,
56
+ bottomRight : `` ,
57
+
58
+ bodyLeft : `` ,
59
+ bodyRight : `` ,
60
+ bodyJoin : `` ,
61
+
62
+ joinBody : `` ,
63
+ joinLeft : `` ,
64
+ joinRight : `` ,
65
+ joinJoin : ``
66
+ }
67
+ }
68
+
64
69
let printSpecsStatus = ( bsConfig , buildDetails ) => {
65
70
return new Promise ( ( resolve , reject ) => {
66
71
options = getOptions ( bsConfig . auth , buildDetails . build_id )
67
72
tableConfig = getTableConfig ( ) ;
68
73
stream = tableStream ( tableConfig ) ;
69
74
70
75
async . whilst (
71
- function ( ) {
76
+ function ( ) { // condition for loop
72
77
return whileLoop ;
73
78
} ,
74
- function ( callback ) {
79
+ function ( callback ) { // actual loop
75
80
whileProcess ( callback )
76
81
} ,
77
- function ( err , result ) {
78
- if ( err ) {
79
- reject ( err )
80
- } else {
81
- specSummary . duration = endTime - startTime
82
- logger . info ( ) ;
83
- resolve ( specSummary )
84
- }
82
+ function ( err , result ) { // when loop ends
83
+ specSummary . duration = endTime - startTime
84
+ logger . info ( ) ;
85
+ resolve ( specSummary )
85
86
}
86
87
) ;
87
88
} ) ;
88
89
} ;
89
90
90
- function whileProcess ( whilstCallback ) {
91
+ let whileProcess = ( whilstCallback ) => {
91
92
request . post ( options , function ( error , response , body ) {
92
93
if ( error ) {
93
94
return whilstCallback ( error ) ;
@@ -107,10 +108,6 @@ function whileProcess(whilstCallback) {
107
108
return whilstCallback ( null , body ) ;
108
109
default :
109
110
whileLoop = false ;
110
- whileTries -= 1 ;
111
- if ( whileTries === 0 ) {
112
- return whilstCallback ( { status : 504 , message : "Tries limit reached" } ) ; //Gateway Timeout
113
- }
114
111
return whilstCallback ( { status : response . statusCode , message : body } ) ;
115
112
}
116
113
} ) ;
@@ -120,33 +117,40 @@ let showSpecsStatus = (data) => {
120
117
let specData = JSON . parse ( data ) ;
121
118
specData . forEach ( specDetails => {
122
119
if ( specDetails == "created" ) {
123
- startTime = Date . now ( ) ;
124
- logger . info ( "Running Tests: ..." )
125
- n = 10
120
+ printInitialLog ( ) ;
126
121
} else {
127
122
try {
128
- specDetails = JSON . parse ( specDetails )
129
- printSpecData ( specDetails )
123
+ printSpecData ( JSON . parse ( specDetails ) )
130
124
} catch ( error ) {
131
125
}
132
126
}
133
127
} ) ;
134
128
}
135
129
130
+ let printInitialLog = ( ) => {
131
+ startTime = Date . now ( ) ;
132
+ logger . info ( Constants . syncCLI . LOGS . INIT_LOG )
133
+ n = Constants . syncCLI . INITIAL_DELAY_MULTIPLIER
134
+ }
135
+
136
136
let printSpecData = ( data ) => {
137
137
let combination = getCombinationName ( data [ "spec" ] ) ;
138
- let specName = data [ "path" ]
139
138
let status = getStatus ( data [ "spec" ] [ "status" ] ) ;
139
+ writeToTable ( combination , data [ "path" ] , status )
140
+ addSpecToSummary ( data [ "path" ] , data [ "spec" ] [ "status" ] , combination , data [ "session_id" ] )
141
+ }
140
142
143
+ let writeToTable = ( combination , specName , status ) => {
141
144
stream . write ( [ combination + ":" , `${ specName } ${ status } ` ] ) ;
145
+ }
142
146
143
- // for part 3
144
- // Format: {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
147
+ let addSpecToSummary = ( specName , status , combination , session_id ) => {
148
+ // Format for part 3 : {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
145
149
specSummary [ "specs" ] . push ( {
146
150
"specName" : specName ,
147
- "status" : data [ "spec" ] [ " status" ] ,
151
+ "status" : status ,
148
152
"combination" : combination ,
149
- "sessionId" : data [ " session_id" ]
153
+ "sessionId" : session_id
150
154
} )
151
155
}
152
156
0 commit comments