jest icon indicating copy to clipboard operation
jest copied to clipboard

[Bug]: Validation warnings for options like preset or coverage directory

Open MichaelBorde opened this issue 2 years ago • 105 comments

Version

29.3.0

Steps to reproduce

Use a jest.config.ts like:

export default {
  preset: './jest.preset.js',
  coverageDirectory: './coverage',
};

Expected behavior

Run tests using ./node_modules/.bin/jest without any warnings.

Actual behavior

● Validation Warning:

  Unknown option "preset" with value "./jest.preset.js" was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "coverageDirectory" with value "./coverage" was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

Additional context

Might be related to the missing default option for preset or coverage in packages/jest-config/src/ValidConfig.ts.

Environment

System:
    OS: macOS 13.0
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 16.18.0 - ~/.volta/tools/image/node/16.18.0/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 8.19.2 - ~/.volta/tools/image/node/16.18.0/bin/npm
  npmPackages:
    jest: ^29.3.0 => 29.3.0

MichaelBorde avatar Nov 08 '22 14:11 MichaelBorde

Also seeing those warnings with several options:

● Validation Warning:

  Unknown option "testTimeout" with value 5000 was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "reporters" with value ["default", "github-actions"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["packages/ariakit/src/**/*.{js,ts,tsx}", "packages/ariakit-utils/src/**/*.{js,ts,tsx}", "!**/__examples__/**", "!**/*test.{js,ts,tsx}", "!**/test-*.{js,ts}"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "testTimeout" with value 5000 was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "reporters" with value ["default", "github-actions"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["packages/ariakit/src/**/*.{js,ts,tsx}", "packages/ariakit-utils/src/**/*.{js,ts,tsx}", "!**/__examples__/**", "!**/*test.{js,ts,tsx}", "!**/test-*.{js,ts}"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "testTimeout" with value 5000 was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "reporters" with value ["default", "github-actions"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["packages/ariakit/src/**/*.{js,ts,tsx}", "packages/ariakit-utils/src/**/*.{js,ts,tsx}", "!**/__examples__/**", "!**/*test.{js,ts,tsx}", "!**/test-*.{js,ts}"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "testTimeout" with value 5000 was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "reporters" with value ["default", "github-actions"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["packages/ariakit/src/**/*.{js,ts,tsx}", "packages/ariakit-utils/src/**/*.{js,ts,tsx}", "!**/__examples__/**", "!**/*test.{js,ts,tsx}", "!**/test-*.{js,ts}"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "testTimeout" with value 5000 was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "reporters" with value ["default", "github-actions"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["packages/ariakit/src/**/*.{js,ts,tsx}", "packages/ariakit-utils/src/**/*.{js,ts,tsx}", "!**/__examples__/**", "!**/*test.{js,ts,tsx}", "!**/test-*.{js,ts}"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "testTimeout" with value 5000 was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "reporters" with value ["default", "github-actions"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["packages/ariakit/src/**/*.{js,ts,tsx}", "packages/ariakit-utils/src/**/*.{js,ts,tsx}", "!**/__examples__/**", "!**/*test.{js,ts,tsx}", "!**/test-*.{js,ts}"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "testTimeout" with value 5000 was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "reporters" with value ["default", "github-actions"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["packages/ariakit/src/**/*.{js,ts,tsx}", "packages/ariakit-utils/src/**/*.{js,ts,tsx}", "!**/__examples__/**", "!**/*test.{js,ts,tsx}", "!**/test-*.{js,ts}"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "testTimeout" with value 5000 was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "reporters" with value ["default", "github-actions"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["packages/ariakit/src/**/*.{js,ts,tsx}", "packages/ariakit-utils/src/**/*.{js,ts,tsx}", "!**/__examples__/**", "!**/*test.{js,ts,tsx}", "!**/test-*.{js,ts}"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

diegohaz avatar Nov 08 '22 16:11 diegohaz

Sorry about that! I'm fixing preset in #13583 as that's obviously a bug. However, e.g. testTimeout only works as global config, not as part of projects.

https://github.com/facebook/jest/blob/dfc87111e708b9294dc54ab0c17712972d042c1c/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L61-L63 https://github.com/facebook/jest/blob/dfc87111e708b9294dc54ab0c17712972d042c1c/packages/jest-jasmine2/src/index.ts#L43

It probably should be project config, but it's not. same with coverageDirectory and collectCoverageFrom at least. Not sure about reporters - that is probably correct as global.


TBH global vs project config is confusing even to me after 5 years of contributing and maintaining Jest 😅

SimenB avatar Nov 08 '22 22:11 SimenB

Preset fixed in https://github.com/facebook/jest/releases/tag/v29.3.1.

It's midnight here now, so I'll need to revisit tomorrow and verify what's the correct behaviour for the other fields. Even if it makes sense that a certain option is a project config and not global, we need to look at what the behaviour is first - that can only change in the next major. But if more fields are wrongly warned about, we should fix that.

SimenB avatar Nov 08 '22 22:11 SimenB

● Validation Warning:

  Unknown option "coverageProvider" with value "v8" was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["**/*.{ts,tsx}", "!**/*.d.ts", "!{index,routes}.ts"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

I'm still getting some warnings like this post jest-config 29.3. Forcing it to <29.3 removes the validation messages.

webark avatar Nov 09 '22 00:11 webark

I can confirm this works for preset option.

MichaelBorde avatar Nov 09 '22 07:11 MichaelBorde

I'm getting same error on >29.3

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["<rootDir>/components/**/*.vue", "<rootDir>/pages/**/*.vue"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

Angeart avatar Nov 11 '22 12:11 Angeart

I'm seeing these on my end:

● Validation Warning:

  Unknown option "coverageReporters" with value ["lcovonly", "html", "json-summary", "json", "text"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "watchPlugins" with value ["jest-watch-master"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "projects" with value ["."] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

jlowcs avatar Nov 15 '22 13:11 jlowcs

I am also seeing this with slightly different options:

● Validation Warning:

  Unknown option "reporters" with value ["default", "jest-junit"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "collectCoverageFrom" with value ["<rootDir>/src/**/*.{ts,tsx}"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "coverageDirectory" with value "<rootDir>/coverage/" was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

dmeents avatar Nov 16 '22 00:11 dmeents

Also seeing similar to the above for supposedly valid options:

● Validation Warning:

  Unknown option "verbose" with value true was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "reporters" with value ["default", "jest-teamcity-reporter"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "projects" with value ["<rootDir>/src/jest.*.config.js"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "name" with value "jsdom" was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

asos-dominicjomaa avatar Nov 16 '22 11:11 asos-dominicjomaa

Same mistakes here with jest 29.3.1 and ts-jest 29.0.3:

● Validation Warning:

  Unknown option "coverageDirectory" with value "../../coverage/apps/api" was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

● Validation Warning:

  Unknown option "coverageReporters" with value ["html", ["text-summary"]] was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

Problems are solved downgrading to jest 28.1.3 and ts-jest 28.0.8.

My configuration is:

export default {
  displayName: 'api',
  preset: '../../jest.preset.js',
  testEnvironment: 'node',
  maxWorkers: 2,
  transform: {
    '^.+\\.[tj]s$': [
      'ts-jest',
      {
        tsconfig: '<rootDir>/tsconfig.spec.json',
        diagnostics: {
          ignoreCodes: ['TS151001'],
        },
      },
    ],
  },
  moduleFileExtensions: ['ts', 'js'],
  coverageDirectory: '../../coverage/apps/api',
  coverageReporters: ['html', ['text-summary', { skipFull: true }]],
  clearMocks: true,
};

drackp2m avatar Nov 16 '22 19:11 drackp2m

Having same issues. Would like to ask what's the state with it?

AlexSapoznikov avatar Nov 22 '22 07:11 AlexSapoznikov

Seeing the same issue with: coverageReporters, coverageProvider, verbose and watchPlugins.

alopix avatar Nov 24 '22 08:11 alopix

same issue with projects collectCoverage and coverageDirectory

kristojorg avatar Nov 24 '22 10:11 kristojorg

I feel like it's something to do with this https://github.com/facebook/jest/blob/6e5b1d60a1214e792b5229993b5475445e9c1a6e/packages/jest-config/src/index.ts#L56 I'll have to stick a debugger on there when i get to a computer next.

webark avatar Nov 24 '22 17:11 webark

@webark any luck debugging this issue?

asos-dominicjomaa avatar Nov 28 '22 12:11 asos-dominicjomaa

I can confirm that this is an issue since 29.0.0 (not sure about the prereleases). Reverting back to the last version of v28 and the warning went away.

mauris avatar Nov 30 '22 09:11 mauris

getting the coverageDirectory and maxConcurrency warnings with 29.3.1

I do have this is a jest.config.js located inside of a project folder; and so according to @SimenB 's comment, that is incorrect.

However though I am getting this warning, coverage is being placed in the configured directory.

wimbarelds avatar Dec 05 '22 12:12 wimbarelds

I'm also getting these warnings after upgarding to 29.3.1

arnoudius avatar Dec 05 '22 13:12 arnoudius

● Validation Warning:

Unknown option "collectCoverage" with value true was found. This is probably a typing mistake. Fixing it will remove this message.

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

Validation Warning:

Unknown option "collectCoverageFrom" with value ["<rootDir>/src//!(.spec|.jest).{js,jsx,vue,ts,tsx}", "!<rootDir>//*.d.ts"] was found. This is probably a typing mistake. Fixing it will remove this message.

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

Seeing the same issue even after upgrading jest to 29.3.1 and @types/jest to ^29.2.4 @SimenB Can you please Take a look at this issue :)

sampath3112 avatar Dec 06 '22 19:12 sampath3112

Hello. I do have the same issue with the coverageDirectory and coverageReporters options. I am using the 29.3.1 version.

maxailloud avatar Dec 06 '22 21:12 maxailloud

If I understand this issue correctly:

  • The warnings indicate that per-project Jest configs (i.e., files referenced by a Jest config projects entry) are using configuration settings like coverageDirectory, coverageReporters, and collectCoverageFrom that can only apply at the global level.
  • This feature (warning about per-project settings that have no effect because they can only apply at the global level) was added in #13565.
  • The "correct" fix is to adjust your Jest configs - any project config file (i.e., anything that's referenced by another Jest config's projects) shouldn't have these settings.

Am I understanding correctly?

In my opinion, it's sometimes useful to be able to use global settings in project configs - maybe you want to reuse a single configuration object for both, or maybe you want each package in a monorepo to have a jest.config.ts so that Jest can be run at the monorepo level or per project and share the same configs. (NX, for example, defaults to putting global settings in per-project configs, for whatever reason.) Maybe Jest shouldn't warn on this, or should only warn if --debug or --showConfig is given, or should wait until Jest 30 and make a concrete recommendation about stricter separation of global and project settings then?

joshkel avatar Dec 15 '22 19:12 joshkel

The only addition I would tack on to what you're saying is that: Despite the warning, the project setting does work correctly and actually does place coverage reports in the (per project) specified directory.

wimbarelds avatar Dec 19 '22 10:12 wimbarelds

Getting same warnings with [email protected]

aldex32 avatar Dec 30 '22 11:12 aldex32

Am I understanding correctly?

That's correct.

The only addition I would tack on to what you're saying is that: Despite the warning, the project setting does work correctly and actually does place coverage reports in the (per project) specified directory.

If it still works, that means the error is wrong (like it was for preset before 29.3.1). Could you list out which actually works so we can make sure to not warn for those cases?

SimenB avatar Jan 02 '23 13:01 SimenB

I cannot give an exhaustive list of things that are giving warnings (but are still working), but at the very least coverageDirectory:

● Validation Warning:

  Unknown option "coverageDirectory" with value "../../coverage/integrations/xxxx-adapter" was found.
  This is probably a typing mistake. Fixing it will remove this message.

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

If that one is fixed / excluded from giving warnings I would be happy already. (Edit: jest 29.3.1 btw)

aukevanleeuwen avatar Jan 02 '23 15:01 aukevanleeuwen

There's been several comments listing out options that are throwing warning after the upgrade in the issue.

webark avatar Jan 02 '23 17:01 webark

collectCoverageFrom
coverageDirectory
coverageProvider
coverageReporters
maxConcurrency
name
projects
reporters
testTimeout
verbose
watchPlugins

these were the ones I found in this issue.

webark avatar Jan 02 '23 20:01 webark

Thanks for the list! coverageReporters , maxConcurrency, reporters (probably verbose as well as AFAIK it's only used in reporters) and watchPlugins at least are global config so the warning is correct for those. The others seem reasonable to me, will fix. But as mentioned in https://github.com/facebook/jest/issues/13576#issuecomment-1307946313 most really are global config and have no effect when specified as project config.

SimenB avatar Jan 03 '23 09:01 SimenB

See https://github.com/facebook/jest/blob/4fd1cb3926f93974a1f10d995ed73368784bc6b9/packages/jest-config/src/index.ts#L77-L201

The coverage stuff should probably move... We might need a major version to clean this up.


However, looking at OP, they get the error in a single config - that's a bug.

SimenB avatar Jan 03 '23 09:01 SimenB

Would it make sense to document project vs global config and then adjust the warning? API documentation currently does not specify which configs are global, project or both.

eps1lon avatar Jan 29 '23 10:01 eps1lon