mocha icon indicating copy to clipboard operation
mocha copied to clipboard

Custom reporter and event handling

Open axelssonHakan opened this issue 8 years ago • 5 comments

I'm writing my own reporter and on failure taking a screenshot and saving to disc. But it seems that the event onEnd doesn't wait for my event onFailure to finish.

The process ends after on end and my screenshots is never saved to disc. Tried to push my promises in onFailure to an array and in onEnd use Promise.settle but that doesn't work.

Is there any way of running onEnd first after all other events has finished?

axelssonHakan avatar Oct 20 '15 07:10 axelssonHakan

+1 I have a similar problem where I am trying to get a reporter to post the results to testrail, but mocha will not wait for callbacks or promises and just kills the reporter when the tests end.

jaydlawrence avatar Feb 12 '16 11:02 jaydlawrence

@jaydlawrence Nice to know there are peeps out there looking to do testrail mocha integration.

Did you guys have any luck with this ?

mekdev avatar Apr 27 '16 06:04 mekdev

It does not, I believe it is related to Process event exit. I was able to successfully fork and do some additional work.

carsonreinke avatar Jun 23 '16 18:06 carsonreinke

I know Runner#run will invoke end game processing. But the reporter's onEnd handler should have been registered to run prior to the runner's handler. After your reporter registers your end handler, where does it show up positionally?

runner.listeners('end').forEach(function(func) {
  console.log(func.toString());
});

It can be forced to the front using this method instead of Emitter#on

runner.prependListener('end', onReporterEnd);

@axelssonHakan, @jaydlawrence, @carsonreinke: Do any of you have code that demonstrates the problem for testing?

plroebuck avatar Oct 29 '18 01:10 plroebuck

Hello there, does any of participants have update in this issue? I'm currently trying to write custom reporter to azure devops for Cypress and facing same issue (async HTTP request call at the end of run isn't proceeded).

MartinPilny avatar Mar 17 '22 13:03 MartinPilny

This open question has existed for quite a while without a concrete answer. Per #5027 we've moved question-asking to Discord. If you're reading this and interested, please:

  1. Search other issues for what you're trying to do
  2. Ask there or StackOverflow

Cheers!

JoshuaKGoldberg avatar Dec 28 '23 00:12 JoshuaKGoldberg