Skip to content

Commit a885f26

Browse files
committed
docs(en): merging all conflicts
2 parents 4393761 + 93d506c commit a885f26

5 files changed

Lines changed: 71 additions & 2 deletions

File tree

api/browser/assertions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ interface ExpectPollOptions {
5454
```
5555

5656
::: tip
57+
<<<<<<< HEAD
5758
`expect.element``expect.poll(() => element)`的简写,工作方式完全相同。
59+
=======
60+
Like [`expect.poll`](/api/expect#poll), `expect.element` retries DOM assertions until they pass or the timeout is reached. When it receives a locator, Vitest resolves it with [`locator.findElement()`](/api/browser/locators#findelement) before running the DOM assertion. The `timeout` option applies to the whole retry operation. The `interval` option controls how often failed DOM assertions are retried, but locator resolution uses `findElement`'s own increasing retry intervals.
61+
>>>>>>> 93d506c0d3a604ea067f8e4b69315ce75ccceb1b
5862
5963
`toHaveTextContent` 以及其他所有断言在常规的 `expect` 中仍然可用,但没有内置的重试机制:
6064

api/expect.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,17 @@ test('expect.soft test', () => {
105105

106106
```ts
107107
interface ExpectPoll extends ExpectStatic {
108-
(actual: () => T, options?: { interval?: number; timeout?: number; message?: string }): Promise<Assertions<T>>
108+
(actual: (options: { signal: AbortSignal }) => T, options?: { interval?: number; timeout?: number; message?: string }): Promise<Assertions<Awaited<T>>>
109109
}
110110
```
111111

112+
<<<<<<< HEAD
112113
`expect.poll` 重新运行断言,直到成功为止。你可以通过设置 `interval``timeout` 选项来配置 Vitest 应重新运行 `expect.poll` 回调的次数。
114+
=======
115+
`expect.poll` reruns the _assertion_ until it is succeeded. You can configure how often Vitest retries and how long it waits by setting `interval` and `timeout` options. The `timeout` applies to the whole polling operation, including pending callback and async matcher execution.
116+
117+
The callback receives an `AbortSignal` that is aborted when the poll timeout is reached.
118+
>>>>>>> 93d506c0d3a604ea067f8e4b69315ce75ccceb1b
113119
114120
如果在 `expect.poll` 回调中抛出错误,Vitest 将重试直到超时为止。
115121

api/mock.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,9 @@ MyClass.mock.instances[0] === a
702702
若构造函数显式返回值,该值不会存入 `instances`,而会出现在 `results` 中:
703703

704704
```js
705-
const Spy = vi.fn(() => ({ method: vi.fn() }))
705+
const Spy = vi.fn(function () {
706+
return { method: vi.fn() }
707+
})
706708
const a = new Spy()
707709
708710
Spy.mock.instances[0] !== a

guide/common-errors.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,55 @@ test('rejects for missing user', async () => {
167167
await expect(fetchUser(123)).rejects.toThrow('User 123 not found')
168168
})
169169
```
170+
171+
## Package fails to load in Vitest but works in your app
172+
173+
Some packages work in an app build but fail in Vitest because they are only valid after a bundler has rewritten or resolved them. When Vitest externalizes a dependency, Node.js loads it directly, so Node's ESM and package rules apply. See Node.js documentation on [ECMAScript modules](https://nodejs.org/docs/latest/api/esm.html) and [packages](https://nodejs.org/docs/latest/api/packages.html) for the precise rules.
174+
175+
Common examples include packages that:
176+
177+
- ship ESM syntax in `.js` files without `"type": "module"`
178+
- use extensionless relative imports in ESM files
179+
- have incorrect `exports`, `imports`, `main`, or `module` entries
180+
- mix CommonJS and ESM entry points in a way that only works after bundling
181+
- import CSS or other non-JavaScript files that are expected to be handled by a bundler
182+
183+
You might see errors such as:
184+
185+
- `Cannot find module './relative-path' imported from ...`
186+
- `Unexpected token 'export'`
187+
- `Cannot use import statement outside a module`
188+
- `Module ... seems to be an ES Module but shipped in a CommonJS package.`
189+
- `Unknown file extension ".css"`
190+
191+
When possible, fix the package so Node.js can load it directly: add `"type": "module"` for ESM `.js` files, use `.mjs`, include explicit file extensions in ESM imports, and make sure `exports` points to files Node.js can load.
192+
193+
If you cannot fix the package itself, inline it so Vite handles it instead of passing it to Node.js as an external dependency. Inline the whole dependency chain that leads to the invalid package. If your source imports `wrapper-package`, and `wrapper-package` imports `broken-package`, inline both packages:
194+
195+
```ts [vitest.config.js]
196+
import { defineConfig } from 'vitest/config'
197+
198+
export default defineConfig({
199+
test: {
200+
server: {
201+
deps: {
202+
inline: ['wrapper-package', 'broken-package'],
203+
},
204+
},
205+
},
206+
})
207+
```
208+
209+
You can also use Vite's [`ssr.resolve.noExternal`](https://vite.dev/config/ssr-options#ssr-resolve-noexternal) for the same purpose. Vitest merges `ssr.resolve.noExternal` into [`server.deps.inline`](/config/server#server-deps-inline), so this is useful when the dependency also needs to be bundled by Vite in SSR builds:
210+
211+
```ts [vitest.config.js]
212+
import { defineConfig } from 'vitest/config'
213+
214+
export default defineConfig({
215+
ssr: {
216+
resolve: {
217+
noExternal: ['wrapper-package', 'broken-package'],
218+
},
219+
},
220+
})
221+
```

guide/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ bun add -D vitest
4141

4242
:::
4343

44+
<<<<<<< HEAD
4445
:::tip 提示
4546
Vitest 需要 Vite >=v6.0.0 和 Node >=v20.0.0
47+
=======
48+
:::tip
49+
Vitest requires Vite >=v6.4.0 and Node >=v22.12.0
50+
>>>>>>> 93d506c0d3a604ea067f8e4b69315ce75ccceb1b
4651
:::
4752

4853
如果在 `package.json` 中安装一份 `vitest` 的副本,可以使用上面列出的方法之一。然而,如果更倾向于直接运行 `vitest` ,可以使用 `npx vitest``npx` 会随着 npm 和 Node.js 一起被安装)。

0 commit comments

Comments
 (0)