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

jest --silent --no-silent no longer negates silent flag #9517

Closed
jensbodal opened this issue Feb 5, 2020 · 5 comments · Fixed by #9519
Closed

jest --silent --no-silent no longer negates silent flag #9517

jensbodal opened this issue Feb 5, 2020 · 5 comments · Fixed by #9519

Comments

@jensbodal
Copy link

💥 Regression Report

Our package.json script runs jest with the --silent flag. Previously I was able to override this by passing --no-silent flag when running the script.

npm run test -- --no-silent

Last working version

Worked up to version: ~24.8.0 (specifically 24.8.0 is installed)

Stopped working in version: ~25.1.0

To Reproduce

  1. Create package.json script:
"test:silent": "jest --silent --config jest.config.js",
"test:no-silent": "jest --no-silent --config jest.config.js",
"test:negate:silent": "npm run test:silent -- --no-silent",
  1. Add a console.log statement to a test
  2. Run npm run test:silent and observe log statement isn't logged (expected)
  3. Run npm run test:no:silent and observe log statement is logged (expected)
  4. Run npm run test:silent -- --no-silent and observe log statement isn't logged (regression, this used to work)

Expected behavior

Expect no-silent to negate --silent flag.

Link to repl or repo (highly encouraged)

https://repl.it/repls/DownrightTrivialCalculator

Switch to version 24 to see it work. Basically run the test:negate:silent script and it will work with version 24 but not with version 25.

Issues without a reproduction link are likely to stall.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
  Binaries:
    Node: 8.17.0 - ~/local/n/n/versions/node/8.17.0/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.13.4 - ~/local/n/n/versions/node/8.17.0/bin/npm
  npmPackages:
    jest: ~25.1.0 => 25.1.0
@SimenB
Copy link
Member

SimenB commented Feb 5, 2020

We use yargs for CLI args parsing. Jest 24.8 used v12 and Jest 24.9 used v13. For Jest 25 we upgraded to v15. Quick testing shows this changed in yargs 14.

Test file:

const { argv } = require('yargs').option('silent', { type: 'boolean' });

console.log(argv);

yargs@<=13

$ node file.js --silent --no-silent --silent
{ _: [], silent: true, '$0': 'file.js' }

yargs@>13

$ node file.js --silent --no-silent --silent
{ _: [], silent: [ true, false, true ], '$0': 'file.js' }

This feels like a bug... We tell yargs we want a boolean, and it gives us back an array of booleans? @bcoe thoughts?

We just do if (config.silent) and an array is truthy. We do little runtime checks of what comes out of yargs, running jest --silent --no-silent --show-config will show that silent is an array in the config

@bcoe
Copy link
Contributor

bcoe commented Feb 5, 2020

@SimenB you should be able to address this by passing a configuration setting to yargs, we've made this behavior more explicit, see:

https://github.com/yargs/yargs-parser#duplicate-arguments-array

Set duplicate-arguments-array to false:

yargs.parserOptions({'duplicate-arguments-array': false});

Edit: yargs(process.argv.slice(2)).parserConfiguration({}), I should learn how to use yargs.

@SimenB
Copy link
Member

SimenB commented Feb 5, 2020

Thanks! Through some trial and error I got to yargs(process.argv.slice(2)).parserConfiguration({}) 😀

@SimenB
Copy link
Member

SimenB commented Mar 1, 2020

@jensbodal this was fixed in yargs, so you should be able to just update the version of yargs in your project

@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.

3 participants