Skip to content

Commit 2a3d656

Browse files
committed
docs: update content
1 parent 2a88219 commit 2a3d656

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

guide/coverage.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,23 @@ Vitest 默认采用 'v8' 作为覆盖率提供器。
8585
简单来说,插桩就是在你的源文件里加入一段额外的 JavaScript,用于记录代码的执行路径:
8686

8787
```js
88-
// Simplified example of branch and function coverage counters
88+
// 分支和函数覆盖率计数器的简化示例
8989
const coverage = { // [!code ++]
9090
branches: { 1: [0, 0] }, // [!code ++]
9191
functions: { 1: 0 }, // [!code ++]
9292
} // [!code ++]
9393

9494
export function getUsername(id) {
95-
// Function coverage increased when this is invoked // [!code ++]
95+
// 当这个函数被调用时,函数覆盖率会增加 // [!code ++]
9696
coverage.functions['1']++ // [!code ++]
9797

9898
if (id == null) {
99-
// Branch coverage increased when this is invoked // [!code ++]
99+
// 当这个分支被调用时,分支覆盖率会增加 // [!code ++]
100100
coverage.branches['1'][0]++ // [!code ++]
101101

102102
throw new Error('User ID is required')
103103
}
104-
// Implicit else coverage increased when if-statement condition not met // [!code ++]
104+
// 当 if 语句条件不满足时,隐式的 else 覆盖率会增加 // [!code ++]
105105
coverage.branches['1'][1]++ // [!code ++]
106106

107107
return database.getUser(id)
@@ -247,10 +247,10 @@ export default defineConfig({
247247
test: {
248248
coverage: {
249249
reporter: [
250-
// Specify reporter using name of the NPM package
250+
// 使用 NPM 包的名称指定报告器
251251
['@vitest/custom-coverage-reporter', { someOption: true }],
252252

253-
// Specify reporter using local path
253+
// 使用本地路径指定报告器
254254
'/absolute/path/to/custom-reporter.cjs',
255255
],
256256
},
@@ -267,7 +267,7 @@ module.exports = class CustomReporter extends ReportBase {
267267
constructor(opts) {
268268
super()
269269

270-
// Options passed from configuration are available here
270+
// 从配置中传递的选项在这里可用
271271
this.file = opts.file
272272
}
273273

@@ -315,7 +315,7 @@ const CustomCoverageProviderModule: CoverageProviderModule = {
315315
return new CustomCoverageProvider()
316316
},
317317

318-
// Implements rest of the CoverageProviderModule ...
318+
// 实现 CoverageProviderModule 的其余部分...
319319
}
320320

321321
class CustomCoverageProvider implements CoverageProvider {
@@ -326,7 +326,7 @@ class CustomCoverageProvider implements CoverageProvider {
326326
this.options = ctx.config.coverage
327327
}
328328

329-
// Implements rest of the CoverageProvider ...
329+
// 实现 CoverageProvider 的其余部分...
330330
}
331331

332332
export default CustomCoverageProviderModule
@@ -426,8 +426,8 @@ catch (error) {
426426
console.log('Ignored') // [!code error]
427427
}
428428

429-
// Requires rolldown-vite due to esbuild's lack of support.
430-
// See https://vite.dev/guide/rolldown.html#how-to-try-rolldown
429+
// 由于 esbuild 不支持,需要使用 rolldown-vite。
430+
// 参阅 https://vite.dev/guide/rolldown.html#how-to-try-rolldown
431431
try {
432432
console.log('Included')
433433
}
@@ -462,9 +462,9 @@ export function ignored() { // [!code error]
462462
```
463463
:::
464464

465-
## Coverage Performance {#coverage-performance}
465+
## 覆盖率性能 {#coverage-performance}
466466

467-
If code coverage generation is slow on your project, see [Profiling Test Performance | Code coverage](/guide/profiling-test-performance.html#code-coverage).
467+
如果你的项目中代码覆盖率生成较慢,请参阅[性能测试分析 | 代码覆盖率](/guide/profiling-test-performance.html#code-coverage)
468468

469469
## Vitest UI {#vitest-ui}
470470

guide/profiling-test-performance.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ _src_prime-number_ts-525172412.js
179179
180180
## Code coverage
181181
182-
If code coverage generation is slow on your project you can use `DEBUG=vitest:coverage` environment variable to enable performance logging.
182+
如果你的项目中代码覆盖率生成较慢,您可以使用 `DEBUG=vitest:coverage` 环境变量来启用性能日志记录。
183183
184184
```bash
185185
$ DEBUG=vitest:coverage vitest --run --coverage
@@ -199,9 +199,9 @@ $ DEBUG=vitest:coverage vitest --run --coverage
199199
vitest:coverage Generate coverage total time 3521 ms
200200
```
201201
202-
This profiling approach is great for detecting large files that are accidentally picked by coverage providers.
203-
For example if your configuration is accidentally including large built minified Javascript files in code coverage, they should appear in logs.
204-
In these cases you might want to adjust your [`coverage.include`](/config/#coverage-include) and [`coverage.exclude`](/config/#coverage-exclude) options.
202+
这种性能分析方法非常适合检测被覆盖率提供程序意外包含的大文件。
203+
例如,如果你的配置意外地将大型构建压缩后的 JavaScript 文件包含在代码覆盖率中,这些文件应该会出现在日志中。
204+
在这种情况下,你可能需要调整 [`coverage.include`](/config/#coverage-include) [`coverage.exclude`](/config/#coverage-exclude) 选项。
205205
206206
## Inspecting profiling records
207207

guide/reporters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export default defineConfig({
142142
Duration 1.26s (transform 35ms, setup 1ms, collect 90ms, tests 1.47s, environment 0ms, prepare 267ms)
143143
```
144144

145-
If there is only one test file running, Vitest will output the full test tree of that file, simillar to the [`tree`](#tree-reporter) reporter. The default reporter will also print the test tree if there is at least one failed test in the file.
145+
如果只有一个测试文件在运行,Vitest 将输出该文件的完整测试树,类似于 [`tree`](#tree-reporter) 报告器。如果文件中至少有一个测试失败,default 报告器也会打印测试树。
146146

147147
```bash
148148
✓ __tests__/file1.test.ts (2) 725ms
@@ -196,7 +196,7 @@ Example output:
196196
Duration 1.26s (transform 35ms, setup 1ms, collect 90ms, tests 1.47s, environment 0ms, prepare 267ms)
197197
```
198198

199-
An example with `--includeTaskLocation`:
199+
一个带有 `--includeTaskLocation` 参数的示例:
200200

201201
```bash
202202
✓ __tests__/file1.test.ts:2:1 > first test file > 2 + 2 should equal 4 1ms

0 commit comments

Comments
 (0)