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

Exit if wrong args/flags are passed. #85

Open
garg3133 opened this issue Jan 24, 2023 · 6 comments
Open

Exit if wrong args/flags are passed. #85

garg3133 opened this issue Jan 24, 2023 · 6 comments
Labels
good first issue Good for newcomers

Comments

@garg3133
Copy link
Member

Currently, create-nightwatch passes through and starts the setup process even if some wrong arguments or flags are passed. Instead, we should error out on wrong args/flags and possibly give suggestions on the correct flags.

We currently have our own implementation for giving suggestions on the correct flag if a wrong flag is passed, but if the flag passed is just something random, instead of erroring out, it lets the process pass through. So, maybe we can try using the didyoumean package as used in Nightwatch.

@garg3133 garg3133 added the good first issue Good for newcomers label Dec 10, 2023
@samson-olawoyin
Copy link

samson-olawoyin commented Mar 4, 2024

After reviewing this issue, am suggesting adding the argv checks on argv-setup.js file located in nightwatch/lib/runner/cli/. the setup() on line 242 function holds all the passable arguments that are expected when running a test with nightwatch. the get argv() (line 13 of argv-setup.js) get all the passed arguments when running the test and setup() function (line 242 of argv-setup.js) holds all the definition and alias of the passable argument when running a test.

Therefore in other to determine if an arguments passed is valid or not, we can call the setup() function by setting the passed arguments to this.option of the ArgvSetup class constructor.

In conclusion, the argument passed check would be checked in the get argv() function (line 13) by adding a new conditional statement in checking if the argv values are valid nightwatch flags and then call the didyoumean library and passing all the valid args/flags keys as the list argument and then passing the first argument to be the flag.

Example:
const didYouMean = require('didyoumean');
const suggestion = didYouMean(flag, list);

I stand to be corrected where ever necessary and anticipating suggestion as well.

@garg3133 could you please help review this comment.

@garg3133
Copy link
Member Author

garg3133 commented Mar 6, 2024

Hi @olawoyinsamson, thanks for investigating this but this issue is for the create-nightwatch repository and not the main nightwatch repository.

This can be reproduced easily by running npm init nightwatch@latest -- --random-arg or npx create-nightwatch --random-arg, and the changes need to be done in src/index.ts file.

@samson-olawoyin
Copy link

@garg3133 thank you for your review and help, i will revert to the create-nightwatch repository and analyse this issue again and come back with a resolution.

@samson-olawoyin
Copy link

samson-olawoyin commented Mar 6, 2024

@garg3133 please I have only found the following flags when install nightwatch

  1. --mobile
    2.--generate-config

Please do we have any other flags apart from the ones above.

I will implement the issue resolution with checking argv against flags --mobile and --generate-config and when none defined flags is been detected, then I will use didyoumean library to communicate the available flags and then terminate the setup process.

I stand to be corrected.

@samson-olawoyin
Copy link

Hi @garg3133 i wanted to mention that i now have a resolution for issue #85 via repo [email protected]:olawoyinsamson/create-nightwatch.git , please help review and send feedback. Thank you.

@samson-olawoyin
Copy link

Hi @garg3133 here is a PR i have raised #101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants