Trying to think through the best way to do better CLI testing. Right now we have only: https://github.com/publiclab/image-sequencer/blob/440c3e0ad0ab081bdcc7dfff0d000f52a0902035/test/core/cli.js which is pretty non-existent.
Noting that we encountered this in https://github.com/publiclab/image-sequencer/issues/659 but did not at that time implement tests.
Ok, so I had thought this was the way to go, installing https://github.com/sstephenson/bats (blog https://medium.com/@pimterry/testing-your-shell-scripts-with-bats-abfca9bdc5b9) and comparing images like perhaps:
looksSame = require('looks-same');
looksSame(process.argv[2], process.argv[3], function(error, {equal}) {
// equal will be true, if images looks the same
console.log(equal ? 1 : 0);
});
But actually maybe it's just easier to use one of our existing JS tests and running our CLI tests from inside node, like this:
const { exec } = require('child_process');
var yourscript = exec('sh hi.sh',
(error, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
https://stackoverflow.com/questions/44647778/how-to-run-shell-script-file-using-nodejs#44667294 has some guidance on this.
Is there a standard way to write CLI tests for commander.js?
UPDATE: yes, it looks like there are some good ways: https://github.com/tj/commander.js/issues/438
cc @VibhorCodecianGupta @HarshKhandeparkar @blurry-x-face who've all worked on related parts of this before... hope you're well, just seeing if this seems interesting! Also @publiclab/is-reviewers @publiclab/image-sequencer-guides
@jywarren is it open to work/brainstorm on?
We can do something like
./index.js --test
and run the series of CLI tests on a new commander instance we want. ( Inspiration can be taken from how commander.js test there module themselves ( as said in the linked issue ).
@daemon1024 we'd LOVE help with this. would you be interested in submitting a PR with even a simple version of this?
@jywarren i will start working on it.