Skip to content

Commit

Permalink
Ensure we call done() on the async onExit to not prevent exitting aft…
Browse files Browse the repository at this point in the history
…er single run. Fixes #5
  • Loading branch information
joeljeske committed Feb 5, 2018
1 parent 045c3f4 commit cad4bbf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,17 @@ const AggregatedCoverageReporter = function(injector, logger, config, baseReport
};

this.onExit = function(done) {
callThrough('onExit', done);
// We cannot call callThrough here as we must determine when all relevant reporters have called done()
const promises = reporters.map(({name, reporter}) => new Promise((resolve) => {
if (_.isFunction(reporter.onExit)) {
log.debug(`relaying done() on reporter:${name}`);
reporter.onExit(() => resolve());
} else {
resolve();
}
}));

Promise.all(promises).then(() => done());
};
};

Expand Down

0 comments on commit cad4bbf

Please sign in to comment.