@grafana/plugin-e2e

中文文档
4.0.0发布于 2026/11/03Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 31.4万

end-to-end test Grafana plugins with ease.

原始使用文档
文档目录8 节
  1. Overview
  2. Features
  3. Get started
  4. Prerequisites
  5. Writing Tests
  6. Running Tests
  7. Contributing
  8. Credits

Grafana / Plugin E2E

end-to-end test Grafana plugins with ease.

Links

Overview

@grafana/plugin-e2e is designed specifically for Grafana plugin developers. It extends Playwright test capabilities with fixtures, models, and expect matchers, enabling comprehensive end-to-end testing of Grafana plugins across multiple versions of Grafana. This package simplifies the testing process, ensuring your plugin is robust and compatible with various Grafana environments.

Features

  • Predefined Fixtures: Offers a set of predefined fixtures that are tailored for Grafana plugin testing.
  • Custom Models: Provides custom models that represent pages and components in Grafana, simplifying maintenance and creating reusable code to avoid repetition.
  • Expect Matchers: Includes a range of expect matchers that are specialized for Grafana plugin assertions, helping you validate plugin behavior more effectively.
  • Version Compatibility: Ensures that your plugin is tested across multiple versions of Grafana, guaranteeing compatibility and stability.
  • Accessibility testing: Integration with Axe to support configurable accessibility tests within your tests, with default rules aligned with Grafana's WCAG2AA target.
  • Integration with Playwright: Seamlessly integrates with the Playwright testing framework, leveraging its powerful browser automation capabilities.

Get started

Checkout our Get started guide for detailed instructions on how to install, configure, write tests and run your end-to-end tests in CI.

Prerequisites

  • You need to have a Grafana plugin development environment
  • Node.js 20+
  • Basic Knowledge of Playwright. If you have not worked with Playwright before, we recommend following the Getting started section in their documentation

Install Playwright

Please refer to the Playwright documentation for instruction on how to install. @grafana/plugin-e2e extends Playwright APIs, so you need to have Playwright/test with a minimum version of 1.41.2 installed as a dev dependency in the package.json file of your plugin.

Configure Playwright

Open the Playwright config file that was generated when Playwright was installed and paste the following configuration.

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'],
    },
  ],
});

Writing Tests

Here's a basic example of how to write an end-to-end test using @grafana/plugin-e2e:

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']);
});

Running Tests

To run your tests, use the following command:

npx playwright test

Contributing

We welcome contributions to @grafana/plugin-e2e. If you're interested in contributing, please read our contributing guidelines.

Credits

@grafana/plugin-e2e wouldn't be possible without Playwright test. Many thanks to Microsoft and all the people contributing to this amazing tool!

版本与发布记录

@grafana/plugin-e2e 共发布 849 个版本,首次发布于 2023/12/15;过去 12 个月发布了 238 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.0.0latest2026/11/0313 天前
3.15.42026/10/2819 天前
3.15.32026/10/2225 天前
3.15.22026/10/1928 天前
3.15.12026/10/131 个月前
3.15.02026/10/091 个月前

其他发布通道:canary → 3.8.1-canary.2678.26587359388.0。

关于 @grafana/plugin-e2e 的常见问题

@grafana/plugin-e2e 是什么?

end-to-end test Grafana plugins with ease.

如何安装 @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 和提交记录判断。