jest --silent --no-silent no longer negates silent flag

Created on 5 Feb 2020  路  4Comments  路  Source: facebook/jest

馃挜 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
Regression Upstream Bug

Most helpful comment

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

All 4 comments

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

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

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

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

Was this page helpful?
0 / 5 - 0 ratings