Skip to content

Failed to update coverage thresholds. Configuration file is too complex. #5803

@Ghislain89

Description

@Ghislain89

Describe the bug

In our monorepo we have a shared configuration file for Vitest:

const { default: tsconfigPaths } = require('vite-tsconfig-paths');
const { defineConfig } = require('vitest/config');

module.exports = defineConfig({
  plugins: [tsconfigPaths({ projects: ['./tsconfig.json'] })],
  test: {
    include: ["src/**/*.{test,spec}.{ts,tsx}"],
    globals: false,
    coverage: {
      include: ['src/**'],
      exclude: ['**/tests/**', '**/integration-tests/**', '**/test/**'],
      enabled: true,
      provider: 'v8',
      thresholds: {
        lines: 90,
        functions: 90,
        branches: 90,
        statements: 90,
        autoUpdate: false
      },
    },
  },
});

Each of our packages that use vitest import this shared configuration and uses mergeConfig to merge any package specific overrides with the shared defaults. As we have some packages that aren't quite yet there in terms of code coverage, we've have overwritten coverage thresholds to the values currently applicable for these packages. As our devs improve coverage, we want to update the package-specific thresholds to grow as coverage grows.

An example of a package-specific config can be found below.

import baseConfig from '@shared-config/vitest.config';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import { defineConfig,mergeConfig } from 'vitest/config';

export default mergeConfig(
  baseConfig,
  defineConfig({
    plugins: [vanillaExtractPlugin({ emitCssInSsr: true })],
    test: {
      globals: true,
      globalSetup: './vitest-globals.ts',
      setupFiles: ['vitest.setup.ts'],
      environment: 'happy-dom',
      coverage: {
        provider: 'v8',
        thresholds: {
          lines: 61.9,
          functions: 58.57,
          branches: 84.17,
          statements: 61.9,
          autoUpdate: true,
        },
      },
    },
  }),
);

We figured, based on the docs that setting autoUpdate to true would be enough. Unfortunately this results in an error when running the tests:

Error: Failed to update coverage thresholds. Configuration file is too complex.
 ❯ resolveConfig ../../../node_modules/.pnpm/vitest@1.6.0_@types+node@20.12.7_@vitest+ui@1.6.0/node_modules/vitest/dist/coverage.js:183:9
 ❯ V8CoverageProvider.updateThresholds ../../../node_modules/.pnpm/vitest@1.6.0_@types+node@20.12.7_@vitest+ui@1.6.0/node_modules/vitest/dist/coverage.js:15:20
 ❯ V8CoverageProvider.reportCoverage ../../../node_modules/.pnpm/@vitest+coverage-v8@1.6.0_vitest@1.6.0/node_modules/@vitest/coverage-v8/dist/provider.js:2348:14
 ❯ Vitest.reportCoverage ../../../node_modules/.pnpm/vitest@1.6.0_@types+node@20.12.7_@vitest+ui@1.6.0/node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:11456:7
 ❯ async file:/Users/ghislain/workspaces/kadena/kadena.js/node_modules/.pnpm/vitest@1.6.0_@types+node@20.12.7_@vitest+ui@1.6.0/node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:11219:7
 ❯ Vitest.runFiles ../../../node_modules/.pnpm/vitest@1.6.0_@types+node@20.12.7_@vitest+ui@1.6.0/node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:11225:12
 ❯ Vitest.start ../../../node_modules/.pnpm/vitest@1.6.0_@types+node@20.12.7_@vitest+ui@1.6.0/node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:11092:7
 ❯ startVitest ../../../node_modules/.pnpm/vitest@1.6.0_@types+node@20.12.7_@vitest+ui@1.6.0/node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:18345:7
 ❯ start ../../../node_modules/.pnpm/vitest@1.6.0_@types+node@20.12.7_@vitest+ui@1.6.0/node_modules/vitest/dist/vendor/cac.EdDItJD-.js:1415:17
 ❯ CAC.run ../../../node_modules/.pnpm/vitest@1.6.0_@types+node@20.12.7_@vitest+ui@1.6.0/node_modules/vitest/dist/vendor/cac.EdDItJD-.js:1395:3

We had expected/hoped that the autoUpdate: True would just update the coverage package specific coverage values instead of throwing an error.

Reproduction

A small reproduction can be found on Stackblitz

System Info

System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M2 Pro
    Memory: 2.82 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.1 - ~/.nvm/versions/node/v20.12.1/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.1/bin/npm
    pnpm: 8.15.8 - ~/.nvm/versions/node/v20.12.1/bin/pnpm
  Browsers:
    Chrome: 125.0.6422.113
    Safari: 17.5

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: coverageIssues and PRs related to the coverage featurep2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions