Skip to content
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

docs(en): merge docs-cn/sync-docs into docs-cn/dev @ ad8972b3 #563

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { pwa } from './scripts/pwa'
import { transformHead } from './scripts/transformHead'

export default ({ mode }: { mode: string }) => {
<<<<<<< HEAD
return withPwa(
defineConfig({
lang: 'en-US',
Expand All @@ -36,6 +37,138 @@ export default ({ mode }: { mode: string }) => {
root: {
label: '简体中文',
lang: 'zh',
=======
return withPwa(defineConfig({
lang: 'en-US',
title: vitestName,
description: vitestDescription,
locales: {
root: {
label: 'English',
lang: 'en-US',
},
zh: {
label: '简体中文',
lang: 'zh',
link: 'https://cn.vitest.dev/',
},
},
head: [
['meta', { name: 'theme-color', content: '#729b1a' }],
['link', { rel: 'icon', href: '/favicon.ico', sizes: '48x48' }],
['link', { rel: 'icon', href: '/logo.svg', sizes: 'any', type: 'image/svg+xml' }],
['meta', { name: 'author', content: `${teamMembers.map(c => c.name).join(', ')} and ${vitestName} contributors` }],
['meta', { name: 'keywords', content: 'vitest, vite, test, coverage, snapshot, react, vue, preact, svelte, solid, lit, marko, ruby, cypress, puppeteer, jsdom, happy-dom, test-runner, jest, typescript, esm, tinypool, tinyspy, node' }],
['meta', { property: 'og:title', content: vitestName }],
['meta', { property: 'og:description', content: vitestDescription }],
['meta', { property: 'og:url', content: ogUrl }],
['meta', { property: 'og:image', content: ogImage }],
['meta', { name: 'twitter:title', content: vitestName }],
['meta', { name: 'twitter:description', content: vitestDescription }],
['meta', { name: 'twitter:image', content: ogImage }],
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
['link', { rel: 'preload', as: 'style', onload: 'this.onload=null;this.rel=\'stylesheet\'', href: font }],
['noscript', {}, `<link rel="stylesheet" crossorigin="anonymous" href="${font}" />`],
['link', { rel: 'mask-icon', href: '/logo.svg', color: '#ffffff' }],
['link', { rel: 'apple-touch-icon', href: '/apple-touch-icon.png', sizes: '180x180' }],
],
lastUpdated: true,
vite: {
plugins: [
groupIconVitePlugin({
customIcon: {
'CLI': 'vscode-icons:file-type-shell',
'vitest.shims': 'vscode-icons:file-type-vitest',
'vitest.workspace': 'vscode-icons:file-type-vitest',
'vitest.config': 'vscode-icons:file-type-vitest',
'.spec.ts': 'vscode-icons:file-type-testts',
'.test.ts': 'vscode-icons:file-type-testts',
'.spec.js': 'vscode-icons:file-type-testjs',
'.test.js': 'vscode-icons:file-type-testjs',
'marko': 'vscode-icons:file-type-marko',
},
}),
],
},
markdown: {
config(md) {
md.use(tabsMarkdownPlugin)
md.use(groupIconMdPlugin)
},
theme: {
light: 'github-light',
dark: 'github-dark',
},
codeTransformers: mode === 'development'
? [transformerNotationWordHighlight()]
: [
transformerNotationWordHighlight(),
transformerTwoslash({
processHoverInfo: (info) => {
if (info.includes(process.cwd())) {
return info.replace(new RegExp(process.cwd(), 'g'), '')
}
return info
},
}),
],
},
themeConfig: {
logo: '/logo.svg',

editLink: {
pattern: 'https://github.com/vitest-dev/vitest/edit/main/docs/:path',
text: 'Suggest changes to this page',
},

search: {
provider: 'local',
/* provider: 'algolia',
options: {
appId: 'ZTF29HGJ69',
apiKey: '9c3ced6fed60d2670bb36ab7e8bed8bc',
indexName: 'vitest',
// searchParameters: {
// facetFilters: ['tags:en'],
// },
}, */
},

carbonAds: {
code: 'CW7DVKJE',
placement: 'vitestdev',
},

socialLinks: [
{ icon: 'bluesky', link: bluesky },
{ icon: 'mastodon', link: mastodon },
{ icon: 'discord', link: discord },
{ icon: 'github', link: github },
],

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

nav: [
{ text: 'Guide & API', link: '/guide/', activeMatch: '^/(guide|api)/(?!browser)' },
{ text: 'Config', link: '/config/', activeMatch: '^/config/' },
{ text: 'Browser Mode', link: '/guide/browser', activeMatch: '^/guide/browser/' },
{
text: 'Resources',
items: [
{
text: 'Advanced API',
link: '/advanced/api/',
activeMatch: '^/advanced/',
},
{
text: 'Team',
link: '/team',
},
],
>>>>>>> ad8972b35b240f2baee9909f2fec09db81c2ee8b
},
en: {
label: 'English',
Expand Down Expand Up @@ -202,10 +335,80 @@ export default ({ mode }: { mode: string }) => {
activeMatch: '^/guide/browser/',
},
{
<<<<<<< HEAD
text: '相关连接',
items: [
{
text: '高级 API',
=======
text: 'Configuration',
collapsed: false,
items: [
{
text: 'Browser Config Reference',
link: '/guide/browser/config',
docFooterText: 'Browser Config Reference | Browser Mode',
},
{
text: 'Configuring Playwright',
link: '/guide/browser/playwright',
docFooterText: 'Configuring Playwright | Browser Mode',
},
{
text: 'Configuring WebdriverIO',
link: '/guide/browser/webdriverio',
docFooterText: 'Configuring WebdriverIO | Browser Mode',
},
],
},
{
text: 'API',
collapsed: false,
items: [
{
text: 'Context API',
link: '/guide/browser/context',
docFooterText: 'Context API | Browser Mode',
},
{
text: 'Interactivity API',
link: '/guide/browser/interactivity-api',
docFooterText: 'Interactivity API | Browser Mode',
},
{
text: 'Locators',
link: '/guide/browser/locators',
docFooterText: 'Locators | Browser Mode',
},
{
text: 'Assertion API',
link: '/guide/browser/assertion-api',
docFooterText: 'Assertion API | Browser Mode',
},
{
text: 'Commands API',
link: '/guide/browser/commands',
docFooterText: 'Commands | Browser Mode',
},
],
},
{
text: 'Guides',
collapsed: false,
items: [
{
text: 'Multiple Setups',
link: '/guide/browser/multiple-setups',
docFooterText: 'Multiple Setups | Browser Mode',
},
],
},
{
items: [
...footer(),
{
text: 'Node API Reference',
>>>>>>> ad8972b35b240f2baee9909f2fec09db81c2ee8b
link: '/advanced/api/',
activeMatch: '^/advanced/',
},
Expand Down
2 changes: 1 addition & 1 deletion .vitepress/scripts/cli-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const options = resolveOptions(cliOptionsConfig)
const template = options.map((option) => {
const title = option.title
const cli = option.cli
const config = skipConfig.has(title) ? '' : `[${title}](/config/#${title.toLowerCase().replace(/\./g, '-')})`
const config = skipConfig.has(title) ? '' : `[${title}](${title.includes('browser.') ? '/guide/browser/config' : '/config/'}#${title.toLowerCase().replace(/\./g, '-')})`
return `### ${title}\n\n- **CLI:** ${cli}\n${config ? `- **Config:** ${config}\n` : ''}\n${option.description}\n`
}).join('\n')

Expand Down
9 changes: 8 additions & 1 deletion advanced/api/vitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Vitest 3 is one step closer to stabilising the public API. To achieve that, we d
- `changeNamePattern`
- `changeFilenamePattern`
- `rerunFailed`
- `updateSnapshot`
- `_createRootProject` (renamed to `_ensureRootProject`, but still private)
- `filterTestsBySource` (this was moved to the new internal `vitest.specifications` instance)
- `runFiles` (use [`runTestSpecifications`](#runtestspecifications) instead)
Expand Down Expand Up @@ -326,6 +325,14 @@ function runTestSpecifications(

This method emits `reporter.onWatcherRerun` and `onTestsRerun` events, then it runs tests with [`runTestSpecifications`](#runtestspecifications). If there were no errors in the main process, it will emit `reporter.onWatcherStart` event.

## updateSnapshot

```ts
function updateSnapshot(files?: string[]): Promise<TestRunResult>
```

Update snapshots in specified files. If no files are provided, it will update files with failed tests and obsolete snapshots.

## collectTests

```ts
Expand Down
36 changes: 36 additions & 0 deletions api/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,42 @@ test('getApplesCount has some unusual side effects...', () => {
})
```

## toBeOneOf

- **Type:** `(sample: Array<any>) => any`

`toBeOneOf` asserts if a value matches any of the values in the provided array.

```ts
import { expect, test } from 'vitest'

test('fruit is one of the allowed values', () => {
expect(fruit).toBeOneOf(['apple', 'banana', 'orange'])
})
```

The asymmetric matcher is particularly useful when testing optional properties that could be either `null` or `undefined`:

```ts
test('optional properties can be null or undefined', () => {
const user = {
firstName: 'John',
middleName: undefined,
lastName: 'Doe'
}

expect(user).toEqual({
firstName: expect.any(String),
middleName: expect.toBeOneOf([expect.any(String), undefined]),
lastName: expect.any(String),
})
})
```

:::tip
You can use `expect.not` with this matcher to ensure a value does NOT match any of the provided options.
:::

## toBeTypeOf

- **类型:** `(c: 'bigint' | 'boolean' | 'function' | 'number' | 'object' | 'string' | 'symbol' | 'undefined') => Awaitable<void>`
Expand Down
12 changes: 11 additions & 1 deletion config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1763,8 +1763,9 @@ test('doNotRun', () => {

提供 API 服务的端口。当设置为 true 时,默认端口为 51204

### browser {#browser}
### browser <Badge type="warning">experimental</Badge> {#browser}

<<<<<<< HEAD
- **类型:** `{ enabled?, name?, provider?, headless?, api? }`
- **默认值:** `{ enabled: false, headless: process.env.CI, api: 63315 }`
- **命令行终端:** `--browser`, `--browser=<name>`, `--browser.name=chrome --browser.headless`
Expand All @@ -1774,11 +1775,18 @@ test('doNotRun', () => {
::: tip NOTE
在 [指南页面](/guide/browser/) 中阅读有关在真实浏览器中进行测试的更多信息。
:::
=======
- **Default:** `{ enabled: false }`
- **CLI:** `--browser=<name>`, `--browser.name=chrome --browser.headless`

Configuration for running browser tests. Please, refer to the ["Browser Config Reference"](/guide/browser/config) article.
>>>>>>> ad8972b35b240f2baee9909f2fec09db81c2ee8b

::: warning
这是一项实验性功能。重大更改可能不会遵循 semver,请在使用时锁定 Vitest 的版本。
:::

<<<<<<< HEAD
#### browser.enabled

- **类型:** `boolean`
Expand Down Expand Up @@ -1982,6 +1990,8 @@ export interface BrowserScript {

自定义[命令](/guide/browser/commands),可在浏览器测试期间从 `@vitest/browser/commands` 导入。

=======
>>>>>>> ad8972b35b240f2baee9909f2fec09db81c2ee8b
### clearMocks

- **类型:** `boolean`
Expand Down
4 changes: 4 additions & 0 deletions guide/browser/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ CDP session仅适用于 `playwright` provider,并且仅在使用 `chromium`

## Custom Commands

<<<<<<< HEAD
你也可以通过 [`browser.commands`](/config/#browser-commands) 配置选项添加自己的命令。如果你开发了一个库,你可以通过插件内的 `config` 钩子来提供它们:
=======
You can also add your own commands via [`browser.commands`](/guide/browser/config#browser-commands) config option. If you develop a library, you can provide them via a `config` hook inside a plugin:
>>>>>>> ad8972b35b240f2baee9909f2fec09db81c2ee8b

```ts
import type { Plugin } from 'vitest/config'
Expand Down
Loading