-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playwright tests for datasource plugins examples (#315)
* WIP * datasource-logs e2e tests * WIP http-datasource * WIP: backend mock server * Update integration tests action * Fix action * Update action * Use github output * Add e2e script * Stop mockserver after canary tests * e2e tests for streaming-backend-datasource * e2e tests for streaming-websocket-datasource * return datasource-http test back * fix ci * WIP test CI * fix CI build * WIP fix the build * skip queryeditpr tests for datasource-streamiing-backend-websocket * return datasource.go to iitial state * change id to testid for datasource-logs tests --------- Co-authored-by: Esteban Beltran <[email protected]>
- Loading branch information
Showing
32 changed files
with
8,130 additions
and
16,496 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { PluginOptions } from '@grafana/plugin-e2e'; | ||
import { defineConfig, devices } from '@playwright/test'; | ||
import { dirname } from 'node:path'; | ||
|
||
const pluginE2eAuth = `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig<PluginOptions>({ | ||
testDir: './tests', | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'html', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: 'http://localhost:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
// 1. Login to Grafana and store the cookie on disk for use in other tests. | ||
{ | ||
name: 'auth', | ||
testDir: pluginE2eAuth, | ||
testMatch: [/.*\.js/], | ||
}, | ||
// 2. Run tests in Google Chrome. Every test will start authenticated as admin user. | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/admin.json' }, | ||
dependencies: ['auth'], | ||
}, | ||
], | ||
}); |
15 changes: 15 additions & 0 deletions
15
examples/datasource-logs/provisioning/datasources/datasources.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: 1 | ||
|
||
datasources: | ||
- name: Datasource logs | ||
type: example-logs-datasource | ||
access: proxy | ||
isDefault: true | ||
orgId: 1 | ||
version: 1 | ||
editable: true | ||
jsonData: | ||
path: '/resources' | ||
defaultTimeField: | ||
secureJsonData: | ||
apiKey: 'api-key' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { test, expect } from '@grafana/plugin-e2e'; | ||
import { MyQuery } from '../src/types'; | ||
|
||
test('"Save & test" should display success alert box when config is valid', async ({ | ||
createDataSourceConfigPage, | ||
readProvisionedDataSource, | ||
page, | ||
selectors, | ||
}) => { | ||
const ds = await readProvisionedDataSource({ fileName: 'datasources.yml' }); | ||
const configPage = await createDataSourceConfigPage({ type: ds.type }); | ||
|
||
await configPage.getByGrafanaSelector(selectors.pages.DataSource.saveAndTest).click(); | ||
await expect(configPage).toHaveAlert('success'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { test, expect } from '@grafana/plugin-e2e'; | ||
|
||
test('logs should show certain values', async ({ page, selectors, panelEditPage, readProvisionedDataSource }) => { | ||
const ds = await readProvisionedDataSource({ fileName: 'datasources.yml' }); | ||
await panelEditPage.datasource.set(ds.name); | ||
await panelEditPage.setVisualization('Table'); | ||
await panelEditPage.getQueryEditorRow('A').getByTestId('query-editor-query-text', { exact: true }).fill('number'); | ||
await panelEditPage.getQueryEditorRow('A').getByTestId('query-editor-log-limit', { exact: true }).fill('10'); | ||
const refreshPanelButton = panelEditPage.getByGrafanaSelector(selectors.components.RefreshPicker.runButtonV2, { | ||
root: panelEditPage.getByGrafanaSelector(selectors.components.PanelEditor.General.content), | ||
}); | ||
await refreshPanelButton.click(); | ||
await expect(panelEditPage.panel.data).toContainText(['number=']); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.