Skip to content

Commit 7012f8c

Browse files
authored
docs: add env documentation (#6063)
1 parent 95a2d87 commit 7012f8c

4 files changed

Lines changed: 52 additions & 30 deletions

File tree

docs/.vitepress/config.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -246,32 +246,39 @@ export default ({ mode }: { mode: string }) => {
246246
{
247247
text: 'Browser Mode',
248248
link: '/guide/browser/',
249-
collapsed: true,
250-
items: [{
251-
text: 'Assertion API',
252-
link: '/guide/browser/assertion-api',
253-
docFooterText: 'Assertion API | Browser Mode',
254-
}, {
255-
text: 'Retry-ability',
256-
link: '/guide/browser/retry-ability',
257-
docFooterText: 'Retry-ability | Browser Mode',
258-
}, {
259-
text: 'Context',
260-
link: '/guide/browser/context',
261-
docFooterText: 'Context | Browser Mode',
262-
}, {
263-
text: 'Interactivity API',
264-
link: '/guide/browser/interactivity-api',
265-
docFooterText: 'Interactivity API | Browser Mode',
266-
}, {
267-
text: 'Commands',
268-
link: '/guide/browser/commands',
269-
docFooterText: 'Commands | Browser Mode',
270-
}, {
271-
text: 'Examples',
272-
link: '/guide/browser/examples',
273-
docFooterText: 'Examples | Browser Mode',
274-
}],
249+
collapsed: false,
250+
items: [
251+
{
252+
text: 'Assertion API',
253+
link: '/guide/browser/assertion-api',
254+
docFooterText: 'Assertion API | Browser Mode',
255+
},
256+
{
257+
text: 'Retry-ability',
258+
link: '/guide/browser/retry-ability',
259+
docFooterText: 'Retry-ability | Browser Mode',
260+
},
261+
{
262+
text: 'Context',
263+
link: '/guide/browser/context',
264+
docFooterText: 'Context | Browser Mode',
265+
},
266+
{
267+
text: 'Interactivity API',
268+
link: '/guide/browser/interactivity-api',
269+
docFooterText: 'Interactivity API | Browser Mode',
270+
},
271+
{
272+
text: 'Commands',
273+
link: '/guide/browser/commands',
274+
docFooterText: 'Commands | Browser Mode',
275+
},
276+
{
277+
text: 'Examples',
278+
link: '/guide/browser/examples',
279+
docFooterText: 'Examples | Browser Mode',
280+
},
281+
],
275282
},
276283
{
277284
text: 'In-Source Testing',

docs/api/mock.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Accepts a function that will be used as an implementation of the mock.
5959
```ts twoslash
6060
import { vi } from 'vitest'
6161
// ---cut---
62-
const mockFn = vi.fn().mockImplementation(apples => apples + 1)
62+
const mockFn = vi.fn().mockImplementation((apples: number) => apples + 1)
6363
// or: vi.fn(apples => apples + 1);
6464

6565
const NelliesBucket = mockFn(0)

docs/guide/features.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn('hello', 1)
115115
expect(vi.isMockFunction(fn)).toBe(true)
116116
expect(fn.mock.calls[0]).toEqual(['hello', 1])
117117

118-
fn.mockImplementation(arg => arg)
118+
fn.mockImplementation((arg: string) => arg)
119119

120120
fn('world', 2)
121121

@@ -243,3 +243,18 @@ vitest --merge-reports --reporter=junit --coverage.reporter=text
243243
```
244244

245245
See [`Improving Performance | Sharding`](/guide/improving-performance#sharding) for more information.
246+
247+
## Environment Variables
248+
249+
Vitest exclusively autoloads environment variables prefixed with `VITE_` from `.env` files to maintain compatibility with frontend-related tests, adhering to [Vite's established convention](https://vitejs.dev/guide/env-and-mode.html#env-files). To load every environmental variable from `.env` files anyway, you can use `loadEnv` method imported from `vite`:
250+
251+
```ts twoslash
252+
import { loadEnv } from 'vite'
253+
import { defineConfig } from 'vitest/config'
254+
255+
export default defineConfig(({ mode }) => ({
256+
test: {
257+
// mode defines what ".env.{mode}" file to choose if exists
258+
env: loadEnv(mode, process.cwd(), ''),
259+
},
260+
}))

packages/vitest/src/node/cli/cli-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,11 @@ export const cliOptionsConfig: VitestCLIOptions = {
469469
'Should all test files run in parallel. Use `--no-file-parallelism` to disable (default: `true`)',
470470
},
471471
maxWorkers: {
472-
description: 'Maximum number of workers to run tests in',
472+
description: 'Maximum number or percentage of workers to run tests in',
473473
argument: '<workers>',
474474
},
475475
minWorkers: {
476-
description: 'Minimum number of workers to run tests in',
476+
description: 'Minimum number or percentage of workers to run tests in',
477477
argument: '<workers>',
478478
},
479479
environment: {

0 commit comments

Comments
 (0)