Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: listen to 'start' and 'end' events when using Mocha programmatically #3660

Merged
merged 1 commit into from Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/runner.js
Expand Up @@ -939,7 +939,9 @@ Runner.prototype.run = function(fn) {
this.emit(constants.EVENT_DELAY_BEGIN, rootSuite);
rootSuite.once(EVENT_ROOT_SUITE_RUN, start);
} else {
start();
Runner.immediately(function() {
start();
});
}

return this;
Expand Down
10 changes: 10 additions & 0 deletions test/unit/mocha.spec.js
Expand Up @@ -487,6 +487,16 @@ describe('Mocha', function() {
}, 'not to throw');
});

it('should catch the `start` event if no tests are provided', function(done) {
var mocha = new Mocha(opts);
mocha.run().on('start', done);
});

it('should catch the `end` event if no tests are provided', function(done) {
var mocha = new Mocha(opts);
mocha.run().on('end', done);
});

describe('#reporter("xunit")#run(fn)', function() {
// :TBD: Why does specifying reporter differentiate this test from preceding one
it('should not raise errors if callback was not provided', function() {
Expand Down