jest-runner-eslint icon indicating copy to clipboard operation
jest-runner-eslint copied to clipboard

Allow passing cliOptions through normal jest config?

Open tunnckoCore opened this issue 5 years ago • 8 comments

Would you consider this or not? Currently, we require to have jest-runner-eslint config file (or field) which... isn't that good if you want to provide "zero config" experience, or near zero.

So here we'll have config.cliOptions || explorer.searchSync(config.rootDir);

Worth nothing.

I'll PR if you agree.

tunnckoCore avatar Jun 16 '19 21:06 tunnckoCore

See #58, #31, #10, but also https://github.com/facebook/jest/issues/4278#issuecomment-326676409

ljharb avatar Jun 16 '19 21:06 ljharb

Hey, thanks! :) Uh, that's both very sad and surprising... I've just seen that runners accept { testPath, config } and thought it's the "normal jest config".

Any suggestion where this can be started? I'm not familiar with the jest codebase.

tunnckoCore avatar Jun 17 '19 00:06 tunnckoCore

Actually, there is a way. Hacky one of course. But for now, we can use it until it land official. And of course, we will see the validation warnings but they don't break the execution anyway.

config.haste[runner-name] (e.g. config.haste.jest-runner-eslint) because that's the only thing that doesn't fail. For some reason config[runner-name] doesn't work.

Why in config.haste? Glad you asked. You can actually put whatever name you want in your jest config file (module.exports = { foobar: 123 }), but it won't appear in the jest runner (e.g. { config }, the config.foobar won't exist), but haste appears, always.

tunnckoCore avatar Jun 17 '19 00:06 tunnckoCore

This is the smallest and only needed change which adds such support.

https://github.com/tunnckoCoreHQ/devest/commit/508688f2b8157bbc74b3415930b2a97bfeeb1db0

Want PR?

tunnckoCore avatar Jun 17 '19 05:06 tunnckoCore

I don't think adding a bunch of validation warnings, or relying on a hack, is worth it.

ljharb avatar Jun 17 '19 05:06 ljharb

It's optional anyway and allows you to build on top of Jest, and when you know what are you doing. It worths when you know what are you doing and why.

Also, it's not "a bunch", it's one warning. And all this is some temporary solution.

tunnckoCore avatar Jun 17 '19 05:06 tunnckoCore

How is one supposed to pass cliOptions with this thing without getting these validation warnings?

// jest-runner-eslint.config.js
module.exports = {
  runner: 'jest-runner-eslint',
  displayName: 'lint',
  cliOptions: {
    fix: true
  }
};
$ jest -c jest-runner-eslint.config.js
● Validation Warning:

  Unknown option "cliOptions" with value {"fix": true} was found.
  This is probably a typing mistake. Fixing it will remove this message.

  Configuration Documentation:
  https://jestjs.io/docs/configuration

Is there some another way?

raine avatar Sep 05 '23 06:09 raine

EDIT: I think I got it to work -- configuration done in package.json helped and also installing fresh node_modules

hey @raine :wave: did u ever figure out how cliOptions is injected into the jest configuration?

I might be misunderstanding the README -- and havent had much luck with cliOptions either

nsunga avatar Oct 24 '23 21:10 nsunga