Skip to content

Commit 26cc282

Browse files
committed
docs: upgrades for Vitest doc
1 parent e4bea15 commit 26cc282

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

docs/repo-docs/guides/tools/vitest.mdx

+25-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import { Tab, Tabs } from '#/components/tabs';
1010

1111
[Vitest](https://vitest.dev/) is a test runner from the Vite ecosystem. Integrating it with Turborepo will lead to enormous speed-ups.
1212

13-
<CreateTurboCallout />
13+
<Callout>
14+
For information on how to set up Vitest in a monorepo, refer to [Vitest's
15+
Workspace guide](https://vitest.dev/guide/workspace). This guide will teach
16+
how to use Vitest with concepts from Turborepo.
17+
</Callout>
1418

1519
## Setting up
1620

@@ -29,12 +33,15 @@ Let's say we have a monorepo that looks like this:
2933
</Folder>
3034
</Files>
3135

32-
Both `apps/web` and `packages/ui` have their own test suite. Their `package.json` files include a `test` script that runs Vitest:
36+
Both `apps/web` and `packages/ui` have their own test suites, with `vitest` [installed into the packages that use them](/repo/docs/crafting-your-repository/managing-dependencies#install-dependencies-where-theyre-used). Their `package.json` files include a `test` script that runs Vitest:
3337

3438
```json title="./apps/web/package.json"
3539
{
40+
"devDependencies": {
41+
"vitest": "latest"
42+
},
3643
"scripts": {
37-
"test": "vitest"
44+
"test": "vitest run"
3845
}
3946
}
4047
```
@@ -44,7 +51,9 @@ Inside the root `turbo.json`, create a `test` task:
4451
```json title="./turbo.json"
4552
{
4653
"tasks": {
47-
"test": {}
54+
"test": {
55+
"dependsOn": ["^test"]
56+
}
4857
}
4958
}
5059
```
@@ -53,16 +62,24 @@ Now, `turbo test` can parallelize and cache all of the test suites from each pac
5362

5463
## Running tests in watch mode
5564

56-
When you run your test suite normally, it completes and outputs to `stdout`. This means you can [cache it](/repo/docs/crafting-your-repository/caching) with Turborepo.
65+
When you run your test suite in CI, it logs to `stdout` and eventually exits upon completion. This means you can [cache it](/repo/docs/crafting-your-repository/caching) with Turborepo.
5766

5867
But when you run your tests in a watched mode, the process never exits. This makes a watch task more like a [development task](/repo/docs/crafting-your-repository/developing-applications).
5968

60-
Because of this difference, we recommend specifying **two separate Turborepo tasks**: one for running your tests, and one for running them in watch mode. Inside your each `package.json` file for each workspace:
69+
Because of this difference, we recommend specifying **two separate Turborepo tasks**: one for running your tests, and one for running them in watch mode.
70+
71+
<Callout>
72+
This strategy below creates two tasks, one for local development and one for
73+
CI. You could choose to make the `test` task for local development and create
74+
a `test:ci` task instead.
75+
</Callout>
76+
77+
For example, inside your each `package.json` file for each workspace:
6178

6279
```json title="./apps/web/package.json"
6380
{
6481
"scripts": {
65-
"test": "vitest",
82+
"test": "vitest run",
6683
"test:watch": "vitest --watch"
6784
}
6885
}
@@ -82,7 +99,7 @@ Inside the root `turbo.json`:
8299
}
83100
```
84101

85-
You can now either run this task using [global `turbo`](/repo/docs/getting-started/installation#global-installation) as `turbo test:watch` or from a script in your root `package.json`:
102+
You can now either run your tasks using [global `turbo`](/repo/docs/getting-started/installation#global-installation) as `turbo test:watch` or from a script in your root `package.json`:
86103

87104
<Tabs items={["Global turbo", "./package.json"]}>
88105
<Tab value="Global turbo">

0 commit comments

Comments
 (0)