Jest: Running CLI command with "-U" results in a message containing `Did you mean "$0"`

Created on 4 Oct 2019  ·  11Comments  ·  Source: facebook/jest

🐛 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.
good first issue

All 11 comments

PR with a fix appreciated!

Hey! Can I take this up?

@rbrishabh go for it!

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

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

I would like to work on this issue.

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.

```./node_modules/jest/bin/jest.js -l
● Unrecognized CLI Parameter:

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

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

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.

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

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 :)

Was this page helpful?
0 / 5 - 0 ratings