@@ -5,6 +5,8 @@ const BrowserCollection = require('../../lib/browser_collection')
5
5
const EventEmitter = require ( '../../lib/events' ) . EventEmitter
6
6
const Executor = require ( '../../lib/executor' )
7
7
8
+ const log = require ( '../../lib/logger' ) . create ( )
9
+
8
10
describe ( 'executor' , ( ) => {
9
11
let emitter
10
12
let capturedBrowsers
@@ -21,36 +23,85 @@ describe('executor', () => {
21
23
executor . socketIoSockets = new EventEmitter ( )
22
24
23
25
spy = {
24
- onRunStart : ( ) => null ,
25
- onSocketsExecute : ( ) => null
26
+ onRunStart : sinon . stub ( ) ,
27
+ onSocketsExecute : sinon . stub ( ) ,
28
+ onRunComplete : sinon . stub ( )
26
29
}
27
-
28
- sinon . spy ( spy , 'onRunStart' )
29
- sinon . spy ( spy , 'onSocketsExecute' )
30
+ sinon . stub ( log , 'warn' )
30
31
31
32
emitter . on ( 'run_start' , spy . onRunStart )
33
+ emitter . on ( 'run_complete' , spy . onRunComplete )
32
34
executor . socketIoSockets . on ( 'execute' , spy . onSocketsExecute )
33
35
} )
34
36
35
- it ( 'should start the run and pass client config' , ( ) => {
36
- capturedBrowsers . areAllReady = ( ) => true
37
+ describe ( 'schedule' , ( ) => {
38
+ it ( 'should start the run and pass client config' , ( ) => {
39
+ capturedBrowsers . areAllReady = ( ) => true
40
+
41
+ executor . schedule ( )
42
+ expect ( spy . onRunStart ) . to . have . been . called
43
+ expect ( spy . onSocketsExecute ) . to . have . been . calledWith ( config . client )
44
+ } )
45
+
46
+ it ( 'should wait for all browsers to finish' , ( ) => {
47
+ capturedBrowsers . areAllReady = ( ) => false
37
48
38
- executor . schedule ( )
39
- expect ( spy . onRunStart ) . to . have . been . called
40
- expect ( spy . onSocketsExecute ) . to . have . been . calledWith ( config . client )
49
+ // they are not ready yet
50
+ executor . schedule ( )
51
+ expect ( spy . onRunStart ) . not . to . have . been . called
52
+ expect ( spy . onSocketsExecute ) . not . to . have . been . called
53
+
54
+ capturedBrowsers . areAllReady = ( ) => true
55
+ emitter . emit ( 'run_complete' )
56
+ expect ( spy . onRunStart ) . to . have . been . called
57
+ expect ( spy . onSocketsExecute ) . to . have . been . called
58
+ } )
41
59
} )
42
60
43
- it ( 'should wait for all browsers to finish' , ( ) => {
44
- capturedBrowsers . areAllReady = ( ) => false
61
+ describe ( 'scheduleError' , ( ) => {
62
+ it ( 'should return `true` if scheduled synchronously' , ( ) => {
63
+ const result = executor . scheduleError ( 'expected error' )
64
+ expect ( result ) . to . be . true
65
+ } )
66
+
67
+ it ( 'should emit both "run_start" and "run_complete"' , ( ) => {
68
+ executor . scheduleError ( 'expected error' )
69
+ expect ( spy . onRunStart ) . to . have . been . called
70
+ expect ( spy . onRunComplete ) . to . have . been . called
71
+ expect ( spy . onRunStart ) . to . have . been . calledBefore ( spy . onRunComplete )
72
+ } )
73
+
74
+ it ( 'should report the error' , ( ) => {
75
+ const expectedError = 'expected error'
76
+ executor . scheduleError ( expectedError )
77
+ expect ( spy . onRunComplete ) . to . have . been . calledWith ( [ ] , {
78
+ success : 0 ,
79
+ failed : 0 ,
80
+ skipped : 0 ,
81
+ error : expectedError ,
82
+ exitCode : 1
83
+ } )
84
+ } )
85
+
86
+ it ( 'should wait for scheduled runs to end before reporting the error' , ( ) => {
87
+ // Arrange
88
+ let browsersAreReady = true
89
+ const expectedError = 'expected error'
90
+ capturedBrowsers . areAllReady = ( ) => browsersAreReady
91
+ executor . schedule ( )
92
+ browsersAreReady = false
45
93
46
- // they are not ready yet
47
- executor . schedule ( )
48
- expect ( spy . onRunStart ) . not . to . have . been . called
49
- expect ( spy . onSocketsExecute ) . not . to . have . been . called
94
+ // Act
95
+ const result = executor . scheduleError ( expectedError )
96
+ browsersAreReady = true
50
97
51
- capturedBrowsers . areAllReady = ( ) => true
52
- emitter . emit ( 'run_complete' )
53
- expect ( spy . onRunStart ) . to . have . been . called
54
- expect ( spy . onSocketsExecute ) . to . have . been . called
98
+ // Assert
99
+ expect ( result ) . to . be . false
100
+ expect ( spy . onRunComplete ) . to . not . have . been . called
101
+ emitter . emit ( 'run_complete' )
102
+ expect ( spy . onRunComplete ) . to . have . been . calledWith ( [ ] , sinon . match ( {
103
+ error : expectedError
104
+ } ) )
105
+ } )
55
106
} )
56
107
} )
0 commit comments