* refactor so server is created unless GRAFANA_URL is provided * update documentation * don't swallow errors from the server process
3.1 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-playwright/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:playwrightcommand starts a Grafana development server on port 3001 and runs the Playwright tests.You can run against an arbitrary instance by setting the
GRAFANA_URLenvironment variable:GRAFANA_URL=http://localhost:3000 yarn e2e:playwrightNote this will not start a development server, so you must ensure that Grafana is running and accessible at the specified URL.
-
You can provision the development server with the devenv dashboards, data sources, and apps.