my nodejs module starts a server on a specific port, I am wondering if it is a way to stop the execution of that server in my mocha test:
Let's assume that myserver.js contains something like:
myserver = http.Server(app);
....
process.on('SIGTERM', ()=>{ ... });
and in my mocha test, If I do something like this: in order to load my class:
it(' starts the execution and then stop the server() {
require('../myserver.js');
????
}
How can I stop the execution from test case?
I was wondering if I could send a SIGTERM message to that process, but I should discover the pid of that process first, maybe it is not worth to do that.
I assume that I could export from my module a function that is then used from other modules in some specific circumstances, like the one I want to test, in order to stop the overall execution.