Open garg3133 opened 1 year ago
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.
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.
@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.
@garg3133 please I have only found the following flags when install nightwatch
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.
Hi @garg3133 i wanted to mention that i now have a resolution for issue #85 via repo git@github.com:olawoyinsamson/create-nightwatch.git , please help review and send feedback. Thank you.
Hi @garg3133 here is a PR i have raised https://github.com/nightwatchjs/create-nightwatch/pull/101
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.