loading...

How would you write tests for a Node CLI?

skiilaa profile image skiilaa ・1 min read

I’m writing my new project Candy, and I’m writing a CLI for it.

The main project is tested with mocha and chia, but I’ve never seen anyone test a CLI before, nor any ways to do it.

How would you/did you approach this problem?

Discussion

markdown guide
 

I think this project github.com/sstephenson/bats can come handy! I have never used it myself though. For me, it was always enough to write tests with mocha & chai (i.e. test that arguments are parsed correctly and your internal logic). What exactly do you want to achieve by testing via CLI?

 

I think you could probably write another small app if you really need to do testing right at the CLI that know what inputs and outputs to look for. A miniature "postman" for your app. I would submit that you should first make sure everything before the CLI is tested correctly. If you have internal tests for all logic/processing/CRUD in your application there is really very little to test at the CLI. What functionality or behavior are you wanting to test there that can't be tested internally?