Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e smoke tests #464

Draft
wants to merge 5 commits into
base: sunker/remove-cypress
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: E2E tests
on:
pull_request:
schedule:
- cron: '0 11 * * *' #once a day at 11 UTC

permissions:
contents: read
id-token: write

jobs:
resolve-versions:
name: Resolve Grafana images
runs-on: ubuntu-latest
timeout-minutes: 3
outputs:
matrix: ${{ steps.resolve-versions.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve Grafana E2E versions
id: resolve-versions
uses: grafana/plugin-actions/e2e-version@main
with:
version-resolver-type: plugin-grafana-dependency
grafana-dependency: '>=8.5.0'

playwright-tests:
needs: resolve-versions
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
GRAFANA_IMAGE: ${{fromJson(needs.resolve-versions.outputs.matrix)}}
name: e2e ${{ matrix.GRAFANA_IMAGE.name }}@${{ matrix.GRAFANA_IMAGE.VERSION }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Install yarn dependencies
run: yarn install

- name: Install Mage
uses: magefile/mage-action@v3
with:
install-only: true

- name: Build binaries
run: mage -v build:linux

- name: Build frontend
run: yarn build

- name: Install Playwright Browsers
run: yarn playwright install --with-deps

- name: Start Grafana
run: |
docker compose pull
GRAFANA_VERSION=${{ matrix.GRAFANA_IMAGE.VERSION }} GRAFANA_IMAGE=${{ matrix.GRAFANA_IMAGE.NAME }} docker compose up -d

- name: Wait for grafana server
uses: grafana/plugin-actions/wait-for-grafana@main

- name: Run Playwright tests
id: run-tests
run: yarn playwright test

# Uncomment this step to upload the Playwright report to Github artifacts.
# If your repository is public, the report will be public on the Internet so beware not to expose sensitive information.
# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# if: ${{ (always() && steps.run-tests.outcome == 'success') || (failure() && steps.run-tests.outcome == 'failure') }}
# with:
# name: playwright-report-${{ matrix.GRAFANA_IMAGE.NAME }}-v${{ matrix.GRAFANA_IMAGE.VERSION }}-${{github.run_id}}
# path: playwright-report/
# retention-days: 30
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ e2e-results/
.idea

# End to End tests
provisioning
cypress/report.json
cypress/screenshots/actual
cypress/videos/

# vscode
.vscode
__debug_bin
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
1 change: 1 addition & 0 deletions cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"go.sum",
"mage_output_file.go",
"go.mod",
".gitignore"
],
"words": [
"athenaclientmock",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
"devDependencies": {
"@babel/core": "^7.25.8",
"@grafana/aws-sdk": "0.5.0",
"@grafana/eslint-config": "^8.0.0",
"@grafana/eslint-config": "^7.0.0",
"@grafana/plugin-e2e": "^1.12.1",
"@grafana/tsconfig": "^2.0.0",
"@playwright/test": "^1.48.2",
"@swc/core": "^1.7.36",
"@swc/helpers": "^0.5.13",
"@swc/jest": "^0.2.36",
Expand Down
57 changes: 57 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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`;

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* 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: [
{
name: 'auth',
testDir: pluginE2eAuth,
testMatch: [/.*\.js/],
},
{
name: 'run-tests',
use: {
...devices['Desktop Chrome'],
// @grafana/plugin-e2e writes the auth state to this file,
// the path should not be modified
storageState: 'playwright/.auth/admin.json',
},
dependencies: ['auth'],
},
],
});
40 changes: 40 additions & 0 deletions provisioning/datasources/aws-athena.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# config file version
apiVersion: 1

deleteDatasources:
- name: AWS Athena
orgId: 1
- name: AWS Athena assume role
orgId: 1

datasources:
- name: AWS Athena
type: grafana-athena-datasource
uid: P7DC3E4760CFAC4ACE
jsonData:
authType: keys
defaultRegion: us-east-2
catalog: AwsDataCatalog
database: some-db
workgroup: some-workgroup
secureJsonData:
accessKey: $ACCESS_KEY
secretKey: $SECRET_KEY
version: 1

- name: AWS Athena assume role
type: grafana-athena-datasource
uid: P7DC3E4760CFAC4AF
editable: true
enabled: true
jsonData:
authType: keys
defaultRegion: us-east-2
catalog: AwsDataCatalog
database: some-db
workgroup: some-workgroup
assumeRoleArn: arn:aws:iam::123:role/some-role
secureJsonData:
accessKey: $ACCESS_KEY
secretKey: $SECRET_KEY
version: 1
8 changes: 8 additions & 0 deletions tests/annotationsEditor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from '@grafana/plugin-e2e';
import { selectors } from '../src/tests/selectors';

test('should render annotations editor', async ({ annotationEditPage, page }) => {
const regionSelector = selectors.components.ConfigEditor.region.wrapper;
await annotationEditPage.datasource.set('AWS Athena');
await expect(page.getByTestId(regionSelector)).toBeVisible();
});
7 changes: 7 additions & 0 deletions tests/configEditor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test, expect } from '@grafana/plugin-e2e';

test('should render config editor', async ({ createDataSourceConfigPage, readProvisionedDataSource, page }) => {
const ds = await readProvisionedDataSource({ fileName: 'aws-athena.yaml', name: 'AWS Athena' });
await createDataSourceConfigPage({ type: ds.type });
await expect(page.getByTestId('connection-config')).toBeVisible();
});
8 changes: 8 additions & 0 deletions tests/queryEditor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test, expect } from '@grafana/plugin-e2e';
import { selectors } from '../src/tests/selectors';

test('should render query editor', async ({ panelEditPage }) => {
const regionSelector = selectors.components.ConfigEditor.region.wrapper;
await panelEditPage.datasource.set('AWS Athena');
await expect(panelEditPage.getQueryEditorRow('A').getByTestId(regionSelector)).toBeVisible();
});
8 changes: 8 additions & 0 deletions tests/variableEditor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from '@grafana/plugin-e2e';
import { selectors } from '../src/tests/selectors';

test('should render variable editor', async ({ variableEditPage, page }) => {
const regionSelector = selectors.components.ConfigEditor.region.wrapper;
await variableEditPage.datasource.set('AWS Athena');
await expect(page.getByTestId(regionSelector)).toBeVisible();
});
Loading
Loading