diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index cbaa58b6e641..c87d8730c247 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -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', diff --git a/docs/api/mock.md b/docs/api/mock.md index bbbc9893886e..4addb63fcf3c 100644 --- a/docs/api/mock.md +++ b/docs/api/mock.md @@ -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) diff --git a/docs/guide/features.md b/docs/guide/features.md index b9cf838b0bee..5ea007d88c9d 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -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) @@ -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(), ''), + }, +})) diff --git a/packages/vitest/src/node/cli/cli-config.ts b/packages/vitest/src/node/cli/cli-config.ts index 3a99814317e2..f9b8b1a3ac97 100644 --- a/packages/vitest/src/node/cli/cli-config.ts +++ b/packages/vitest/src/node/cli/cli-config.ts @@ -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: '', }, minWorkers: { - description: 'Minimum number of workers to run tests in', + description: 'Minimum number or percentage of workers to run tests in', argument: '', }, environment: {