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.
Some tips:
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.