Skip to content
Open
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
7 changes: 7 additions & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export default ({ mode }: { mode: string }) => {
},
}) as any,
],
define: {
__VITEST_VERSION__: JSON.stringify(version),
},
},
markdown: {
config(md) {
Expand Down Expand Up @@ -229,6 +232,10 @@ export default ({ mode }: { mode: string }) => {
text: '团队',
link: '/team',
},
{
text: 'Releases',
link: '/releases',
},
],
},
{
Expand Down
172 changes: 172 additions & 0 deletions .vitepress/theme/SupportedVersions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<script setup lang="ts">
import { computed, ref } from 'vue'

declare const __VITEST_VERSION__: string

// Constants
const supportedVersionMessage = {
color: 'var(--vp-c-brand-1)',
text: 'supported',
}
const notSupportedVersionMessage = {
color: 'var(--vp-c-danger-1)',
text: 'not supported',
}
const previousMajorLatestMinors: Record<string, string> = {
1: '1.6',
2: '2.1',
3: '3.2',
4: '4.1',
}

// Current latest Vitest version and support info
const parsedViteVersion = parseVersion(__VITEST_VERSION__)!
const supportInfo = computeSupportInfo(parsedViteVersion)

// Check supported version input
const checkedVersion = ref(`${Math.max(parsedViteVersion.major - 2, 2)}.0.0`)
const checkedResult = computed(() => {
const version = checkedVersion.value
if (!isValidVitestVersion(version)) {
return notSupportedVersionMessage
}

const parsedVersion = parseVersion(checkedVersion.value)
if (!parsedVersion) {
return notSupportedVersionMessage
}

const satisfies = (targetVersion: string) => {
const compared = parseVersion(targetVersion)!
return (
parsedVersion.major === compared.major
&& parsedVersion.minor >= compared.minor
)
}
const satisfiesOneSupportedVersion
= parsedVersion.major >= parsedViteVersion.major // Treat future major versions as supported
|| supportInfo.regularPatches.some(satisfies)
|| supportInfo.importantFixes.some(satisfies)
|| supportInfo.securityPatches.some(satisfies)

return satisfiesOneSupportedVersion
? supportedVersionMessage
: notSupportedVersionMessage
})

function parseVersion(version: string) {
let [major, minor, patch] = version.split('.').map((v) => {
const num = /^\d+$/.exec(v)?.[0]

Check failure on line 59 in .vitepress/theme/SupportedVersions.vue

View workflow job for this annotation

GitHub Actions / autofix

Move this regular expression to module scope to avoid re-compilation on every call
return num ? Number.parseInt(num) : null
})
if (!major) {
return null
}
minor ??= 0
patch ??= 0

return { major, minor, patch }
}

function computeSupportInfo(
version: NonNullable<ReturnType<typeof parseVersion>>,
) {
const { major, minor } = version
const f = (versions: string[]) => {
return versions
.map(v => previousMajorLatestMinors[v] ?? v)
.filter((version) => {
if (!isValidVitestVersion(version)) {
return false
}
// Negative versions are invalid
if (/-\d/.test(version)) {

Check failure on line 83 in .vitepress/theme/SupportedVersions.vue

View workflow job for this annotation

GitHub Actions / autofix

Move this regular expression to module scope to avoid re-compilation on every call
return false
}
return true
})
}

return {
regularPatches: f([`${major}.${minor}`]),
importantFixes: f([`${major - 1}`, `${major}.${minor - 1}`]),
// unlike vite, we only support the last major version
securityPatches: f([`${major - 1}`, `${major}.${minor - 1}`]),
}
}

function versionsToText(versions: string[]) {
versions = versions.map(v => `<code>vitest@${v}</code>`)
if (versions.length === 0) {
return ''
}
if (versions.length === 1) {
return versions[0]
}
return (
`${versions.slice(0, -1).join(', ')} and ${versions[versions.length - 1]}`
)
}

function isValidVitestVersion(version: string) {
if (version.length === 1) {
version += '.'
}
// Vitest 0.x shouldn't be mentioned
if (version.startsWith('0.')) {
return false
}
return true
}
</script>

<template>
<div>
<ul>
<li v-if="supportInfo.regularPatches.length">
Regular patches are released for
<span v-html="versionsToText(supportInfo.regularPatches)" />.
</li>
<li v-if="supportInfo.importantFixes.length">
Important fixes and security patches are backported to
<span v-html="versionsToText(supportInfo.importantFixes)" />.
</li>
<li>
All versions before these are no longer supported. Users should upgrade
to receive updates.
</li>
</ul>
<p>
If you're using Vitest
<input
v-model="checkedVersion"
class="checked-input"
type="text"
placeholder="0.0.0"
>, it is
<strong :style="{ color: checkedResult.color }">{{
checkedResult.text
}}</strong>.
</p>
</div>
</template>

<style scoped>
.checked-input {
display: inline-block;
padding: 0px 5px;
width: 100px;
color: var(--vp-c-text-1);
background: var(--vp-c-bg-soft);
font-size: var(--vp-code-font-size);
font-family: var(--vp-font-family-mono);
border: 1px solid var(--vp-c-divider);
border-radius: 5px;
transition: border-color 0.1s;
}

.checked-input:focus,
.checked-input:hover {
border-color: var(--vp-c-brand);
}
</style>
13 changes: 12 additions & 1 deletion config/browser/locators.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ outline: deep

用于通过 `getByTestId` 定位器查找元素的属性。

## browser.locators.exact <Version type="experimental">4.1.3</Version> {#browser-locators-exact}
## browser.locators.exact

<<<<<<< HEAD
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve merge conflict markers before publishing docs

This commit leaves unresolved merge-conflict markers (<<<<<<<, =======, >>>>>>>) in documentation content (also present in config/forcereruntriggers.md, guide/cli-generated.md, and guide/migration.md). As committed, the site will render raw conflict text and contradictory values (for example browser.locators.exact shows both false and true defaults), which makes the docs unreliable until the conflicts are resolved.

Useful? React with 👍 / 👎.

- **类型:** `boolean`
- **默认值:** `false`

Expand All @@ -24,6 +25,16 @@ outline: deep
```ts
// 当 exact: false(默认值)时,会匹配 "Hello, World!"、"Say Hello, World" 等文本
// 当 exact: true 时,仅精确匹配字符串 "Hello, World"
=======
- **Type:** `boolean`
- **Default:** `true`

When set to `true`, [locators](/api/browser/locators) match text exactly by default, requiring a full, case-sensitive match. Individual locator calls can override this default via their own `exact` option.

```ts
// With exact: true (default), this only matches the string "Hello, World" exactly.
// With exact: false, this matches "Hello, World!", "Say Hello, World", etc.
>>>>>>> 988854f772c8e8fd6f0c5fee0d18f90f58657ea6
const locator = page.getByText('Hello, World', { exact: true })
await locator.click()
```
Expand Down
5 changes: 5 additions & 0 deletions config/forcereruntriggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ outline: deep

# forceRerunTriggers <CRoot />

<<<<<<< HEAD
- **类型:** `string[]`
- **默认值:** `['**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**']`
=======
- **Type:** `string[]`
- **Default:** `['**/package.json', '**/vitest.config.*', '**/vite.config.*']`
>>>>>>> 988854f772c8e8fd6f0c5fee0d18f90f58657ea6

将触发整个测试套件重新运行的文件路径(glob 模式)。当与 `--changed` 参数配合使用时,如果在 git diff 中发现触发文件,就会运行整个测试套件。

Expand Down
4 changes: 4 additions & 0 deletions guide/cli-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,13 @@
- **命令行终端:** `--browser.locators.exact`
- **配置:** [browser.locators.exact](/config/browser/locators#locators-exact)

<<<<<<< HEAD
定位器是否默认需完全匹配文本内容(默认值:`false`)
=======
Should locators match the text exactly by default (default: `true`)
>>>>>>> 988854f772c8e8fd6f0c5fee0d18f90f58657ea6

### pool

Check failure on line 471 in guide/cli-generated.md

View workflow job for this annotation

GitHub Actions / autofix

Heading level skipped from 1 to 3

- **命令行终端:** `--pool <pool>`
- **配置:** [pool](/config/pool)
Expand Down
19 changes: 19 additions & 0 deletions guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

# 迁移指南 {#migration-guide}

<<<<<<< HEAD

Check failure on line 8 in guide/migration.md

View workflow job for this annotation

GitHub Actions / autofix

Unexpected additional H1 heading found
[迁移至 Vitest 3.0](https://v3.vitest.dev/guide/migration) | [迁移至 Vitest 2.0](https://v2.vitest.dev/guide/migration)
=======
[Migrating to Vitest 4.0](https://v4.vitest.dev/guide/migration) | [Migrating to Vitest 3.0](https://v3.vitest.dev/guide/migration)
>>>>>>> 988854f772c8e8fd6f0c5fee0d18f90f58657ea6

## 迁移至 Vitest 5.0 {#vitest-5}

Expand Down Expand Up @@ -56,7 +60,22 @@
}
```

<<<<<<< HEAD
### 移除了已弃用的入口 {#removed-deprecated-entrypoints}
=======
### Locators are Strict by Default

Browser locators now match the text exactly by default, requiring a full, case-sensitive match. To keep the previous behaviour, you can set [`browser.locators.exact`](/config/browser/locators#browser-locators-exact) to `false`.

```ts
// With exact: true (default), this only matches the string "Hello, World" exactly.
// With exact: false, this matches "Hello, World!", "Say Hello, World", etc.
const locator = page.getByText('Hello, World', { exact: true })
await locator.click()
```

### Removed Deprecated Entrypoints
>>>>>>> 988854f772c8e8fd6f0c5fee0d18f90f58657ea6

多个入口在 Vitest 4.1 中被标记为已弃用。此版本完全移除了它们。

Expand Down
57 changes: 57 additions & 0 deletions releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<script setup>
import SupportedVersions from './.vitepress/theme/SupportedVersions.vue';
</script>

# Releases

Vitest releases follow [Semantic Versioning](https://semver.org/). You can see the latest stable version of Vitest in the [Vitest npm package page](https://www.npmjs.com/package/vite).
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Point the Vitest package link to the correct npm package

The sentence says this is the Vitest package page, but the URL points to https://www.npmjs.com/package/vite (Vite). Readers using this link will land on the wrong package and can install or verify the wrong dependency; the link should target the Vitest package instead.

Useful? React with 👍 / 👎.


A full changelog of past releases is [available on GitHub](https://github.com/vitest-dev/vitest/releases).

## Release Cycle

Vitest does not have a fixed release cycle.

- **Patch** releases are released as needed (usually every week).
- **Minor** releases always contain new features and are released as needed. Minor releases always have a beta pre-release phase (usually every two months).
- **Major** releases generally align with [Vite](https://vite.dev/releases) and [Node.js EOL schedule](https://endoflife.date/nodejs), and will be announced ahead of time. These releases will have a long beta pre-release phases (usually every year).

## Supported Versions

In summary, the current supported Vitest versions are:

<SupportedVersions />

<br>

The supported version ranges are automatically determined by:

- **Current Minor** gets regular fixes.
- **Previous Major** (only for its latest minor) and **Previous Minor** receives important fixes and security patches.
- All versions before these are no longer supported.

We recommend updating Vitest regularly. Check out the [Migration Guides](/guide/migration) when you update to each Major. We test new Vitest versions before releasing them through the [vitest-ecosystem-ci project](https://github.com/vitest-dev/vitest-ecosystem-ci). Most projects using Vitest should be able to quickly offer support or migrate to new versions as soon as they are released.

## Semantic Versioning Edge Cases

### TypeScript Definitions

We may ship incompatible changes to TypeScript definitions between minor versions. This is because:

- Sometimes TypeScript itself ships incompatible changes between minor versions, and we may have to adjust types to support newer versions of TypeScript.
- Occasionally we may need to adopt features that are only available in a newer version of TypeScript, raising the minimum required version of TypeScript.
- If you are using TypeScript, you can use a semver range that locks the current minor and manually upgrade when a new minor version of Vite is released.

## Pre Releases

Minor releases typically go through a non-fixed number of beta releases. Major releases will go through a long beta phase.

Pre-releases allow early adopters and maintainers from the Ecosystem to do integration and stability testing, and provide feedback. Do not use pre-releases in production. All pre-releases are considered unstable and may ship breaking changes in between. Always pin to exact versions when using pre-releases.

## Deprecations

We periodically deprecate features that have been superseded by better alternatives in Minor releases. Deprecated features will continue to work with a type or logged warning. They will be removed in the next major release after entering deprecated status. The [Migration Guide](/guide/migration.html) for each major will list these removals and document an upgrade path for them.

## Experimental Features

Some features are marked as experimental when released in a stable version of Vite. Experimental features allow us to gather real-world experience to influence their final design. The goal is to let users provide feedback by testing them in production. Experimental features themselves are considered unstable, and should only be used in a controlled manner. These features may change between Minors, so users must pin their Vite version when they rely on them. We will create [a GitHub discussion](https://github.com/vitest-dev/vitest/discussions/categories/feedback?discussions_q=is%3Aopen+label%3Aexperimental+category%3AFeedback) for each experimental feature.
Loading