Skip to content

Commit 57d23ce

Browse files
authored
docs: fix inconsistencies, remove low informative twoslash examples (#6200)
1 parent 8cd8272 commit 57d23ce

35 files changed

+1461
-810
lines changed

docs/.vitepress/config.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ export default ({ mode }: { mode: string }) => {
6060
light: 'github-light',
6161
dark: 'github-dark',
6262
},
63-
codeTransformers: mode === 'development' ? [] : [transformerTwoslash()],
63+
codeTransformers: mode === 'development'
64+
? []
65+
: [transformerTwoslash({
66+
processHoverInfo: (info) => {
67+
if (info.includes(process.cwd())) {
68+
return info.replace(new RegExp(process.cwd(), 'g'), '')
69+
}
70+
return info
71+
},
72+
})],
6473
},
6574
themeConfig: {
6675
logo: '/logo.svg',

docs/.vitepress/scripts/cli-generator.ts

+37-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,37 @@ import type { CLIOption, CLIOptions } from '../../../packages/vitest/src/node/cl
55
import { cliOptionsConfig } from '../../../packages/vitest/src/node/cli/cli-config'
66

77
const docsDir = resolve(dirname(fileURLToPath(import.meta.url)), '../..')
8-
const cliTablePath = resolve(docsDir, './guide/cli-table.md')
8+
const cliTablePath = resolve(docsDir, './guide/cli-generated.md')
99

1010
const nonNullable = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined
1111

12+
const skipCli = new Set([
13+
'mergeReports',
14+
'changed',
15+
'shard',
16+
])
17+
18+
const skipConfig = new Set([
19+
'config',
20+
'api.port',
21+
'api.host',
22+
'api.strictPort',
23+
'coverage.watermarks.statements',
24+
'coverage.watermarks.lines',
25+
'coverage.watermarks.branches',
26+
'coverage.watermarks.functions',
27+
'coverage.thresholds.statements',
28+
'coverage.thresholds.branches',
29+
'coverage.thresholds.functions',
30+
'coverage.thresholds.lines',
31+
'standalone',
32+
'clearScreen',
33+
'color',
34+
'run',
35+
'hideSkippedTests',
36+
'dom',
37+
])
38+
1239
function resolveOptions(options: CLIOptions<any>, parentName?: string) {
1340
return Object.entries(options).flatMap(
1441
([subcommandName, subcommandConfig]) => resolveCommand(
@@ -19,7 +46,7 @@ function resolveOptions(options: CLIOptions<any>, parentName?: string) {
1946
}
2047

2148
function resolveCommand(name: string, config: CLIOption<any> | null): any {
22-
if (!config) {
49+
if (!config || skipCli.has(name)) {
2350
return null
2451
}
2552

@@ -37,17 +64,19 @@ function resolveCommand(name: string, config: CLIOption<any> | null): any {
3764
}
3865

3966
return {
40-
title,
67+
title: name,
68+
cli: title,
4169
description: config.description,
4270
}
4371
}
4472

4573
const options = resolveOptions(cliOptionsConfig)
4674

47-
const template = `
48-
| Options | |
49-
| ------------- | ------------- |
50-
${options.map(({ title, description }) => `| ${title} | ${description} |`).join('\n')}
51-
`.trimStart()
75+
const template = options.map((option) => {
76+
const title = option.title
77+
const cli = option.cli
78+
const config = skipConfig.has(title) ? '' : `[${title}](/config/#${title.toLowerCase().replace(/\./g, '-')})`
79+
return `### ${title}\n\n- **CLI:** ${cli}\n${config ? `- **Config:** ${config}\n` : ''}\n${option.description}\n`
80+
}).join('\n')
5281

5382
writeFileSync(cliTablePath, template, 'utf-8')

docs/advanced/api.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Vitest exposes experimental private API. Breaking changes might not follow SemVe
88

99
You can start running Vitest tests using its Node API:
1010

11-
```js twoslash
11+
```js
1212
import { startVitest } from 'vitest/node'
1313

1414
const vitest = await startVitest('test')
@@ -38,7 +38,7 @@ Alternatively, you can pass in the complete Vite config as the fourth argument,
3838
3939
You can create Vitest instance yourself using `createVitest` function. It returns the same `Vitest` instance as `startVitest`, but it doesn't start tests and doesn't validate installed packages.
4040
41-
```js twoslash
41+
```js
4242
import { createVitest } from 'vitest/node'
4343

4444
const vitest = await createVitest('test', {
@@ -50,7 +50,7 @@ const vitest = await createVitest('test', {
5050
5151
You can use this method to parse CLI arguments. It accepts a string (where arguments are split by a single space) or a strings array of CLI arguments in the same format that Vitest CLI uses. It returns a filter and `options` that you can later pass down to `createVitest` or `startVitest` methods.
5252
53-
```ts twoslash
53+
```ts
5454
import { parseCLI } from 'vitest/node'
5555

5656
parseCLI('vitest ./files.ts --coverage --browser=chrome')

docs/advanced/pool.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Vitest runs tests in pools. By default, there are several pools:
1414

1515
You can provide your own pool by specifying a file path:
1616

17-
```ts twoslash
17+
```ts
1818
import { defineConfig } from 'vitest/config'
19-
// ---cut---
19+
2020
export default defineConfig({
2121
test: {
2222
// will run every file with a custom pool by default

docs/advanced/reporters.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ You can import reporters from `vitest/reporters` and extend them to create your
66

77
In general, you don't need to create your reporter from scratch. `vitest` comes with several default reporting programs that you can extend.
88

9-
```ts twoslash
9+
```ts
1010
import { DefaultReporter } from 'vitest/reporters'
1111

1212
export default class MyDefaultReporter extends DefaultReporter {

docs/advanced/runner.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Snapshot support and some other features depend on the runner. If you don't want
110110

111111
You can extend Vitest task system with your tasks. A task is an object that is part of a suite. It is automatically added to the current suite with a `suite.task` method:
112112

113-
```js twoslash
113+
```js
114114
// ./utils/custom.js
115115
import { createTaskCollector, getCurrentSuite, setFn } from 'vitest/suite'
116116

@@ -134,7 +134,7 @@ export const myCustomTask = createTaskCollector(
134134
)
135135
```
136136

137-
```js twoslash
137+
```js
138138
// ./garden/tasks.test.js
139139
import { afterAll, beforeAll, describe, myCustomTask } from '../custom.js'
140140
import { gardener } from './gardener.js'

0 commit comments

Comments
 (0)