configureVitest
plugin hook
#7104
Replies: 5 comments 10 replies
-
How does this work with |
Beta Was this translation helpful? Give feedback.
-
It sounds to me like |
Beta Was this translation helpful? Give feedback.
-
This is a nit, and there might be context I'm missing, but I find it slightly weird that |
Beta Was this translation helpful? Give feedback.
-
What is special about browser commands, that they warrant a specific |
Beta Was this translation helpful? Give feedback.
-
My recommendation would be to stay away from resolvable strings as configs, and require explicit configurations instead. To me, one of Vite's core strengths (and Storybook's weakness) is the fact that you have to import plugins, you can't just reference them with a string like We have so many issues with the string-based approach in Storybook - what if the dependency is hoisted in a monorepo? what about Yarn PnP? What is the relative path relative to? etc. If this is indeed just a shortcut and doesn't provide any extra value over just Another argument, is that it would be hard/impossible to merge configs using the resolvable string. I can imagine the Storybook plugin would use |
Beta Was this translation helpful? Give feedback.
-
The teams wants to propose a Vitest-specific plugin hook called
configureVitest
(similar toconfigureServer
). The hook will be called after the workspace projects are created and filtered and before the reporter resolution.This hook is mostly useful to library authors or in very advanced use cases where you need to access the public Node.js API.
Vitest already provides reporter API that covers the test runner lifecycle hooks and some additional hooks like
onWatcherStart
oronPathsCollected
, we will not change that and keep adding new hooks to reporters if the need arises.However while you can already use Vite plugins to inject some config values in the
config
hook, it is not possible to manipulate the root Vitest config from the workspace projects:With
configureVitest
hook you can directly modify the resolved global Vitest config. It is still recommended to use theconfig
plugin hook to inject project-level options likesetupFiles
ormaxConcurrency
.This plugin hook will not be called for server created to serve browser assets in the browser mode. The hook will be called in parallel for all plugins in a single project. Project plugins will be called sequentially:
Note that it's possible to have the same config in separate workspace projects, so it's recommended to validate the config first before injecting or changing values.
Beta Was this translation helpful? Give feedback.
All reactions