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.

New Feature: Forward unknown command line arguments to jest.config.js

See original GitHub issue

šŸš€ Feature Proposal

Forward unknown command line arguments to jest.config.js file. Right now, jest will respond with "unknown argumentā€™. The proposal is to instead allow these unrecognized arguments so they can be used in the jest.config.js file to modify the config.

Tor-051496:my-project ben$ yarn jest --unit
yarn run v1.5.1
$ /Users/ben/Projects/my-project/node_modules/.bin/jest --unit
ā— Unrecognized CLI Parameter:

  Unrecognized option "unit".

  CLI Options Documentation:
  https://facebook.github.io/jest/docs/en/cli.html

Motivation

Sometimes you want to slightly change the jest config based on some variable. For example, I might want to only run my unit tests or integration tests instead of all my tests. Or I might want to only test a certain project in a monorepo.

Example

Your cli command would look like this: jest --integration

And you config might look like this:

const argv = require('yargs').argv;
function getTestRegex() {
  if(argv.integration) {
    return `__tests__/integration/\.(ts|js)x?$`;
  }

  return 'test\.(ts|js)x?$';
}

module.exports = {
  "testRegex": getTestRegex(),
}

Alternatives

Alternatively, you could also somehow specify this is a custom flag. The advantage here is that you can keep the ā€œunknown flagā€ check. The disadvantage is that it becomes a little more verbose.

jest --known-jest-flag --custom-flags --integration or maybe jest --known-jest-flag -f --integration

Right now, you can also use environment variables, but theyā€™re more verbose. TEST_TYPE=integration jest

Pitch

This involves a direct change to the jest cli, and thereā€™s no way to do this outside the core as far as I know.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
thymikeecommented, May 27, 2018

Disabling unknown CLI commands was a conscious decision, to align Jest with a lot of UNIX tools, and weā€™re not going back. We believe this makes sense.

As you already mentioned, this is possible using env variables and I donā€™t see it being more verbose than a CLI flag. I canā€™t see any added value by this proposal, but even more config options to maintain.

Sorry to be a bearer of bad news, but Iā€™m going to close this. Thanks for taking the time to prepare a nice feature request, appreciated! Looking forward to more proposals or bug fixes šŸ˜ƒ

1reaction
thernstigcommented, Nov 16, 2019

Imagine you are using jest-puppeteer to run e2e tests. You might want to supply options like headless=false and slowmo=250, or even other start-up options for Puppeteer.

If a preset like jest-puppeteer could add itā€™s own commands directly to the Jest CLI, would that not be good? It makes sense to me at least, as long as they are namespaced and validated by the preset.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest: Passing custom arguments - Medium
In the post i'll show how to pass custom command line arguments to ... Feature: Forward unknown command line arguments to jest.config.js.
Read more >
Jest CLI Options
Jest CLI Options. The jest command line runner has a number of useful options. You can run jest --help to view all available...
Read more >
Migration Guide | Detox
If you were using Mocha, now you have two options: switch to Jest ... runnerConfig: 'e2e/jest.config.js', ... You'll be adding a new reporter...
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
run() begins at step 9 below. # Serial Mode. User (that's you) executes mocha; Loads options from config files, if present; Mocha processes...
Read more >
CLI Reference - Turborepo
Turborepo is a high-performance build system for JavaScript and TypeScript ... Command-Line Reference ... Options can be passed to turbo in different ways....
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