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

Running CLI command with "-U" results in a message containing Did you mean "$0" #9007

Closed
Tokimon opened this issue Oct 4, 2019 · 12 comments Β· Fixed by #10604
Closed

Running CLI command with "-U" results in a message containing Did you mean "$0" #9007

Tokimon opened this issue Oct 4, 2019 · 12 comments Β· Fixed by #10604

Comments

@Tokimon
Copy link

Tokimon commented Oct 4, 2019

πŸ› Bug Report

Got this message when running CLI command with a bad parameter:

● Unrecognized CLI Parameter:
  Unrecognized option "U". Did you mean "$0"?

I seems to me that the message ("$0") is wrong (looks like a misinterpreted regular expression replacement).

To Reproduce

Launch jest cli command with -U instead of -u

Expected behavior

I think the message is supposed to say:
Unrecognized option "U". Did you mean "u"?

Link to repl or repo (highly encouraged)

N/A

envinfo

full command and result

$ npm test -- -U

> <MyProject>@1.1.7 test <MyProjectPath>
> cross-env TZ=UTC NODE_ENV=test jest --ci "-U"

● Unrecognized CLI Parameter:

  Unrecognized option "U". Did you mean "$0"?

  CLI Options Documentation:
  https://jestjs.io/docs/en/cli.html

npm ERR! Test failed.  See above for more details.
@thymikee
Copy link
Collaborator

thymikee commented Oct 4, 2019

PR with a fix appreciated!

@rbrishabh
Copy link

Hey! Can I take this up?

@thymikee
Copy link
Collaborator

thymikee commented Oct 5, 2019

@rbrishabh go for it!

@tonythetiger323
Copy link

@rbrishabh did you have a chance to look into it? If not I wouldn't mind taking a look at it.

@rbrishabh
Copy link

Hey @tonythetiger323, yes I'm looking into this. Will create a PR soon.

@Hardik500
Copy link

I would like to work on this issue.

@clentfort
Copy link
Contributor

I tried to reproduce your described error but if i run NODE_ENV=test ./node_modules/.bin/jest --ci "-U" from latest master I get no such error. Instead jest just runs some of the tests.

@iPawan
Copy link

iPawan commented Jan 9, 2020

● Unrecognized CLI Parameter:

  Unrecognized option "l". Did you mean "$0"?

  CLI Options Documentation:
  https://jestjs.io/docs/en/cli.html```

@ghostd
Copy link
Contributor

ghostd commented Apr 16, 2020

I did a quick analyze. If i understand correctly, the $0 comes from the following array in validateCLIOptions:

const yargsSpecialOptions = ['$0', '_', 'help', 'h'];

When we pass the incorrect option (here l) and the set of potential options to createDidYouMeanMessage, the function returns Did you mean "$0"?

It seems right given the fact the incorrect option is only one letter, the leven library cannot make a better suggestion.

Maybe we should not suggest anything when the incorrect option has a length < 2 or something like that.

I can provide a PR when we'll decide the expected bahavior.

@jcs98
Copy link
Contributor

jcs98 commented Oct 6, 2020

@thymikee I would love to take this up as my first issue.
Can you please suggest the expected behavior?

@thymikee
Copy link
Collaborator

thymikee commented Oct 6, 2020

What @ghostd said. Plus, we could add a simple check if lowercasing a single letter would match with one of the valid options, but nothing more :)

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants