Skip to content

docs(en): merge docs-cn/sync-docs into docs-cn/dev @ 666ac87a #685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
13 changes: 12 additions & 1 deletion .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import {
groupIconMdPlugin,
groupIconVitePlugin,
} from 'vitepress-plugin-group-icons'
<<<<<<< HEAD
import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
import { version } from '../package.json'
=======
import llmstxt from 'vitepress-plugin-llms'
import { version } from '../../package.json'
>>>>>>> 666ac87ab1a915e59288a0db12a0c6cb76f55843
import { teamMembers } from './contributors'
import {
bluesky,
Expand Down Expand Up @@ -79,6 +84,7 @@ export default ({ mode }: { mode: string }) => {
'qwik': 'logos:qwik-icon',
},
}),
llmstxt(),
],
},
markdown: {
Expand Down Expand Up @@ -131,7 +137,7 @@ export default ({ mode }: { mode: string }) => {

footer: {
message: 'Released under the MIT License.',
copyright: 'Copyright © 2021-PRESENT Anthony Fu, Matías Capeletto and Vitest contributors',
copyright: 'Copyright © 2021-PRESENT VoidZero Inc. and Vitest contributors',
},

nav: [
Expand Down Expand Up @@ -283,6 +289,11 @@ export default ({ mode }: { mode: string }) => {
link: '/guide/browser/multiple-setups',
docFooterText: 'Multiple Setups | Browser Mode',
},
{
text: 'Visual Regression Testing',
link: '/guide/browser/visual-regression-testing',
docFooterText: 'Visual Regression Testing | Browser Mode',
},
],
},
{
Expand Down
5 changes: 5 additions & 0 deletions .vitepress/sponsors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const vitestSponsors = {
url: 'https://oomol.com/',
img: '/oomol.svg',
},
{
name: 'Mailmeteor',
url: 'https://mailmeteor.com/',
img: '/mailmeteor.svg',
},
],
} satisfies Record<string, Sponsor[]>

Expand Down
8 changes: 7 additions & 1 deletion advanced/runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,20 @@ export default CustomRunner
```

::: warning
<<<<<<< HEAD
Vitest 还会将 `ViteNodeRunner` 的实例作为 `__vitest_executor` 属性注入。你可以使用它来处理 `importFile` 方法中的文件(这是 `TestRunner` 和 `BenchmarkRunner` 的默认行为)。

`ViteNodeRunner` 暴露了 `executeId` 方法,该方法用于在友好的 Vite 环境中导入测试文件。这意味着它会在运行时解析导入并转换文件内容,以便 Node 能够理解。
=======
Vitest also injects an instance of `ModuleRunner` from `vite/module-runner` as `moduleRunner` property. You can use it to process files in `importFile` method (this is default behavior of `TestRunner` and `BenchmarkRunner`).

`ModuleRunner` exposes `import` method, which is used to import test files in a Vite-friendly environment. Meaning, it will resolve imports and transform file content at runtime so that Node can understand it:
>>>>>>> 666ac87ab1a915e59288a0db12a0c6cb76f55843

```ts
export default class Runner {
async importFile(filepath: string) {
await this.__vitest_executor.executeId(filepath)
await this.moduleRunner.import(filepath)
}
}
```
Expand Down
4 changes: 4 additions & 0 deletions api/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,11 @@ test.each(errorDirs)('build fails with "%s"', async (dir) => {

- **类型:** `() => any`

<<<<<<< HEAD
该非对称匹配器与相等检查一起使用时,将始终返回 `true`。如果只想确定属性是否存在,那么它就很有用。
=======
This asymmetric matcher matches anything except `null` or `undefined`. Useful if you just want to be sure that a property exists with any value that's not either `null` or `undefined`.
>>>>>>> 666ac87ab1a915e59288a0db12a0c6cb76f55843

```ts
import { expect, test } from 'vitest'
Expand Down
30 changes: 25 additions & 5 deletions config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,13 @@ Vite 将处理内联模块。这可能有助于处理以 ESM 格式传送 `.js`

#### deps.optimizer {#deps-optimizer}

<<<<<<< HEAD
- **类型:** `{ ssr?, web? }`
- **参考:** [依赖优化选项](https://cn.vitejs.dev/config/dep-optimization-options.html)
=======
- **Type:** `{ ssr?, client? }`
- **See also:** [Dep Optimization Options](https://vitejs.dev/config/dep-optimization-options.html)
>>>>>>> 666ac87ab1a915e59288a0db12a0c6cb76f55843

启用依赖优化。如果你有很多测试,这可能会提高它们的性能。

Expand All @@ -239,7 +244,11 @@ Vite 将处理内联模块。这可能有助于处理以 ESM 格式传送 `.js`
- 你的 `alias` 配置现在在捆绑包中得到处理
- 测试中的代码更接近于它在浏览器中的运行方式

<<<<<<< HEAD
请注意,只有 `deps.experimentalOptimizer?.[mode].include` 选项中的包会被捆绑(一些插件会自动填充它,比如 Svelte)。 你可以在 [Vite](https://cn.vitejs.dev/config/dep-optimization-options.html) 文档中阅读有关可用选项的更多信息。默认情况,Vitest 的 `experimentalOptimizer.web` 用在 `jsdom` 和 `happy-dom`, 在 `node` 和 `edge` 环境下使用 `experimentalOptimizer.ssr`,但这可以在 [`transformMode`](#transformmode) 进行配置。
=======
Be aware that only packages in `deps.optimizer?.[mode].include` option are bundled (some plugins populate this automatically, like Svelte). You can read more about available options in [Vite](https://vitejs.dev/config/dep-optimization-options.html) docs (Vitest doesn't support `disable` and `noDiscovery` options). By default, Vitest uses `optimizer.client` for `jsdom` and `happy-dom` environments, and `optimizer.ssr` for `node` and `edge` environments.
>>>>>>> 666ac87ab1a915e59288a0db12a0c6cb76f55843

此选项还继承了你的 `optimizeDeps` 配置(对于 web 环境, Vitest 将会继承 `optimizeDeps`,对于 ssr 则是 `ssr.optimizeDeps`)。如果你在 `deps.experimentalOptimizer` 中重新定义 `include`/`exclude`/`entries` 选项,它将在运行测试时覆盖你的 `optimizeDeps`。如果它们在 `exclude` 中配置,Vitest 会自动从 `include` 中删除相同的选项。

Expand All @@ -254,21 +263,29 @@ Vite 将处理内联模块。这可能有助于处理以 ESM 格式传送 `.js`

启用依赖优化。

<<<<<<< HEAD
::: warning
此选项仅适用于 Vite 4.3.2 及更高版本。
:::
=======
#### deps.client {#deps-client}
>>>>>>> 666ac87ab1a915e59288a0db12a0c6cb76f55843

#### deps.web <Badge type="info">0.34.2+</Badge>

<<<<<<< HEAD
#### deps.web
=======
Options that are applied to external files when the environment is set to `client`. By default, `jsdom` and `happy-dom` use `client` environment, while `node` and `edge` environments use `ssr`, so these options will have no affect on files inside those environments.
>>>>>>> 666ac87ab1a915e59288a0db12a0c6cb76f55843

- **类型:** `{ transformAssets?, ... }`

当转换模式设置为 `web` 时应用于外部文件的选项。默认情况下,`jsdom` 和 `happy-dom` 使用 `web` 模式,而 `node` 和 `edge` 环境使用 `ssr` 转换模式,因此这些选项不会影响这些环境中的文件。

通常,`node_modules` 内的文件是外部化的,但这些选项也会影响 [`server.deps.external`](#server-deps-external) 中的文件。

#### deps.web.transformAssets
#### deps.client.transformAssets

- **类型:** `boolean`
- **默认值:** `true`
Expand All @@ -281,7 +298,7 @@ Vitest 是否应该像 Vite 在浏览器中一样处理静态资源(.png、.sv
目前,此选项适用于 [`vmThreads`](#vmthreads) 和 [`vmForks`](#vmForks) 池。
:::

#### deps.web.transformCss
#### deps.client.transformCss

- **类型:** `boolean`
- **默认值:** `true`
Expand All @@ -294,7 +311,7 @@ Vitest 是否应该像 Vite 在浏览器中一样处理静态资源(.css, .scs
目前,此选项仅适用于 [`vmThreads`](#vmthreads) 和 [`vmForks`](#vmForks) 池。
:::

#### deps.web.transformGlobPattern
#### deps.client.transformGlobPattern

- **类型:** `RegExp | RegExp[]`
- **默认值:** `[]`
Expand Down Expand Up @@ -556,7 +573,7 @@ import type { Environment } from 'vitest'

export default <Environment>{
name: 'custom',
transformMode: 'ssr',
viteEnvironment: 'ssr',
setup() {
// custom setup
return {
Expand Down Expand Up @@ -616,7 +633,7 @@ In CI, or when run from a non-interactive shell, "watch" mode is not the default

Vitest reruns tests based on the module graph which is populated by static and dynamic `import` statements. However, if you are reading from the file system or fetching from a proxy, then Vitest cannot detect those dependencies.

To correctly rerun those tests, you can define a regex pattern and a function that retuns a list of test files to run.
To correctly rerun those tests, you can define a regex pattern and a function that returns a list of test files to run.

```ts
import { defineConfig } from 'vitest/config'
Expand Down Expand Up @@ -1681,6 +1698,7 @@ test('doNotRun', () => {

将在每次测试前调用 [`vi.unstubAllGlobals`](/api/#vi-unstuballglobals)。

<<<<<<< HEAD
### testTransformMode {#testtransformmode}

- **类型:** `{ web?, ssr? }`
Expand Down Expand Up @@ -1717,6 +1735,8 @@ export default defineConfig({
})
```

=======
>>>>>>> 666ac87ab1a915e59288a0db12a0c6cb76f55843
### snapshotFormat<NonProjectOption />

- **类型:** `PrettyFormatOptions`
Expand Down
Loading