@@ -4,11 +4,11 @@ const BrowserResult = require('./browser_result')
4
4
const helper = require ( './helper' )
5
5
const logger = require ( './logger' )
6
6
7
- const CONNECTED = 1 // The browser is connected but not yet been commanded to execute tests.
8
- const CONFIGURING = 2 // The browser has been told to execute tests; it is configuring before tests execution.
9
- const EXECUTING = 3 // The browser is executing the tests.
10
- const EXECUTING_DISCONNECTED = 4 // The browser is executing the tests, but temporarily disconnect (waiting for reconnecting).
11
- const DISCONNECTED = 5 // The browser got permanently disconnected (being removed from the collection and destroyed).
7
+ const CONNECTED = 'CONNECTED' // The browser is connected but not yet been commanded to execute tests.
8
+ const CONFIGURING = 'CONFIGURING' // The browser has been told to execute tests; it is configuring before tests execution.
9
+ const EXECUTING = 'EXECUTING' // The browser is executing the tests.
10
+ const EXECUTING_DISCONNECTED = 'EXECUTING_DISCONNECTED' // The browser is executing the tests, but temporarily disconnect (waiting for reconnecting).
11
+ const DISCONNECTED = 'DISCONNECTED' // The browser got permanently disconnected (being removed from the collection and destroyed).
12
12
13
13
class Browser {
14
14
constructor ( id , fullName , collection , emitter , socket , timer , disconnectDelay , noActivityTimeout ) {
@@ -40,6 +40,11 @@ class Browser {
40
40
this . emitter . emit ( 'browser_register' , this )
41
41
}
42
42
43
+ setState ( toState ) {
44
+ this . log . debug ( `${ this . state } -> ${ toState } ` )
45
+ this . state = toState
46
+ }
47
+
43
48
onKarmaError ( error ) {
44
49
if ( this . isNotConnected ( ) ) {
45
50
this . lastResult . error = true
@@ -70,14 +75,14 @@ class Browser {
70
75
}
71
76
72
77
this . lastResult = new BrowserResult ( info . total )
73
- this . state = EXECUTING
78
+ this . setState ( EXECUTING )
74
79
this . emitter . emit ( 'browser_start' , this , info )
75
80
this . refreshNoActivityTimeout ( )
76
81
}
77
82
78
83
onComplete ( result ) {
79
84
if ( this . isNotConnected ( ) ) {
80
- this . state = CONNECTED
85
+ this . setState ( CONNECTED )
81
86
this . lastResult . totalTimeEnd ( )
82
87
83
88
if ( ! this . lastResult . success ) {
@@ -103,7 +108,7 @@ class Browser {
103
108
this . disconnect ( `Client disconnected from CONNECTED state (${ reason } )` )
104
109
} else if ( [ CONFIGURING , EXECUTING ] . includes ( this . state ) ) {
105
110
this . log . debug ( `Disconnected during run, waiting ${ this . disconnectDelay } ms for reconnecting.` )
106
- this . state = EXECUTING_DISCONNECTED
111
+ this . setState ( EXECUTING_DISCONNECTED )
107
112
108
113
this . pendingDisconnect = this . timer . setTimeout ( ( ) => {
109
114
this . lastResult . totalTimeEnd ( )
@@ -119,12 +124,12 @@ class Browser {
119
124
reconnect ( newSocket ) {
120
125
if ( this . state === EXECUTING_DISCONNECTED ) {
121
126
this . log . debug ( `Reconnected on ${ newSocket . id } .` )
122
- this . state = EXECUTING
127
+ this . setState ( EXECUTING )
123
128
} else if ( [ CONNECTED , CONFIGURING , EXECUTING ] . includes ( this . state ) ) {
124
129
this . log . debug ( `New connection ${ newSocket . id } (already have ${ this . getActiveSocketsIds ( ) } )` )
125
130
} else if ( this . state === DISCONNECTED ) {
126
131
this . log . info ( `Connected on socket ${ newSocket . id } with id ${ this . id } ` )
127
- this . state = CONNECTED
132
+ this . setState ( CONNECTED )
128
133
129
134
this . collection . add ( this )
130
135
this . emitter . emit ( 'browser_register' , this )
@@ -155,7 +160,7 @@ class Browser {
155
160
156
161
execute ( config ) {
157
162
this . activeSockets . forEach ( ( socket ) => socket . emit ( 'execute' , config ) )
158
- this . state = CONFIGURING
163
+ this . setState ( CONFIGURING )
159
164
this . refreshNoActivityTimeout ( )
160
165
}
161
166
@@ -165,7 +170,7 @@ class Browser {
165
170
166
171
disconnect ( reason ) {
167
172
this . log . warn ( `Disconnected (${ this . disconnectsCount } times)${ reason || '' } ` )
168
- this . state = DISCONNECTED
173
+ this . setState ( DISCONNECTED )
169
174
this . disconnectsCount ++
170
175
this . emitter . emit ( 'browser_error' , this , `Disconnected${ reason || '' } ` )
171
176
this . collection . remove ( this )
0 commit comments