Open shivanshu3 opened 7 years ago
I was having a hard time wrapping the server start/stop in beforeAll/afterAll methods in a Jest test, until I found this comment.
Indeed, the callback is called after the prototype is finished, not after the smtp server has effectively started.
In my case, the server is in the process of starting when the test starts, then the test finishes, then it tries to stop the server, but as it has not finished started yet, nothing happens, then the Smtp server finally is started : the test process never stops !
If I move the callback call just after the line you mentioned, it works great.
Is the current behaviour intended ?? or is it a bug ?
Ideally this callback should be called after the SMTP server has started listening, specifically right after this line:
logger.info('Mailin Smtp server listening on port ' + configuration.port);
Right now it only gets called if there was an error in
server.listen
, which is OK. The other place when it gets called is at the very end of the Mailin.prototype.start function, which is useless.