From 3892c6d34b98f6f22fa364971000442593fc6cf6 Mon Sep 17 00:00:00 2001 From: Outsider Date: Tue, 29 May 2018 03:49:03 +0900 Subject: [PATCH] fix runner to emit start/end event Signed-off-by: Outsider --- lib/runner.js | 9 +++++++-- test/unit/mocha.spec.js | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index d105bca321..dc2092f9fa 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -851,10 +851,15 @@ Runner.prototype.run = function(fn) { filterOnly(rootSuite); } self.started = true; - self.emit('start'); + Runner.immediately(function() { + self.emit('start'); + }); + self.runSuite(rootSuite, function() { debug('finished running'); - self.emit('end'); + Runner.immediately(function() { + self.emit('end'); + }); }); } diff --git a/test/unit/mocha.spec.js b/test/unit/mocha.spec.js index 3f7145834c..7c91add7f3 100644 --- a/test/unit/mocha.spec.js +++ b/test/unit/mocha.spec.js @@ -34,6 +34,16 @@ describe('Mocha', function() { }); } ); + + it('should emit start event', function(done) { + var mocha = new Mocha(blankOpts); + mocha.run().on('start', done); + }); + + it('should emit end event', function(done) { + var mocha = new Mocha(blankOpts); + mocha.run().on('end', done); + }); }); describe('.addFile()', function() {