@@ -4,6 +4,7 @@ const request = require("request"),
44 utils = require ( "../utils" ) ,
55 logger = require ( "../logger" ) . syncCliLogger ,
66 async = require ( 'async' ) ,
7+ Constants = require ( "../constants" ) ,
78 tableStream = require ( 'table' ) . createStream ,
89 chalk = require ( 'chalk' ) ;
910
@@ -30,26 +31,7 @@ let getOptions = (auth, build_id) => {
3031
3132let getTableConfig = ( ) => {
3233 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 ( ) ,
5335 singleLine : true ,
5436 columns : {
5537 0 : { alignment : 'right' }
@@ -61,33 +43,52 @@ let getTableConfig = () => {
6143 } ;
6244}
6345
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+
6469let printSpecsStatus = ( bsConfig , buildDetails ) => {
6570 return new Promise ( ( resolve , reject ) => {
6671 options = getOptions ( bsConfig . auth , buildDetails . build_id )
6772 tableConfig = getTableConfig ( ) ;
6873 stream = tableStream ( tableConfig ) ;
6974
7075 async . whilst (
71- function ( ) {
76+ function ( ) { // condition for loop
7277 return whileLoop ;
7378 } ,
74- function ( callback ) {
79+ function ( callback ) { // actual loop
7580 whileProcess ( callback )
7681 } ,
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 )
8586 }
8687 ) ;
8788 } ) ;
8889} ;
8990
90- function whileProcess ( whilstCallback ) {
91+ let whileProcess = ( whilstCallback ) => {
9192 request . post ( options , function ( error , response , body ) {
9293 if ( error ) {
9394 return whilstCallback ( error ) ;
@@ -107,10 +108,6 @@ function whileProcess(whilstCallback) {
107108 return whilstCallback ( null , body ) ;
108109 default :
109110 whileLoop = false ;
110- whileTries -= 1 ;
111- if ( whileTries === 0 ) {
112- return whilstCallback ( { status : 504 , message : "Tries limit reached" } ) ; //Gateway Timeout
113- }
114111 return whilstCallback ( { status : response . statusCode , message : body } ) ;
115112 }
116113 } ) ;
@@ -120,33 +117,40 @@ let showSpecsStatus = (data) => {
120117 let specData = JSON . parse ( data ) ;
121118 specData . forEach ( specDetails => {
122119 if ( specDetails == "created" ) {
123- startTime = Date . now ( ) ;
124- logger . info ( "Running Tests: ..." )
125- n = 10
120+ printInitialLog ( ) ;
126121 } else {
127122 try {
128- specDetails = JSON . parse ( specDetails )
129- printSpecData ( specDetails )
123+ printSpecData ( JSON . parse ( specDetails ) )
130124 } catch ( error ) {
131125 }
132126 }
133127 } ) ;
134128}
135129
130+ let printInitialLog = ( ) => {
131+ startTime = Date . now ( ) ;
132+ logger . info ( Constants . syncCLI . LOGS . INIT_LOG )
133+ n = Constants . syncCLI . INITIAL_DELAY_MULTIPLIER
134+ }
135+
136136let printSpecData = ( data ) => {
137137 let combination = getCombinationName ( data [ "spec" ] ) ;
138- let specName = data [ "path" ]
139138 let status = getStatus ( data [ "spec" ] [ "status" ] ) ;
139+ writeToTable ( combination , data [ "path" ] , status )
140+ addSpecToSummary ( data [ "path" ] , data [ "spec" ] [ "status" ] , combination , data [ "session_id" ] )
141+ }
140142
143+ let writeToTable = ( combination , specName , status ) => {
141144 stream . write ( [ combination + ":" , `${ specName } ${ status } ` ] ) ;
145+ }
142146
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...'},
145149 specSummary [ "specs" ] . push ( {
146150 "specName" : specName ,
147- "status" : data [ "spec" ] [ " status" ] ,
151+ "status" : status ,
148152 "combination" : combination ,
149- "sessionId" : data [ " session_id" ]
153+ "sessionId" : session_id
150154 } )
151155}
152156
0 commit comments