Skip to content

Commit

Permalink
docs: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jun 6, 2022
1 parent 8029aa7 commit 24af3fe
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions docs/config/index.md
Expand Up @@ -76,7 +76,7 @@ Handling for dependencies inlining or externalizing
#### deps.external

- **Type:** `(string | RegExp)[]`
- **Default:** `['**\/node_modules\/**','**\/dist\/**']`
- **Default:** `['**/node_modules/**', '**/dist/**']`

Externalize means that Vite will bypass the package to native Node. Externalized dependencies will not be applied Vite's transformers and resolvers, so they do not support HMR on reload. Typically, packages under `node_modules` are externalized.

Expand Down Expand Up @@ -244,6 +244,8 @@ Custom reporters for output. Reporters can be [a Reporter instance](https://gith
Write test results to a file when the `--reporter=json` or `--reporter=junit` option is also specified.
By providing an object instead of a string you can define individual outputs when using multiple reporters.

To provide object via CLI command, use the following syntax: `--outputFile.json=./path --outputFile.junit=./other-path`.

### threads

- **Type:** `boolean`
Expand All @@ -254,7 +256,7 @@ Enable multi-threading using [tinypool](https://github.com/Aslemammad/tinypool)
:::warning
This option is different from Jest's `--runInBand`. Vitest uses workers not only for running tests in parallel, but also to provide isolation. By disabling this option, your tests will run sequentially, but in the same global context, so you must provide isolation yourself.

This might cause all sorts of issues, if you are relying on global state (frontend frameworks usually do) or your code relies on environment to be defined separately for each test (like, `@vue/test-utils`). But can be a speed boost for Node tests (up to 3 times faster), that don't necessarily rely on global state or can easily bypass that.
This might cause all sorts of issues, if you are relying on global state (frontend frameworks usually do) or your code relies on environment to be defined separately for each test. But can be a speed boost for your tests (up to 3 times faster), that don't necessarily rely on global state or can easily bypass that.
:::

### maxThreads
Expand Down Expand Up @@ -298,7 +300,7 @@ Silent console output from tests

Path to setup files. They will be run before each test file.

You can use `process.env.VITEST_WORKER_ID` (integer-like string) inside to distinguish between threads (will always be `1`, if run with `threads: false`).
You can use `process.env.VITEST_WORKER_ID` (integer-like string) inside to distinguish between threads (will always be `'1'`, if run with `threads: false`).

:::tip
Note, that if you are running [`--no-threads`](#threads), this file will be run in the same global scope. Meaning, that you are accessing the same global object before each test, so make sure you are not doing the same thing more than you need.
Expand All @@ -311,12 +313,14 @@ import { config } from '@some-testing-lib'
if (!globalThis.defined) {
config.plugins = [myCoolPlugin]
computeHeavyThing()
afterEach(() => {
cleanup()
})
globalThis.defined = true
}

// hooks are reseted before each suite
afterEach(() => {
cleanup()
})

globalThis.resetBeforeEachTest = true
```
:::
Expand All @@ -334,7 +338,7 @@ Multiple globalSetup files are possible. setup and teardown are executed sequent
:::

::: warning
Beware that the global setup is run in a different global scope if you are using [`--threads`](#threads) (default option). If you disabled `--threads`, everything is run in the same scope (including the Vite server and its plugins).
Beware that the global setup is run in a different global scope, so your tests don't have access to variables defined here.
:::


Expand All @@ -356,7 +360,7 @@ Useful if you are testing calling CLI commands, because Vite cannot construct a

```ts
test('execute a script', async () => {
// Vite cannot rerun this test, if content of `dist/index.js` changes
// Vitest cannot rerun this test, if content of `dist/index.js` changes
await execa('node', ['dist/index.js'])
})
```
Expand Down

0 comments on commit 24af3fe

Please sign in to comment.