diff --git a/api/advanced/artifacts.md b/api/advanced/artifacts.md index b1db9f49..114e9945 100644 --- a/api/advanced/artifacts.md +++ b/api/advanced/artifacts.md @@ -82,6 +82,13 @@ export interface TestAttachment { path?: string /** Inline attachment content as a string or raw binary data */ body?: string | Uint8Array + /** + * @experimental + * How the string `body` is encoded. + * - `'base64'` (default): body is already base64-encoded + * - `'utf-8'`: body is a utf8 string + */ + bodyEncoding?: 'base64' | 'utf-8' } ``` @@ -89,6 +96,8 @@ The `TestAttachment` interface represents a file or data attachment associated w Attachments can be either file-based (via `path`) or inline content (via `body`). The `contentType` helps consumers understand how to interpret the attachment data. +If you pass a string `body`, Vitest assumes it is already base64-encoded unless you set `bodyEncoding: 'utf-8'`. When you pass `body` as a `Uint8Array`, Vitest automatically encodes it as base64. The `bodyEncoding` option only applies to inline `body` attachments, not `path` attachments. + ### `TestArtifactLocation` ```ts diff --git a/config/browser/locators.md b/config/browser/locators.md index facf7a00..a8c05c80 100644 --- a/config/browser/locators.md +++ b/config/browser/locators.md @@ -13,3 +13,17 @@ outline: deep - **默认值:** `data-testid` 用于通过 `getByTestId` 定位器查找元素的属性。 + +## browser.locators.exact 4.1.3 {#browser-locators-exact} + +- **Type:** `boolean` +- **Default:** `false` + +When set to `true`, [locators](/api/browser/locators) will 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: false (default), this matches "Hello, World!", "Say Hello, World", etc. +// With exact: true, this only matches the string "Hello, World" exactly. +const locator = page.getByText('Hello, World', { exact: true }) +await locator.click() +``` diff --git a/guide/cli-generated.md b/guide/cli-generated.md index 7f97bb49..768dd3b4 100644 --- a/guide/cli-generated.md +++ b/guide/cli-generated.md @@ -428,6 +428,13 @@ Directory of HTML coverage output to be served in UI mode and HTML reporter. - **配置:** [browser.trace](/config/browser/trace) 启用追踪视图模式。 可选项: "on", "off", "on-first-retry", "on-all-retries", "retain-on-failure" + +### browser.locators.exact + +- **CLI:** `--browser.locators.exact` +- **Config:** [browser.locators.exact](/config/browser/locators#locators-exact) + +Should locators match the text exactly by default (default: `false`) ### pool diff --git a/guide/test-annotations.md b/guide/test-annotations.md index 37396ca1..c32f7e10 100644 --- a/guide/test-annotations.md +++ b/guide/test-annotations.md @@ -17,6 +17,12 @@ test('hello world', async ({ annotate }) => { const file = createTestSpecificFile() await annotate('creates a file', { body: file }) + + await annotate('creates a file with text', { + contentType: 'text/markdown', + body: 'Hello **markdown**', + bodyEncoding: 'utf-8', + }) }) ``` diff --git a/guide/ui.md b/guide/ui.md index 630acc74..b2439c4a 100644 --- a/guide/ui.md +++ b/guide/ui.md @@ -52,6 +52,23 @@ npx vite preview --outDir ./html 你可以使用 [`outputFile`](/config/outputfile) 配置选项配置输出。你需要在那里指定 `.html` 路径。例如,`./html/index.html` 是默认值。 ::: + +::: tip +To view the HTML report from CI, for example in GitHub Actions, upload the output directory as an artifact: + +```yaml +- uses: actions/upload-artifact@v4 + id: upload-report + with: + name: vitest-report + path: html/ + +- name: Viewer link in summary + run: echo "[View HTML report](https://viewer.vitest.dev/?url=${{ steps.upload-report.outputs.artifact-url }})" >> $GITHUB_STEP_SUMMARY +``` + +This adds a link to the job summary. Click it to open the report in [Vitest Viewer](https://viewer.vitest.dev/) directly in the browser. You can also download the artifact manually and extract it, then run `vite preview` locally as above. +::: ## 模块图 {#module-graph}