@@ -5,6 +5,8 @@ const BrowserCollection = require('../../lib/browser_collection')
55const EventEmitter = require ( '../../lib/events' ) . EventEmitter
66const Executor = require ( '../../lib/executor' )
77
8+ const log = require ( '../../lib/logger' ) . create ( )
9+
810describe ( 'executor' , ( ) => {
911 let emitter
1012 let capturedBrowsers
@@ -21,36 +23,85 @@ describe('executor', () => {
2123 executor . socketIoSockets = new EventEmitter ( )
2224
2325 spy = {
24- onRunStart : ( ) => null ,
25- onSocketsExecute : ( ) => null
26+ onRunStart : sinon . stub ( ) ,
27+ onSocketsExecute : sinon . stub ( ) ,
28+ onRunComplete : sinon . stub ( )
2629 }
27-
28- sinon . spy ( spy , 'onRunStart' )
29- sinon . spy ( spy , 'onSocketsExecute' )
30+ sinon . stub ( log , 'warn' )
3031
3132 emitter . on ( 'run_start' , spy . onRunStart )
33+ emitter . on ( 'run_complete' , spy . onRunComplete )
3234 executor . socketIoSockets . on ( 'execute' , spy . onSocketsExecute )
3335 } )
3436
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
3748
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+ } )
4159 } )
4260
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
4593
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
5097
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+ } )
55106 } )
56107} )
0 commit comments