-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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.5Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.