Open MichaelBorde opened 1 year ago
jest.preset.js...
const nxPreset = require("@nx/jest/preset").default;
const globalConf = {
collectCoverage: true,
coverageDirectory: `${process.env.NX_WORKSPACE_ROOT}/coverage/${process.env["NX_TASK_TARGET_PROJECT"]}`,
};
module.exports = { ...nxPreset, ...globalConf };
Still throwing errors, but the config itself works fine
● 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 "coverageDirectory" with value "../../.cache/coverage/apps/hooks" 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 ["src/*/.{js,ts,jsx,tsx}", "!/index.(js|ts|jsx|tsx)", "!/types.(js|ts|jsx|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 "coverageReporters" with value ["html", "json"] was found. This is probably a typing mistake. Fixing it will remove this message. Configuration Documentation: https://jestjs.io/docs/configuration
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 module
if (obj.__esModule) return obj:
else return { default: obj }
To fix t you have two options:
esModuleInterop
option - do it.export const __esModule = true;
export default cfg;
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?
Seems to be fixed in 29.6.1 🎉
Appears it might have been #14054
Seems to be fixed in 29.6.1 🎉
nope, still happening
Okay, so SOME options appear to be fixed, the one I was using coverageDirectory
is fixed.
Coverage configuration warnings were removed for me 🎉. All of my remaining warnings are for watchPlugins
Still getting this warning for the reporters
option even after upgrading to version 29.6.1
. Upgrading did fix it for coverageDirectory
though.
That's correct, only a PR was made for 2 of the affected options ... See https://github.com/jestjs/jest/pull/14180
I upgraded to jest@29.6.2
but I still see warnings for "collectCoverage" and "coverageReporters":
● 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 "coverageReporters" with value ["text", "cobertura", "lcov"] 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
● Validation Warning:
Unknown option "collectCoverage" with value false 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"] 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"] 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 "silent" 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 "testSequencer" with value "./jest.sequencer.js" was found.
This is probably a typing mistake. Fixing it will remove this message.
Configuration Documentation:
https://jestjs.io/docs/configuration```
My VS Code extension doesn't work for the same reason and I can't run tests through the UI of VS Code:
@kvart714 , that's rather a bug in the VS Code extension not being able to go around the warning.
Yes I understand it. This extension hasn't been supported for 2 years now. But unfortunately it is the best one for VS Code for me. The most popular extension has many other problems. Anyway these warnings are wrong and I just wrote one more related case
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
I definitely don't think this should be closed without some kind of resolution or direction.
It is just right time to fix this. @SimenB is landing breaking changes and preparing Jest 30 release.
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
Just to be clear - reporters
is a valid field in global config and project-specific configs, right? For that option (at least), the issue here is the spurious validation warnings, not that the functionality itself is (or should/will be) unsupported?
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 a ProjectConfig
and GlobalConfig
type but the jest
package does not. Only InitialOptions
from the Config
namespace is exposed on the jest
package. If i try and require the types from jest
I get an error pushing me to use jest
instead.
To further complicate this, the docs state
With the projects option enabled, Jest will copy the root-level configuration options to each individual child configuration during the test run, resolving its values in the child's context. This means that string tokens like
will point to the child's root directory even if they are defined in the root-level configuration.
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.
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 moduleif (obj.__esModule) return obj: else return { default: obj }
So I have been looking at the same issue for the whole day now. I have a similar project that uses the exact same versions and configuration as the one that's failing that DOES work normally and it's really frustrating. For some reason, my jest.config.ts file is not interpreted as TypeScript then I guess. What could cause this?
Any workaround ? Check documentation, apply example -> warning...
I had
Unknown option "default" with value ...
issue with my ESM ("type": "module"
) project. This issue occurs due to the wayjest
checks if imported object is ES moduleif (obj.__esModule) return obj: else return { default: obj }
So I have been looking at the same issue for the whole day now. I have a similar project that uses the exact same versions and configuration as the one that's failing that DOES work normally and it's really frustrating. For some reason, my jest.config.ts file is not interpreted as TypeScript then I guess. What could cause this?
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 :)
It works if you downgrade to 28.1.3...enjoy
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?
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;
root/
-- packages/
---- package1/
------ jest.config.ts
---- package2/
------ jest.config.ts
jest.config.base.ts
jest.config.ts
package.json
all jest.config.ts files are importing and extending the jest.config.base.ts file
import jestBaseConfig from "./jest.config.base";
const jestConfig: JestConfigWithTsJest = {
...jestBaseConfig,
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
...
}
many validation warnings
● Validation Warning:
Unknown option "forceExit" 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 "silent" with value false was found.
This is probably a typing mistake. Fixing it will remove this message.
Configuration Documentation:
https://jestjs.io/docs/configuration
base config is
import type { JestConfigWithTsJest } from "ts-jest";
const jestBaseConfig: JestConfigWithTsJest = {
preset: "ts-jest",
testEnvironment: "node",
detectOpenHandles: true,
forceExit: true,
silent: false,
verbose: true,
testPathIgnorePatterns: ["node_modules", "dist", "env"],
moduleDirectories: ["node_modules"],
extensionsToTreatAsEsm: [".ts"],
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
//the content you'd placed at "global"
useESM: true,
},
],
},
};
export default jestBaseConfig;
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?
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
Yeah, I have this same issue with collectCoverage
, following.
Having this problem for reporters
when using typescript its valid but the runner gives me the same issue.
I'm getting the same error but for watchPlugins
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
Not sure if this has already been mentioned, but this patch-package patch works for us...
patches/jest-validate+29.7.0.patch
:
diff --git a/node_modules/jest-validate/build/warnings.js b/node_modules/jest-validate/build/warnings.js
index 1860d5a..aef7d81 100644
--- a/node_modules/jest-validate/build/warnings.js
+++ b/node_modules/jest-validate/build/warnings.js
@@ -23,6 +23,13 @@ function _interopRequireDefault(obj) {
*/
const unknownOptionWarning = (config, exampleConfig, option, options, path) => {
+ // HACK: do not warn about coverageReporters and reporters.
+ // they are actually valid options, but are being reported as invalid.
+ // https://github.com/jestjs/jest/issues/14701
+ if (option === "coverageReporters" || option === "reporters") {
+ return;
+ }
const didYouMean = (0, _utils.createDidYouMeanMessage)(
option,
Object.keys(exampleConfig)
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 :D
● 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
Some problem here. Also using NX v18.1.1
and jest v29.7.0
.
Validation Warning:
Unknown option "coverageReporters" with value ["cobertura", "html", "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 "reporters" with value XXXXXX 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"] was found.
This is probably a typing mistake. Fixing it will remove this message.
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?
'● 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.
I want to correct the idea that reporters
should be a global-only field. This absolutely doesn't make sense, at least in terms of the options passed. For example, it seems obvious that we should be able to configure different output directories for each project:
{
reporters: ['default', ['jest-junit', { outputDirectory: '/path/to/projectA/junit' }]]
}
I also want to add that, the problem here is less about superfluous warnings, and more that some of these settings I've tried simply do not work at all. For example, the current version of Jest (29.7.0), allows you to have coverageDirectory
defined, without throwing an error. However, it does not respect this field at all. You can add whatever coverage directory you want, but it'll always output to coverage
.
Similarly, you can shut the reporters
error up by adding reporters config to jest-config/build/ValidConfig.js
-> initialProjectOptions
, but this doesn't mean the reporters
field is respected on a per-project basis. In fact, it's completely ignored.
I'll have to dig in and see how this might be implemented. If there's appetite for this and the maintainers would like to point me in the right direction, I'd appreciate it.
+1
您的邮件我已收到! 我会在第一时间内回复您!非常感谢!
Same warning(Jest v29.7.0)
Is there any further updates?
Facing the same warning in jest 29.7.0
I'm having a validation warning on "testTimeout" with Jest 29.7.0
@SimenB Since Jest 29, about two years ago, many warnings about "unknown options" have been generated for no apparent reason. At some point someone made a PR that only fixed 1 or 2 of them but the others are still there (for example "reporters", that has been biting us for the last year).
These options still work on project level and they also make terribly good sense at project level! Why are these warnings generated? What was the idea behind it? And why is this not fixed when it was reported? It's a clear regression from v28, where it all worked as well, but there are no irrelevant warnings. In relation to your comment here: https://github.com/jestjs/jest/pull/13565#issuecomment-1307957629, I imagine fixing it never happened?
Within our company it would really help to get rid of them to build up a bit of trust in Jest (over Karma, where we come from).
@woppa684 I think the priority here is low, because Jest is showing warning but the options you set on project level are still working.
Within our company it would really help to get rid of them to build up a bit of trust in Jest (over Karma, where we come from).
From our experience Karma is worse. We have an Angular application and Karma is executing tests successfully even there are properties missing on an object (maybe just configuration? idk) - Jest fails which is good because you are sure the code is executed correctly and you have to fix your test cases correctly.
Long story short: there's (afaik) no bug.
I also stumbled upon this problem and it seems like this issue should concentrate on updating the documentation & typings, since (as far as I inspected) the actual implementation at the moment works as it should.
This validation code in normalize.ts#L495 causes the warnings and stands in line with what @SimenB said in the first comments. Moreover, I tried and with jest 29.7.0
, placing any coverage
-related configuration props in a project config does not have any effect (apart from causing a validation warning, of course), while placing it in the global config works properly and does not cause any validation warnings.
I believe this issue should result in a change to the docs to point out that some properties (such as coverageReporters
, coveragePathIgnorePatterns
, etc.) are only allowed in global config and cannot be used in project config.
As one of the comments in this thread mentioned, jest
does not provide separate exports for ProjectConfig
and GlobalConfig
, but such an improvement would be great for developer experience, since just annotating a config with the proper specialized type would protect devs from using props that are not allowed in the given config type.
CC: @MichaelBorde @SimenB
So... after two years and 100 comments the answer is RTFM?
Version
29.3.0
Steps to reproduce
Use a
jest.config.ts
like:Expected behavior
Run tests using
./node_modules/.bin/jest
without any warnings.Actual behavior
Additional context
Might be related to the missing default option for preset or coverage in
packages/jest-config/src/ValidConfig.ts
.Environment