jest: [Bug]: Validation warnings for options like preset or coverage directory
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
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 153
- Comments: 89 (9 by maintainers)
Commits related to this issue
- Bumped Jest. But see https://github.com/jestjs/jest/issues/13576. — committed to Divine-Software/WSF by LeviticusMB a year ago
- test: fix validation warning Jest threw a validation warning for `coverageDirectory` being an invalid option. This has been [reported as a bug](https://github.com/jestjs/jest/issues/13576). Added thi... — committed to sebgroup/Spark-packages by believer a year ago
In Version 29.5.0, I get the warnings listed below under my nx repo. It’d be great if there were a configuration switch to turn off warnings that are unnecessary and for which the code performs the correct operation.
jest.preset.js…
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.
We managed to fix most of these warning by consolidating settings in jest.preset.js in the base of our monorepo.
However, we want to specify the coverage directory for each project in that monorepo to be under the coverage directory of the root of the monorepo while maintaining separate reports for each project. This simplifies scanning and production of summary reports.
Thus, we need to specify a unique coverageDirectory in the jest.config.ts file of each project. This works fine, it is just annoying that we get a Validation Warning for each project. Since this is the only want to get a consolidated directory containing all the coverage reports, this setting needs to be supported in each jest.config.ts without generating a validation warning.
If I understand this issue correctly:
projects
entry) are using configuration settings likecoverageDirectory
,coverageReporters
, andcollectCoverageFrom
that can only apply at the global level.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?@SimenB any updates on this?
I’m getting same error on
>29.3
It works if you downgrade to 28.1.3…enjoy
Hello. I do have the same issue with the
coverageDirectory
andcoverageReporters
options. I am using the29.3.1
version.I upgraded to
jest@29.6.2
but I still see warnings for “collectCoverage” and “coverageReporters”:I’m seeing these on my end:
I started using this patch for
coverageDirectory
so that our Nx monorepo would stop throwing warnings. If usingcoverageDirectory
at a project level is truly not intended can we get some sort of migration path?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 ofprojects
.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
andcollectCoverageFrom
at least. Not sure aboutreporters
- that is probably correct as global.TBH global vs project config is confusing even to me after 5 years of contributing and maintaining Jest 😅
Also seeing similar to the above for supposedly valid options:
jest@29.5.0, is there any solution?
Hi there,
I’m currently encountering a warning message in Jest that I’m having trouble resolving. The message reads:
I have checked my Jest configuration file and confirmed that the “coverageDirectory” option is spelled correctly and is a valid Jest configuration option. I’m running the latest version of Jest, and I don’t believe I’m using any third-party libraries or presets that could be causing this issue.
I’m hoping someone in the community can help me figure out what’s causing this warning message and how I can resolve it. Any advice or suggestions would be greatly appreciated.
Thank you!
I’m still getting some warnings like this post
jest-config
29.3
. Forcing it to<29.3
removes the validation messages.nope, still happening
Another +1 to this, same setup here. So far
coverageDirectory
is the only configuration option causing this warning for us. Would like to see continued support for this property on a project level.Seeing the same issue with:
coverageReporters
,coverageProvider
,verbose
andwatchPlugins
.I’m experiencing the same issue with
coverageDirectory
andreporters
in a mono repo managed by nx , while trying to use the jest-stare plugin../packages/constants/jest.config.ts
I threw in a
console.trace
just before the warning to get some contextFrom what I can tell, when I’m running
nx run test
to execute jest tests, it starts the jest cli and passes it the config options from myPATH_TO_MY_REPO/packages/constants/project.json
andPATH_TO_MY_REPO/packages/constants/jest.config.ts
. The jest cli then passes it through jest-config, where it defines an example config to validate against, using jest-validate. It chooses the example for a project, which is missing those config options.jest-validate
has a README.md, and accepts a json object to configure it’s behavior.jest-config
does not appear to have a README.md, and does not seem to have an ability to pass on options tojest-validate
.In my opinion, initialOptions and initialProjectOptions should not differ. It adds unnecessary/undocumented complexity when trying to determine why a config option isn’t working.
It also hamstrings plugins from being able to use their own config if jest is going to say their options are invalid.
Same mistakes here with jest 29.3.1 and ts-jest 29.0.3:
Problems are solved downgrading to jest 28.1.3 and ts-jest 28.0.8.
My configuration is:
I updated to “ts-jest”: “~29.1.1”, “jest”: “~29.7.0” and this still occurs
● Validation Warning:
Unknown option “coverageReporters” with value [“lcov”, “text-summary”] 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 “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 “maxConcurrency” with value 4 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 “passWithNoTests” 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”, [“C:\workspace\rfq-ui-migration\rfq-ui-migration\node_modules\jest-html-reporter\dist\index.js”, {“includeFailureMsg”: true , “includeSuiteFailure”: true, “outputPath”: “reports/tests.html”, “pageTitle”: “Test Report”, “sort”: “default”, “theme”: “defaultTheme”}]] was found. This is probably a typing mistake. Fixing it will remove this message.
Configuration Documentation: https://jestjs.io/docs/configuration
Still getting this warning for the
reporters
option even after upgrading to version29.6.1
. Upgrading did fix it forcoverageDirectory
though.Same for
reporters
actually. We have config for jest-junit in there that also specifies a project-specificoutputDirectory
.As you state, the functionality is obviously supported and works fine, the warning should be removed.
Getting same warnings with
jest@29.3.1
Having same issues. Would like to ask what’s the state with it?
Not sure if this has already been mentioned, but this patch-package patch works for us…
patches/jest-validate+29.7.0.patch
:I definitely don’t think this should be closed without some kind of resolution or direction.
This is exactly our situation.
Also, when generating components using standard Nx commands, the
coverageDirectory
setting in each project is the default behavior. So even if we removed all the coverageDirectory settings in all the existing Nx projects, every new project would introduce the warning again.same issue with
projects
collectCoverage
andcoverageDirectory
This validation warning happens for me when I utilize a base Jest config in a monorepo project and utilize that base config in sub-package config files;
all jest.config.ts files are importing and extending the jest.config.base.ts file
many validation warnings
base config is
I ran into this same issue today. Very weird. Using 28.1.3 does seem to address the problem, but, I’d really prefer to be using 29.x.x. What’s happening on this issue?
I wonder if we should take the opportunity to go all in on generating a json schema and just use ajv or something (like eslint does) to validate?
Ref https://github.com/jestjs/jest/issues/11963
I haven’t done anything more since landing the basics: https://github.com/jestjs/jest/blob/main/packages/jest-schemas/src/index.ts
Okay, so SOME options appear to be fixed, the one I was using
coverageDirectory
is fixed.Hi I am also seeing the similar issue while try to run : npx jest --coverage RelativePath
I have following versions installed:
Can someone please help me here?
Still throwing errors, but the config itself works fine
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.Some problem here. Also using NX
v18.1.1
and jestv29.7.0
.I am also using jest on a monorepo with turborepo and deployed in Vercel. With the
verbose: true
setting I get the same warning, but it seems to work. Well… work but in a strange way. Because the logs are marked in red even if the test passes XD. I’m using the version 29.7.0 of Jest I understand that this problem may be related to this warning. Do you know more about the solution in Jest version 29?Coverage configuration warnings were removed for me 🎉. All of my remaining warnings are for watchPlugins
I had
Unknown option "default" with value ...
issue with my ESM ("type": "module"
) project.This issue occurs due to the way
jest
checks if imported object is ES moduleTo fix t you have two options:
esModuleInterop
option - do it.I got the same issue on jest@29.4.3
for the jest 29.7
It seems like the documentation contains wrong information about configuration Is it possible to fix it in 2024? How many years should be enough to fix it?
Same for collectCoverage while using
● 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
I get those warnings with
29.6.2
Thanks for the list!
coverageReporters
,maxConcurrency
,reporters
(probablyverbose
as well as AFAIK it’s only used in reporters) andwatchPlugins
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.Also seeing those warnings with several options:
'● Validation Warning ' Unknown option "reporters" with value ["default", ["<rootDir>/node_modules/jest-junit/index.js", {"classNameTemplate": "{classname}: {title}", "suiteName": "Unit tests (Jest)", "suiteNameTemplate": [Function suiteNameTemplate], "titleTemplate": "{classname}: {title}"}]] was found.' ' This is probably a typing mistake. Fixing it will remove this message. ' Configuration Documentation: 'https://jestjs.io/docs/configuration'
For the Jest 29.7.0
The error appears only when I run tests from the test explorer (vscode), when I run “npm t” there’s no error.
Funny how our monorepo projects get
Unknown option "verbose" with value true
followed by a helpful link to documentation where the examples consistently use option “verbose” with value true 😄Finally found what the difference was between the project that was failing and the one that was succeeding. Apparently the failing project ran jest via ts-node instead of directly (because of a custom SDK we built on top of Nx, while testing the SDK itself). Maybe it helps someone 😃
I’m facing the same issue. Is there any documentation about what is valid in project vs global config? I see that
@jest/types
exposes aProjectConfig
andGlobalConfig
type but thejest
package does not. OnlyInitialOptions
from theConfig
namespace is exposed on thejest
package. If i try and require the types fromjest
I get an error pushing me to usejest
instead.To further complicate this, the docs state
But in my testing I discovered:
GlobalConfig
reporters
,testTimeout
,coverageReporters
moduleFileExtensions
,modulePathIgnorePatterns
,snapshotFormat
,testPathIgnorePatterns
I am discovering these by trial and error. It would be great to get some documentation about how root/project configs are merged and address the typing issues.
It is just right time to fix this. @SimenB is landing breaking changes and preparing Jest 30 release.
any updates on this?
same here, version: “jest”: “^29.5.0”,
What I don’t understand here is why the
projects
config when listed in my top-leveljest.config.ts
is giving an error: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.