question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The tests fail because yargs detects the OS' locale

See original GitHub issue

I can do a PR for the issue if you want.

Expected Behavior

The tests should pass when cloning & installing the project.

Current Behavior

They do not. See:

  CLI tests
    ✕ Running without parameters should display help (94ms)
    ✕ Running without parameters should display a requirement for the p option (85ms)
    ✕ Linting a file that has wrong host should display an error message and use exit code 1 (76ms)
    ✓ Linting a file that has wrong host should return exit code 1 (74ms)

  ● CLI tests › Running without parameters should display help

    expect(received).not.toBe(expected) // Object.is equality

    Expected: not -1

      17 |       expect(output.indexOf('Usage:')).not.toBe(-1)
      18 |       expect(output.indexOf('Options:')).not.toBe(-1)
    > 19 |       expect(output.indexOf('Examples:')).not.toBe(-1)
         |                                               ^
      20 |       done()
      21 |     })
      22 |   })

      at Socket.toBe (__tests__/cli.test.js:19:47)

That’s because my locale is set to the french one, and yargs translates the CLI output (at least some of it) (See https://github.com/yargs/yargs/blob/master/docs/api.md#detectlocaleboolean Your tests rely on the fact that the user has an english locale.

See the output of the npx lockfile-lint -h command:

Usage: lockfile-lint --path <path-to-lockfile> --allowed-hosts yarn npm

Options:
  --version              Affiche le numéro de version                  [booléen]
  --help, -h             Affiche de l'aide                             [booléen]
  -p, --path             path to the lockfile     [chaine de caractère] [requis]
  -t, --type             lockfile type, options are "npm" or "yarn"
                                                           [chaine de caractère]
  -s, --validate-https   validates the use of HTTPS as protocol schema for all
                         resources                                     [booléen]
  -e, --empty-hostname   allows empty hostnames, or set to false if you wish for
                         a stricter policy              [booléen] [défaut: true]
  -a, --allowed-hosts    validates a whitelist of allowed hosts to be used for
                         resources in the lockfile                     [tableau]
  -o, --allowed-schemes  validates a whitelist of allowed schemes to be used for
                         resources in the lockfile                     [tableau]

Exemples:
  lockfile-lint --path yarn.lock --validate-https
  lockfile-lint --path yarn.lock --validate-https --allowed-hosts npm yarn
  verdaccio
  lockfile-lint --path yarn.lock --allowed-schemes "https:" "git+ssh:"
  --allowed-hosts npm yarn verdaccio

curated by Liran Tal at https://github.com/lirantal/lockfile-lint

Notice the Exemples string

Possible Solution

Adding

.detectLocale(false)

to the lockfile-lint/src.main.js file works.

Steps to Reproduce (for bugs)

Well, I don’t know how to set my locale to another, but I guess https://www.tecmint.com/set-system-locales-in-linux/ should help

  1. Clone the project
  2. Install the dependencies
  3. Launch the tests

Context

I was trying to improve the output of the expected protocol; I’ve tried to analyze one of my project’s lockfile and I was surprised at the output (I expected HTTPS, not https:, do you want to a PR for that?)

Your Environment

Ubuntu LTS, french locale

The output of the locale command.

LANG=fr_FR.UTF-8
LANGUAGE=
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=
  • Library Version used: master
  • Node.js version (e.g. Node.js 5.4): 10.16.3
  • Operating System and version (desktop or mobile): Ubuntu LTS

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
MathieuAAcommented, Dec 27, 2019

By the way, thanks for the article!

0reactions
lirantalcommented, Jan 24, 2020

@MathieuAA no rush on my side so when you get to it in the upcoming week that’s fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

yargs/api.md at main - GitHub
Yargs will then exit, unless .exitProcess() was used to prevent Yargs from exiting after a failed check. ... Should yargs attempt to detect...
Read more >
concurrently - node_modules - yargs - CHANGELOG.md
drop Node 4 from testing matrix, such that we'll gradually start drifting away from supporting Node 4. yargs-parser does not populate 'false' when...
Read more >
server/node_modules/yargs · patch-4 · codemasters / SE 339 Fleet ...
By default, yargs will auto-detect the operating system's locale so that yargs-generated help content will display in the user's language.
Read more >
How do I unit test that an application using yargs provides the ...
Testing fails when using non English locales because the expected results for the test are hard coded in that language. For example the ......
Read more >
CHANGELOG.md
... yargs error object ([#765](https://github.com/yargs/yargs/issues/765)) ... [#246](https://github.com/bcoe/yargs/pull/246) detect locale based only on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found