@onerepo/plugin-vitest
Installation
Section titled InstallationVitest supports Workspaces with a little extra configuration than you may by used to. Create two files at the root of your repository: vitest.config.ts
and vitest.workspace.ts
:
-
Create a root config
This is the generic configuration for tests across all workspaces. Anything configurations here will be defaults for each Workspace.
-
Create a Workspace config
In the
vitest.workspace.ts
file, we need to duplicate the workspace globs from our originalpackage.json
orpnpm-workspace.yaml
file and ensure they point to valid Vitest config files: -
Create each Workspace configs
In each Workspace that has tests, create a new Vitest config file, ensuring to use
defineProject
(notdefineConfig
):
Configuration
Section titled Configurationvitest()
Section titled vitest()Include the vitest
plugin in your oneRepo plugin setup:
Parameters
Section titled ParametersParameter | Type |
---|---|
opts | Options |
Options
Section titled OptionsOptions for configuring the Vitest plugin for oneRepo.
Type declaration
Section titled Type declarationconfig?
Section titled config?Specify the main Jest configuration file, if different from <repo>/vitest.config.js
. This can be relative to the repository root.
name?
Section titled name?- Default:
'vitest'
Rename the default command name. This configuration is recommended, but not provided, to avoid potential conflicts with other commands.
Recommended tasks
Section titled Recommended tasksCommands
Section titled Commandsone vitest
Section titled one vitestAliases: one test
Run unit tests using Vitest
This test commad will automatically attempt to run only the test files related to the changes in your git branch. By passing specific filepaths as extra passthrough arguments after two dashes (--
), you can further restrict the tests to those specific files only.
Additionally, any other Vitest CLI options can be used as passthrough arguments as well after an argument separator (two dashes --
).
Option | Type | Description |
---|---|---|
--affected | boolean | Select all affected Workspaces. If no other inputs are chosen, this will default to true . |
--all, -a | boolean | Run across all Workspaces |
--inspect | boolean | Break for the the Node inspector to debug tests. |
--staged | boolean | Use files on the git stage to calculate affected files or Workspaces. When unset or --no-staged , changes will be calculated from the entire branch, since its fork point. |
--watch | boolean | Shortcut for vitest --watch mode. |
--workspaces, -w | array | List of Workspace names to run against |
Advanced options
Option | Type | Description |
---|---|---|
--config | string , default: "./vitest.config.ts" | Path to the vitest.config file, relative to the repo root. |
--from-ref | string | Git ref to start looking for affected files or Workspaces |
--show-advanced | boolean | Pair with --help to show advanced options. |
--through-ref | string | Git ref to start looking for affected files or Workspaces |
Run only tests related to modified files.
Run vitest in —watch mode.
Run vitest in watch mode with a particular file.
Run all tests in a given Workspace.
How can I stop Vitest from clearing the output when running in
We’ve filed an issue with Vitest, vitest-dev/vitest#5185 in hopes of being able to prevent the screen from clearing automatically from within the oneRepo plugin. However, until that is accepted, you can work around the issue by updating your root Vitest config:pre-commit
tasks?