3.0 KiB
End-to-end tests for plugins
When end-to-end testing Grafana plugins, a best practice is to use the @grafana/plugin-e2e testing tool. The @grafana/plugin-e2e tool extends @playwright/test capabilities with relevant fixtures, models, and expect matchers. Use it to enable comprehensive end-to-end testing of Grafana plugins across multiple versions of Grafana.
Note: To learn more, refer to our documentation on plugin development and end-to-end plugin testing.
Add end-to-end tests for a core plugin
You can add Playwright end-to-end tests for plugins to the e2e/plugin-e2e directory.
-
Add a new directory that has the name as your plugin
here. This is the directory where your plugin tests will be kept. -
Playwright uses projects to logically group tests together. All tests in a project share the same configuration. In the Playwright config file, add a new project item. Make sure the
nameand thetestDirsubdirectory match the name of the directory that contains your plugin tests. Add'authenticate'to the list of dependencies and specify'playwright/.auth/admin.json'as the storage state to ensure that all tests in your project will start already authenticated as an admin user. If you want to use a different role for and perhaps test RBAC for some of your tests, refer to our documentation.{ name: 'mysql', testDir: path.join(testDirRoot, '/mysql'), use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/admin.json', }, dependencies: ['authenticate'], }, -
Update the CODEOWNERS file so that your team is owner of the tests in the directory you added in step 1.
Commands
-
yarn e2e:playwrightruns all Playwright tests. Optionally, you can provide the--project mysqlargument to run tests in a specific project.The
yarn e2e:playwrightscript assumes you have Grafana running onlocalhost:3000. You may change this with an environment variable:HOST=127.0.0.1 PORT=3001 yarn e2e:playwrightThe
yarn e2e:playwright:serverstarts a Grafana development server on port 3001 and runs the Playwright tests. -
You can provision the development server with the devenv dashboards, data sources, and apps.