This turned out to be more time consuming than I’d like. I was testing a Node.js program that would log to stdout as prescribed by
The 12 Factor Apps - Logs page.
Say you have something like
We want to execute the program under test, allow it to
print to stdout and then make assertions about the output.
AVA test runner would report a passing test if it reached the end of
the test without error. To avoid this I would have to wrap the exec call
in a Promise.
utilize exec’s option.SERVER_PORT option with different port values for every test to allow your test suite to run tests and server processes in parallel.
exec’s callback is executed after the process terminates. Since we are
testing a long running process we need to explicitly terminate the server by sending it a SIGTERM signal. Above we do so in a setTimeout.