dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

how do i unit test a vorpal app? #186

Closed komplexb closed 1 year ago

komplexb commented 7 years ago

Can anyone offer advice on unit testing a vorpal app? I'm unclear on how to setup my assertions. i.e. what do I run to get values to compare against?

http://stackoverflow.com/questions/40247962/how-do-i-approach-unit-testing-a-vorpal-cli-app

Shakyamuni177te commented 7 years ago

Will be interesting to see if this is a documentation or a feature request issue. :)

komplexb commented 7 years ago

@Shakyamuni177te lol, well i did see a "questions" label. I'll cross post to the SO channel.

LongLiveCHIEF commented 7 years ago

If I wrote unit tests for each of the projects in the examples, would that help answer this question?

komplexb commented 7 years ago

@LongLiveCHIEF that would be neat, thanks. @dthree also suggested I review the tests on Cash, but i haven't checked it out yet.

johnthepink commented 7 years ago

@komplexb I unit tested launch, but I do not claim they are elegant :)

MatteoGabriele commented 7 years ago

I'm dealing with the same problem: no idea where to start.

It's impossible to test using something like child_process.execSync: the output result is full of extra characters and you can't do a comparisons with that.

The problem also comes when you combine inquirer prompts in your cli. Any nice documentation for all this?

thanks! :)

komplexb commented 7 years ago

Someone suggested I take a look @ https://github.com/dthree/cash/tree/master/test

I haven’t tried it yet, but I hope that helps.


From: Matteo Gabriele notifications@github.com Sent: 22 March 2017 05:50:36 To: dthree/vorpal Cc: Byron; Mention Subject: Re: [dthree/vorpal] how do i unit test a vorpal app? (#186)

I'm dealing with the same problem: no idea where to start.

It's impossible to test using something likechild_process.execSync: the output result is full of extra characters and you can't do a comparisons with that.

The problem also comes when you combine inquirer prompts in your cli. Any nice documentation for all this?

thanks! :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/dthree/vorpal/issues/186#issuecomment-288362467, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADsf_T74rhqpHvEDYCZvphCcBXWptIm6ks5roPz8gaJpZM4KgTlI.

MatteoGabriele commented 7 years ago

@komplexb thanks man! I was looking at it, but i can't spot an example using prompt. Have you tried?

PoignardAzur commented 7 years ago

Pinging this.

It would be really useful to be able to set up simple "send strings in, check what gets out" tests with Vorpal.

laurent22 commented 7 years ago

Actually it's not too complicated to setup a Vorpal app in such a way that it accepts a command, prints the result, and exits. From there it's only a matter of creating a shell script that executes commands and checks the results.

I've done something like this here (the app check if a command was provided as arguments and, if so, execute it and exit):

https://github.com/laurent22/joplin/blob/master/CliClient/app/app.js#L343

Then I've got this shell script to run the tests (the execCommand function is what's calling Vorpal and returning stdout):

https://github.com/laurent22/joplin/blob/master/CliClient/app/cli-integration-tests.js

I think most vorpal apps can be tweaked in that way to allow running commands without starting the prompt

lansehuiyi6 commented 5 years ago

@komplexb Have you find out how to test the vorpal app yet? I mean the vorpal with prompt.

laurent22 commented 1 year ago

This project has been dead for more than 5 years. Better use an alternative such as terminal-kit