Skip to content

Commit

Permalink
docs: add env documentation (#6063)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Jul 9, 2024
1 parent 95a2d87 commit 7012f8c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 30 deletions.
59 changes: 33 additions & 26 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,32 +246,39 @@ export default ({ mode }: { mode: string }) => {
{
text: 'Browser Mode',
link: '/guide/browser/',
collapsed: true,
items: [{
text: 'Assertion API',
link: '/guide/browser/assertion-api',
docFooterText: 'Assertion API | Browser Mode',
}, {
text: 'Retry-ability',
link: '/guide/browser/retry-ability',
docFooterText: 'Retry-ability | Browser Mode',
}, {
text: 'Context',
link: '/guide/browser/context',
docFooterText: 'Context | Browser Mode',
}, {
text: 'Interactivity API',
link: '/guide/browser/interactivity-api',
docFooterText: 'Interactivity API | Browser Mode',
}, {
text: 'Commands',
link: '/guide/browser/commands',
docFooterText: 'Commands | Browser Mode',
}, {
text: 'Examples',
link: '/guide/browser/examples',
docFooterText: 'Examples | Browser Mode',
}],
collapsed: false,
items: [
{
text: 'Assertion API',
link: '/guide/browser/assertion-api',
docFooterText: 'Assertion API | Browser Mode',
},
{
text: 'Retry-ability',
link: '/guide/browser/retry-ability',
docFooterText: 'Retry-ability | Browser Mode',
},
{
text: 'Context',
link: '/guide/browser/context',
docFooterText: 'Context | Browser Mode',
},
{
text: 'Interactivity API',
link: '/guide/browser/interactivity-api',
docFooterText: 'Interactivity API | Browser Mode',
},
{
text: 'Commands',
link: '/guide/browser/commands',
docFooterText: 'Commands | Browser Mode',
},
{
text: 'Examples',
link: '/guide/browser/examples',
docFooterText: 'Examples | Browser Mode',
},
],
},
{
text: 'In-Source Testing',
Expand Down
2 changes: 1 addition & 1 deletion docs/api/mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Accepts a function that will be used as an implementation of the mock.
```ts twoslash
import { vi } from 'vitest'
// ---cut---
const mockFn = vi.fn().mockImplementation(apples => apples + 1)
const mockFn = vi.fn().mockImplementation((apples: number) => apples + 1)
// or: vi.fn(apples => apples + 1);

const NelliesBucket = mockFn(0)
Expand Down
17 changes: 16 additions & 1 deletion docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn('hello', 1)
expect(vi.isMockFunction(fn)).toBe(true)
expect(fn.mock.calls[0]).toEqual(['hello', 1])

fn.mockImplementation(arg => arg)
fn.mockImplementation((arg: string) => arg)

fn('world', 2)

Expand Down Expand Up @@ -243,3 +243,18 @@ vitest --merge-reports --reporter=junit --coverage.reporter=text
```

See [`Improving Performance | Sharding`](/guide/improving-performance#sharding) for more information.

## Environment Variables

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`:

```ts twoslash
import { loadEnv } from 'vite'
import { defineConfig } from 'vitest/config'

export default defineConfig(({ mode }) => ({
test: {
// mode defines what ".env.{mode}" file to choose if exists
env: loadEnv(mode, process.cwd(), ''),
},
}))
4 changes: 2 additions & 2 deletions packages/vitest/src/node/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,11 @@ export const cliOptionsConfig: VitestCLIOptions = {
'Should all test files run in parallel. Use `--no-file-parallelism` to disable (default: `true`)',
},
maxWorkers: {
description: 'Maximum number of workers to run tests in',
description: 'Maximum number or percentage of workers to run tests in',
argument: '<workers>',
},
minWorkers: {
description: 'Minimum number of workers to run tests in',
description: 'Minimum number or percentage of workers to run tests in',
argument: '<workers>',
},
environment: {
Expand Down

0 comments on commit 7012f8c

Please sign in to comment.