-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Make CLI more reusable #2578
Comments
@sgen I'm aware of tj/commander.js#404 ironically i ran into it with the But you raise a valid point, the other option is yargs. Which is fairly similar and the maintainers are more active but not as fast in some cases due to their use of |
It probably won't be toooo hard for me to swap one out for the other. |
I've never used yargs so I cannot comment. I fully support migrating the some of the mocha cli logic to the main library. Ideally all tool functionality should be included in the library, with the cli tool being a simple wrapper to decode cli input. But Im not a Mocha dev so you should wait for them to weigh in. |
I should also mention that I am a Mocha user and may need similar functionality in the near future. This gets a huge +1 from me. |
Thanks for the proposal! And sorry for the delay in reviewing. I'm one of the juniors around here, so I'll defer to the judgement of the team, but my inclination is to say that we really want the CLI to be doing less so there's little to no need to make it reusable/programmatic like this (and hopefully so it's simpler to implement or reimplement if need be). For instance:
My hunch is that if we made Mocha better useable through the programmatic interface, then not only would there be less to code in the CLI, but there'd be little to no need to reuse the CLI code -- all it would be doing is making the same functionality that's available in the programmatic interface callable from the commandline. But maybe I'm not understanding the use-case properly, so a few questions for clarification:
|
hi @ScottFreeCode thank you for the in depth reply. It would be correct that the main reason to have a reusable CLI would be because the To dig into specifics we load variations of mocha specs using a custom bdd interface. That basically scans a load of yaml files with parameters for test cases. (Essentially we built parameterized test cases ontop of mocha.) and then depending on additional CLI flags we added it will run the mocha specs with those specified test case parameters. So there's a fair bit of magic at the moment. I used the term So I take it the first step would be to make the mocha interface capable of handling more of the CLI behaviour, considering I have already dug into the code this is something I would be willing to do. |
So I've revisited this, an important use case if you were to have a reusable CLI would be being able to use it as a subcommand. In detail thats becasue it always calls the base This is looking like its not a good idea with the current limitations in Commander, not to say the functionality wouldn't be wanted. So to conclude what I would like to do:
|
I updated the PR to not expose the cli, and tore out anything that looks like technical debt, also added the changes we discussed. |
Hey, in my use case, while using mocha to test the cli app, mocha options are being given precedence over the arguments supplied by the command line leading to name collisions and lost data. program
.option('-d, --data <path>', 'Data')
.parse(args) where args is either Is there a way to give precedence to the actual options in case both the actual ones and the ones supplied through mocha are present. Thanks. |
closed by #3556 |
Hi
In our use case mocha is basically the underlying engine for a behavioural framework we wrote that tests a bunch of async systems we use in-house.
We did a lot, but for brevity we write the behaviours in mocha specs, and use it to assert the systems output during a test case run. This allows us to test that the system is behaving the way that it should since it's basically a giant async state machine constantly spewing out state change notifications.
In our test case we want our framework to work as much as is possible with other mocha tools.
The problem is that using the
Runner
class you basically lose all of the third party tool support unless you want to reimplement the entire mocha cli on your own.I have used
Commander
extensively in many other projects, so I have figured out how to make the CLI more reusable.More details are in the PR (#2553)
I am willing to make any changes requested myself. And the functionality of the cli has not changed, so if you choose not to expose a CLI component for reuse then this can be looked at as just a code cleanup.
I know I shouldn't have made these changes without speaking to you first, but as the PR says I didn't even know if it would be possible or work, so I dug into it face first and by the time I proved it could be done, I had it working.
FYI I am using my PR in said testing framework and its working well.
The text was updated successfully, but these errors were encountered: