From 2ece3a747974a9c89b16de644eea16f4eef6123b Mon Sep 17 00:00:00 2001 From: patak-dev Date: Tue, 21 Dec 2021 08:40:25 +0100 Subject: [PATCH] docs: config note in getting started guide --- docs/config/index.md | 2 +- docs/guide/index.md | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/config/index.md b/docs/config/index.md index 211537c52..8e7813764 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -2,7 +2,7 @@ ## Configuration -`vitest` will read your root `vite.config.ts` when it is present to match with the plugins and setup as your Vite app. If you want to it to have a different configuration for testing, you could either: +`vitest` will read your root `vite.config.ts` when it is present to match with the plugins and setup as your Vite app. If you want to have a different configuration for testing, you could either: - Create `vitest.config.ts`, which will have the higher priority - Pass `--config` option to CLI, e.g. `vitest --config ./path/to/vitest.config.ts` diff --git a/docs/guide/index.md b/docs/guide/index.md index 021d2a9f9..fe5d7e60c 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -22,6 +22,29 @@ $ npm install -D vitest Vitest requires Vite v2.7 and Node v14 ::: +## Configuring Vitest + +One of the main advantages of Vitest is its unified configuration with Vite. If present, `vitest` will read your root `vite.config.ts` to match with the plugins and setup as your Vite app. For example, your Vite [resolve.alias](https://vitejs.dev/config/#resolve-alias) and [plugins](https://vitejs.dev/guide/using-plugins.html) configuration will work out-of-the-box. If you want a different configuration during testing, you can: + +- Create `vitest.config.ts`, which will have the higher priority +- Pass `--config` option to CLI, e.g. `vitest --config ./path/to/vitest.config.ts` +- Use `process.env.VITEST` to conditionally apply different configuration in `vite.config.ts` + +To configure `vitest` itself, add `test` property in your Vite config + +```ts +// vite.config.ts +import { defineConfig } from 'vite' + +export default defineConfig({ + test: { + // ... + }, +}) +``` + +See the list of config options in the [Config Reference](../config/) + ## Command Line Interface In a project where Vitest is installed, you can use the `vitest` binary in your npm scripts, or run it directly with `npx vitest`. Here is the default npm scripts in a scaffolded Vite project: -- 2.51.2