datproject-discussions
datproject-discussions copied to clipboard
cli process spawning test module
for testing cli modules more better we need a module that:
- is designed around use with
tape
e.g. you pass in a tape test instance - uses
tree-kill
to cleanup child processes after the test is done - uses
win-spawn
to spawn processes correctly on windows - has a debug mode where if you do e.g.
DEBUG=* npm test
it will stream the child process stdout/stderr to the parent stdout/stderr - lets you choose how to handle child stdout/stderr output in a few different ways
- buffer all stdout or stderr output (or both)
- get the first buffer of output from stdout/stderr (one or the other or either)
- do a e.g. regex match or string indexof against output
- for all of the above it should be impossible for the child processes to become zombies if the tests crash
for reference/inspiration: https://github.com/maxogden/dat/blob/master/test/tests/cli.js#L332
@sindresorhus how do you test CLI modules cleanly? know anything that fits our criteria above?
I don't [cleanly]. I've just been lazy using spawning and checking, but this sounds really good. I could definitely use something like this.
Regarding win-spawn
: https://github.com/IndigoUnited/node-cross-spawn#why