# @grafana/plugin-e2e 中文文档

规范地址：https://npmcn.com/package/%40grafana/plugin-e2e/

版本：4\.0\.0
npm 元数据更新时间：2026-11-03T15:35:11.850Z
中文译文更新时间：2026-11-16T21:44:55.445Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40grafana/plugin-e2e
原文对照：https://npmcn.com/package/%40grafana/plugin-e2e/?lang=original
项目主页：https://github.com/grafana/plugin-tools#readme
源码仓库：https://github.com/grafana/plugin-tools

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：429 kB，90 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=22
- 运行依赖：1 个
- peer 依赖：@playwright/test ^1\.52\.0，@axe-core/playwright ^4\.11\.1
- 首次发布：2023-12-15T11:11:28.664Z
- 最新版本发布：2026-11-03T15:35:11.520Z
- 近 30 天下载量：314441（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：849（近 12 个月 238 个）

## 中文简介

端到端的测试 Grafana 插件轻松.

## 安装

```sh
npm install @grafana/plugin-e2e
```

也可以使用：`pnpm add @grafana/plugin-e2e`、`yarn add @grafana/plugin-e2e`、`bun add @grafana/plugin-e2e`

## README

# Grafana / 插件 E2E

端到端的测试 Grafana 插件轻松.

**链接**

-   [`@grafana/plugin-e2e` 文档](https://grafana.com/developers/plugin-tools/e2e-test-a-plugin)

## 概览

`@grafana/plugin-e2e` 是专门为Grafana插件开发者设计的。 它延伸 [剧作家测试](https://github.com/microsoft/playwright/) 具有固定装置、模型和预期匹配者的能力,从而能够对Grafana插件进行跨多个版本的全面端到端测试。 这个软件包简化了测试过程,确保了您的插件坚固并兼容各种Grafana环境.

## 特征

-   **预定义的固定线 :** 为 Grafana 插件测试提供一套预定义的固定装置.
-   **自定义模型 :** 提供代表Grafana中的页面和组件的自定义模型,简化维护并创建可重复使用的代码来避免重复.
-   **期待匹配者 :** 包括一系列针对 Grafana 插件断言的预期匹配者, 帮助您更有效地验证插件行为 .
-   **版本兼容性 :** 保证您的插件在 Grafana 的多版本测试,保证兼容性和稳定性 .
-   **无障碍测试:** 与 Axe 整合,支持测试中的可配置无障碍测试,默认规则与 Grafana 一致 [WCAG2 导弹 AA 对](https://www.w3.org/TR/WCAG21/) 目标.
-   **与 Playwright 合并 :** 与Playwright测试框架无缝地融合,利用其强大的浏览器自动化能力.

## 开始吧

检查我们 [`Get started`](https://grafana.com/developers/plugin-tools/e2e-test-a-plugin/get-started) 关于如何安装、配置、写入测试和在CI中运行端到端测试的详细指南.

### 先决条件

-   您需要 Grafana 插件 [发展环境](https://grafana.com/developers/plugin-tools/set-up/)
-   节点.js 20+
-   游戏作家基础知识. 如果你以前没有和Playwright合作过 我们建议跟随 [开始](https://playwright.dev/docs/intro) 资料中的章节

#### 安装播放机

请参看 [剧作家文档](https://playwright.dev/docs/intro#installing-playwright) 用于指导如何安装. `@grafana/plugin-e2e` 扩展 Playwright API, 因此您需要拥有 `Playwright/test` 在您的插件的软件包.json文件中,将最小版本的1.41.2作为dev依赖性安装.

#### 配置剧作家

打开 Playwright 安装时生成的 Playwright 配置文件并粘贴以下配置.

```ts
import { dirname } from 'path';
import { defineConfig, devices } from '@playwright/test';
import type { PluginOptions } from '@grafana/plugin-e2e';

const pluginE2eAuth = `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`;

export default defineConfig<PluginOptions>({
  testDir: './tests', // change this to the directory that was chosen when installing Playwright
  reporter: 'html',
  use: {
    baseURL: process.env.GRAFANA_URL || 'http://localhost:3000',
  },
  projects: [
    {
      name: 'auth',
      testDir: pluginE2eAuth,
      testMatch: [/.*\.js/],
    },
    {
      name: 'run-tests',
      use: {
        ...devices['Desktop Chrome'],
        storageState: 'playwright/.auth/admin.json',
      },
      dependencies: ['auth'],
    },
  ],
});
```

### 写入测试

以下是一个基本例子,说明如何使用 `@grafana/plugin-e2e`数字 :

```ts
import { test, expect } from '@grafana/plugin-e2e';

test('data query should return values 10 and 20', async ({ panelEditPage, readProvisionedDataSource }) => {
  const ds = await readProvisionedDataSource({ fileName: 'datasources.yml' });
  await panelEditPage.datasource.set(ds.name);
  await panelEditPage.setVisualization('Table');
  await expect(panelEditPage.refreshPanel()).toBeOK();
  await expect(panelEditPage.panel.data).toContainText(['10', '20']);
});
```

### 运行测试

要进行测试,请使用以下命令:

```bash
npx playwright test
```

## 捐款

我们欢迎向@grafana/plugin-e2e捐款。 如果有兴趣的话,请读一下我们 [提供指南](https://npmcn.com/package/%40grafana/plugin-e2e/CONTRIBUTING.md)。 。 。 .

### 贷项

`@grafana/plugin-e2e` 没有我不可能 [剧作家测试](https://playwright.dev/)非常感谢微软和所有为这个惊人的工具献计献策的人!

## 常见问题

### @grafana/plugin-e2e 是什么？

端到端的测试 Grafana 插件轻松\.

### 如何安装 @grafana/plugin-e2e？

在项目目录运行 npm install @grafana/plugin-e2e，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@playwright/test（^1\.52\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @grafana/plugin-e2e 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @grafana/plugin-e2e 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @grafana/plugin-e2e 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=22。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @grafana/plugin-e2e 可以商用吗？

@grafana/plugin-e2e 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @grafana/plugin-e2e 的下载量有多少？

根据 npm 官方下载统计，@grafana/plugin-e2e 在 2026/10/17 – 2026/11/15 这 30 天内被下载 314,441 次，日均约 10,481 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @grafana/plugin-e2e 还在维护吗？

最新版本 4\.0\.0 发布于 2026/11/03（13 天前）；至今共发布 849 个版本，其中过去 12 个月发布了 238 个；首次发布于 2023/12/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

