feat: add "configureVitest" plugin hook#7349
Merged
sheremet-va merged 10 commits intovitest-dev:mainfrom Mar 19, 2025
Merged
Conversation
✅ Deploy Preview for vitest-dev ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
hi-ogawa
reviewed
Mar 18, 2025
Contributor
hi-ogawa
left a comment
There was a problem hiding this comment.
The code looks good, but I'm not familiar with use case. For example, the purpose of force flag doesn't look obvious to me.
If this serves storybook's need, I'm good to proceed with this.
AriPerkkio
reviewed
Mar 18, 2025
Member
AriPerkkio
left a comment
There was a problem hiding this comment.
Looks good, great work! Once tests have been added this should be ready to go as is.
I tested this with two real-world use cases that developers building on top of Vitest have asked before:
Check if coverage is enabled via
coverage.enabledor--coverage(or resolved by both)import { defineConfig } from "vitest/config"; import type { Vite, VitestPluginContext } from "vitest/node"; export default defineConfig({ plugins: [ { name: "vitest:is-coverage-enabled", configureVitest(context: VitestPluginContext) { console.log({ coverage: context.vitest.config.coverage.enabled }); }, } satisfies Vite.Plugin, ], });Configure
coverage.excludesfrom workspace project's pluginsimport { defineConfig } from "vitest/config"; import type { VitestPluginContext } from "vitest/node"; export default defineConfig({ test: { workspace: [ { test: { name: "Headless unit tests", include: ["test/*.test.ts"], }, }, { test: { name: "Stories", include: ["src/**.stories.*ts*"], }, plugins: [ { name: "vitest:configure-coverage-for-storybook", configureVitest(context: VitestPluginContext) { // At this point we can assume `config.coverage` is resolved and defined to non-nullable if (context.project.config.coverage.enabled) { // No need to check if `coverage.exclude` is array, just push. // No need to care about default values like "**/node_modules/**", push doesnt overwrite anything context.project.config.coverage.exclude.push("**/*.stories.*"); } }, }, ], }, ], }, });
…nch 'main' of github.com:vitest-dev/vitest into feat/hook-plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
See discussion: #7104
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.