Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding tests for CLI functionality - brainstorming #1694

Closed
jywarren opened this issue Jul 10, 2020 · 4 comments · Fixed by #1718
Closed

adding tests for CLI functionality - brainstorming #1694

jywarren opened this issue Jul 10, 2020 · 4 comments · Fixed by #1718

Comments

@jywarren
Copy link
Member

jywarren commented Jul 10, 2020

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 #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: tj/commander.js#438

@jywarren jywarren changed the title tests for CLI functionality - brainstorming adding tests for CLI functionality - brainstorming Jul 10, 2020
@jywarren
Copy link
Member Author

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

@daemon1024
Copy link
Member

daemon1024 commented Sep 15, 2020

@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 ).

@jywarren
Copy link
Member Author

@daemon1024 we'd LOVE help with this. would you be interested in submitting a PR with even a simple version of this?

@daemon1024
Copy link
Member

@jywarren i will start working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants