jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.18k stars 6.45k forks source link

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

Open MichaelBorde opened 1 year ago

MichaelBorde commented 1 year ago

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
diegohaz commented 1 year ago

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 ```
SimenB commented 1 year ago

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 commented 1 year ago

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.

webark commented 1 year ago
● 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.

MichaelBorde commented 1 year ago

I can confirm this works for preset option.

Angeart commented 1 year ago

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
jlowcs commented 1 year ago

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
dmeents commented 1 year ago

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
asos-dominicjomaa commented 1 year ago

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
drackp2m commented 1 year ago

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,
};
AlexSapoznikov commented 1 year ago

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

alopix commented 1 year ago

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

kristojorg commented 1 year ago

same issue with projects collectCoverage and coverageDirectory

webark commented 1 year ago

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.

asos-dominicjomaa commented 1 year ago

@webark any luck debugging this issue?

mauris commented 1 year ago

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.

wimbarelds commented 1 year ago

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.

arnoudius commented 1 year ago

I'm also getting these warnings after upgarding to 29.3.1

sampath3112 commented 1 year ago

● 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 ["/src//!(.spec|.jest).{js,jsx,vue,ts,tsx}", "!//*.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 :)

maxailloud commented 1 year ago

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

joshkel commented 1 year ago

If I understand this issue correctly:

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?

wimbarelds commented 1 year ago

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.

aldex32 commented 1 year ago

Getting same warnings with jest@29.3.1

SimenB commented 1 year ago

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?

aukevanleeuwen commented 1 year ago

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)

webark commented 1 year ago

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

webark commented 1 year ago
collectCoverageFrom
coverageDirectory
coverageProvider
coverageReporters
maxConcurrency
name
projects
reporters
testTimeout
verbose
watchPlugins

these were the ones I found in this issue.

SimenB commented 1 year ago

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 commented 1 year ago

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.

eps1lon commented 1 year ago

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.

daniel-ac-martin commented 1 year ago

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.

FWIW, this is the scenario that I have.

It seems a bit annoying to split the package jest.config.js files into two, but perhaps that is the Right (TM) thing to do?

HustleCoding commented 1 year ago

Hi there,

I'm currently encountering a warning message in Jest that I'm having trouble resolving. The message reads:

Validation Warning:

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

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

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!

jimmyko commented 1 year ago

I got the same issue on jest@29.4.3

mkotsollaris commented 1 year ago

Same issue with the latest (29.4.3); do you know if there is any fix for this to suppress this warning? Both these yield the same false warning:

collectCoverage: true,
verbose: true,
kristojorg commented 1 year ago

What I don't understand here is why the projects config when listed in my top-level jest.config.ts is giving an error:

import type { Config } from "jest";

/**
 * This Jest config tells Jest about our workspaces (Jest calls them
 * projects). Each workspace will have it's own Jest config which
 * extends the one in packages/jest-presets.
 *
 */
const jestconfig: Config = {
  projects: ["./apps/*", "./packages/*"]
};

export default jestconfig;
ChrisABryant commented 1 year ago

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.

Paxosman commented 1 year ago

Import new nodeSent from my iPhoneOn Feb 28, 2023, at 3:44 AM, Kristo Jorgenson @.***> wrote: What I don't understand here is why the projects config when listed in my top-level jest.config.ts is giving an error: import type { Config } from "jest";

/**

export default jestconfig;

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

chromey commented 1 year ago

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.

Same for reporters actually. We have config for jest-junit in there that also specifies a project-specific outputDirectory.

As you state, the functionality is obviously supported and works fine, the warning should be removed.

codeedog commented 1 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.

● Validation Warning:

  Unknown option "coverageDirectory" with value "../../coverage/apps/wrap-state" 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 "collectCoverageFrom" with value ["./src/lib/**"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

  Configuration Documentation:
  https://jestjs.io/docs/configuration
wSedlacek commented 1 year ago

I started using this patch for coverageDirectory so that our Nx monorepo would stop throwing warnings. If using coverageDirectory at a project level is truly not intended can we get some sort of migration path?

diff --git a/build/ValidConfig.js b/build/ValidConfig.js
index 889ea1e5e802fdf9e3d83a2213bdee91fbd724f7..08157a5cfefb5637c3b961d5ad6b1b7c05ed2a87 100644
--- a/build/ValidConfig.js
+++ b/build/ValidConfig.js
@@ -226,6 +226,7 @@ const initialProjectOptions = {
   cache: true,
   cacheDirectory: '/tmp/user/jest',
   clearMocks: false,
+  coverageDirectory: 'coverage',
   coveragePathIgnorePatterns: [NODE_MODULES_REGEXP],
   dependencyExtractor: '<rootDir>/dependencyExtractor.js',
   detectLeaks: false,
stefaneckhardtcgi commented 1 year ago

Thanks for the hint, @wSedlacek , adapting your fix I added a few more lines to the initialProjectOptions (reporters, coverageDirectory and coverageReporters) and put the fixed file into a project folder. Just add more "default" options for whatever your test setup makes Jest shout out warnings. Then I installed copyFiles with:

npm install copyfiles --save-dev

for OS independent copying of the fix and added a postinstall task:

"postinstall": "copyfiles -f node_modules_jest_fix/ValidConfig.js node_modules/jest-config/build/"

and the issue is settled for now. Will keep monitoring if they finally fixed the issue whenever I do nx migrate.

oishiimendesu commented 1 year ago

same here, version: "jest": "^29.5.0", image

jadutter commented 1 year ago

I'm experiencing the same issue with coverageDirectory and reporters in a mono repo managed by nx , while trying to use the jest-stare plugin. ./packages/constants/jest.config.ts

export default {
    coverageDirectory: '../../docs/reports/packages/constants',
    reporters: [
        'default',
        [
            'jest-stare',
            {
                coverageLink: './coverage.html',
                resultDir: 'docs/reports/packages/constants',
                resultHtml: 'test-report.html',
                reportTitle: 'Constants Report',
                reportHeadline: 'Constants Report',
                reportSummary: 'Tests report for the constants package'
            }
        ]
    ],
    displayName: 'constants'
}

I threw in a console.trace just before the warning to get some context

Trace: JEST-VALIDATE
    at Object.get [as validate] (PATH_TO_MY_REPO/node_modules/@jest/core/node_modules/jest-validate/build/index.js:39:13)
    at normalize (PATH_TO_MY_REPO/node_modules/@jest/core/node_modules/jest-config/build/normalize.js:553:55)
    at readConfig (PATH_TO_MY_REPO/node_modules/@jest/core/node_modules/jest-config/build/index.js:181:74)
    at async Promise.all (index 0)
    at async readConfigs (PATH_TO_MY_REPO/node_modules/@jest/core/node_modules/jest-config/build/index.js:463:27)
    at async runCLI (PATH_TO_MY_REPO/node_modules/@jest/core/build/cli/index.js:152:59)

From 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 my PATH_TO_MY_REPO/packages/constants/project.json and PATH_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 to jest-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.

theoephraim commented 1 year ago

This may not be exactly the same error but I think it's related so posting here...

I just installed jest (with ts-jest) and following the instructions both from the jest docs and ts-jest docs and doing nothing fancy, I'm getting warnings.

My config:

import type { JestConfigWithTsJest } from 'ts-jest'

const config: JestConfigWithTsJest = {
  preset: 'ts-jest',
  verbose: true,
};

export default config;

The error:

image

It seems to me like a mismatch about expectations about the file export - meaning it's seeing an object named "default" when it's expecting the object at the root. Confirmed this by writing export const preset = 'ts-jest'; - but this would break the typechecking and is not desirable...

Getting everything playing nicely with modules and export syntax in all cases can be a real pain... so I'd suggest altering whatever is doing this check to just handle the case where it receives a root object named default and call it a day.

sebastianhaberey commented 1 year ago

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

wardds commented 1 year ago

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.

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.

arivera-xealth commented 1 year ago

@SimenB any updates on this?

cumt-robin commented 1 year ago

jest@29.5.0, is there any solution?

cvandradg commented 1 year ago

image

same issue here, any updates?

computnik commented 1 year ago

any updates on this?