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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

BenLorantfy opened this issue May 27, 2018 · 6 comments


Copy link

馃殌 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:


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.


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(),


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


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.

Copy link

I'm also willing to submit a PR for this if the proposal is accepted.

Copy link

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

Copy link

NickCis commented Feb 4, 2019

Just for the one who come across this and needs to use custom arguments for their tests. I wrote an article on how to bypass the check and allow this functionality: "Jest: Passing custom arguments"

Copy link

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.

Copy link

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.
None yet
None yet

No branches or pull requests

5 participants