@@ -72,7 +72,7 @@ describe('mocha-runner/mocha-adapter', () => {
72
72
browserAgent = sinon . createStubInstance ( BrowserAgent ) ;
73
73
74
74
sandbox . stub ( MochaStub . prototype ) ;
75
- MochaStub . prototype . run . yields ( ) ;
75
+ MochaStub . prototype . run = ( cb ) => process . nextTick ( cb ) ;
76
76
MochaStub . prototype . suite = mkSuiteStub_ ( ) ;
77
77
78
78
MochaAdapter = proxyquire ( '../../../../lib/runner/mocha-runner/mocha-adapter' , {
@@ -524,8 +524,11 @@ describe('mocha-runner/mocha-adapter', () => {
524
524
525
525
attachEmitFn_ ( emitFn ) ;
526
526
527
- assert . calledOnce ( ProxyReporter . prototype . __constructor ) ;
528
- assert . calledWith ( ProxyReporter . prototype . __constructor , emitFn ) ;
527
+ const emit_ = ProxyReporter . prototype . __constructor . firstCall . args [ 0 ] ;
528
+ emit_ ( 'some-event' , { some : 'data' } ) ;
529
+
530
+ assert . calledOnce ( emitFn ) ;
531
+ assert . calledWith ( emitFn , 'some-event' , sinon . match ( { some : 'data' } ) ) ;
529
532
} ) ;
530
533
531
534
it ( 'should pass to proxy reporter getter for requested browser' , ( ) => {
@@ -552,6 +555,40 @@ describe('mocha-runner/mocha-adapter', () => {
552
555
assert . deepEqual ( getBrowser ( ) , { id : 'some-browser' } ) ;
553
556
} ) ;
554
557
558
+ describe ( 'if event handler throws' , ( ) => {
559
+ const initBadHandler_ = ( event , handler ) => {
560
+ const emitter = new EventEmitter ( ) ;
561
+ emitter . on ( event , handler ) ;
562
+
563
+ attachEmitFn_ ( emitter . emit . bind ( emitter ) ) ;
564
+ return ProxyReporter . prototype . __constructor . firstCall . args [ 0 ] ;
565
+ } ;
566
+
567
+ it ( 'proxy should rethrow error' , ( ) => {
568
+ const emit_ = initBadHandler_ ( 'foo' , ( ) => {
569
+ throw new Error ( new Error ( 'bar' ) ) ;
570
+ } ) ;
571
+
572
+ assert . throws ( ( ) => emit_ ( 'foo' ) , / b a r / ) ;
573
+ } ) ;
574
+
575
+ it ( 'run should be rejected' , ( ) => {
576
+ const emit_ = initBadHandler_ ( 'foo' , ( ) => {
577
+ throw new Error ( 'bar' ) ;
578
+ } ) ;
579
+
580
+ const promise = mochaAdapter . run ( ) ;
581
+
582
+ try {
583
+ emit_ ( 'foo' ) ;
584
+ } catch ( e ) {
585
+ // eslint иди лесом
586
+ }
587
+
588
+ return assert . isRejected ( promise , / b a r / ) ;
589
+ } ) ;
590
+ } ) ;
591
+
555
592
describe ( 'file events' , ( ) => {
556
593
beforeEach ( ( ) => MochaAdapter . init ( ) ) ;
557
594
afterEach ( ( ) => delete global . hermione ) ;
0 commit comments