From f00567c95d74a5edd5d577ef68be98e5262a12dd 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 | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index 6aefb34cce..801ef29fc2 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -845,10 +845,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..9e10313c52 100644 --- a/test/unit/mocha.spec.js +++ b/test/unit/mocha.spec.js @@ -34,6 +34,20 @@ describe('Mocha', function() { }); } ); + + it('should emit start event', function(done) { + var mocha = new Mocha(blankOpts); + mocha.run(function() {}).on('start', function() { + done(); + }); + }); + + it('should emit end event', function(done) { + var mocha = new Mocha(blankOpts); + mocha.run(function() {}).on('end', function() { + done(); + }); + }); }); describe('.addFile()', function() {