Skip to content

Commit c6e1c09

Browse files
authored
Migrate E2E tests to Playwright (#358)
1 parent b20e562 commit c6e1c09

20 files changed

+430
-2467
lines changed

.github/dependabot.yml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ updates:
2121
schedule:
2222
interval: 'weekly'
2323
ignore:
24-
- dependency-name: '@grafana/e2e*'
2524
- dependency-name: 'react'
2625
update-types: ['version-update:semver-major']
2726
- dependency-name: 'react-dom'

.github/workflows/e2e-tests.yml

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: E2E tests
2+
on:
3+
pull_request:
4+
schedule:
5+
- cron: '0 11 * * *' #Run e2e tests once a day at 11 UTC
6+
7+
permissions:
8+
contents: read
9+
id-token: write
10+
11+
jobs:
12+
resolve-versions:
13+
name: Resolve Grafana images
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 3
16+
outputs:
17+
matrix: ${{ steps.resolve-versions.outputs.matrix }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
- name: Resolve Grafana E2E versions
22+
id: resolve-versions
23+
uses: grafana/plugin-actions/e2e-version@main
24+
with:
25+
version-resolver-type: version-support-policy
26+
27+
playwright-tests:
28+
needs: resolve-versions
29+
timeout-minutes: 60
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
GRAFANA_IMAGE: ${{fromJson(needs.resolve-versions.outputs.matrix)}}
34+
name: e2e ${{ matrix.GRAFANA_IMAGE.name }}@${{ matrix.GRAFANA_IMAGE.VERSION }}
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: Setup Node.js environment
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version-file: .nvmrc
43+
44+
- name: Install yarn dependencies
45+
run: yarn install
46+
47+
- name: Install Mage
48+
uses: magefile/mage-action@v3
49+
with:
50+
install-only: true
51+
52+
- name: Build binaries
53+
run: mage -v build:linux
54+
55+
- name: Build frontend
56+
run: yarn build
57+
58+
- name: Install Playwright Browsers
59+
run: yarn playwright install --with-deps
60+
61+
- name: Get secrets from vault
62+
id: get-secrets
63+
uses: grafana/shared-workflows/actions/get-vault-secrets@main
64+
with:
65+
repo_secrets: |
66+
ACCESS_KEY=e2e:accessKey
67+
SECRET_KEY=e2e:secretKey
68+
- name: Start Grafana
69+
run: |
70+
docker compose pull
71+
GRAFANA_VERSION=${{ matrix.GRAFANA_IMAGE.VERSION }} GRAFANA_IMAGE=${{ matrix.GRAFANA_IMAGE.NAME }} ACCESS_KEY=${{env.ACCESS_KEY}} SECRET_KEY=${{env.SECRET_KEY}} docker compose up -d
72+
- name: Wait for grafana server
73+
uses: grafana/plugin-actions/wait-for-grafana@main
74+
75+
- name: Run Playwright tests
76+
id: run-tests
77+
run: yarn playwright test
78+
79+
# Uncomment this step to upload the Playwright report to Github artifacts.
80+
# If your repository is public, the report will be public on the Internet so beware not to expose sensitive information.
81+
# - name: Upload artifacts
82+
# uses: actions/upload-artifact@v4
83+
# if: ${{ (always() && steps.run-tests.outcome == 'success') || (failure() && steps.run-tests.outcome == 'failure') }}
84+
# with:
85+
# name: playwright-report-${{ matrix.GRAFANA_IMAGE.NAME }}-v${{ matrix.GRAFANA_IMAGE.VERSION }}-${{github.run_id}}
86+
# path: playwright-report/
87+
# retention-days: 30

.gitignore

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
node_modules/
44
coverage/
55
ci/
6-
cypress/report.json
7-
cypress/screenshots/actual
8-
cypress/videos/
96
dist/
10-
provisioning
117
pkg/__debug_bin
128
yarn-error.log
9+
10+
# End to End tests
11+
provisioning/
12+
!provisioning/datasources/aws-timestream-e2e.yaml
13+
/test-results/
14+
/playwright-report/
15+
/blob-report/
16+
/playwright/.cache/
17+
/playwright/.auth/

CONTRIBUTING.md

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ Make sure you have the following dependencies installed first:
4646
mage -v
4747
```
4848

49+
## E2E Tests
50+
51+
1. `yarn playwright install --with-deps`
52+
1. `yarn server`
53+
1. `yarn e2e`
54+
4955
### Golden files
5056

5157
Golden files check that data frames are being generated correctly based on the Timestream API response. They have two parts, the json files represent the raw API response and the golden files represent the expected data frame. Both are generated in executor_test.go.

cspell.config.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
".github/**",
44
"node_modules/**",
55
"dist/**",
6-
"cypress/**",
76
"provisioning/**",
87
"src/dashboards/**",
98
"yarn.lock",
109
"go.mod",
1110
"go.sum",
1211
"mage_output_file.go",
1312
"pkg/timestream/testdata/**",
14-
"language.ts"
13+
"language.ts",
14+
"playwright*/**"
1515
],
1616
"words": [
1717
"awsds",
@@ -99,6 +99,7 @@
9999
"errorsource",
100100
"tibdex",
101101
"sqlds",
102-
"subresource"
102+
"subresource",
103+
"unroute"
103104
]
104105
}

cypress/integration/smoke.spec.ts

-105
This file was deleted.
Binary file not shown.

cypress/tsconfig.json

-9
This file was deleted.

docker-compose.yaml

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
version: '3.0'
2-
31
services:
42
grafana:
3+
user: root
54
container_name: 'grafana-timestream-datasource'
6-
platform: 'linux/amd64'
5+
76
build:
87
context: ./.config
98
args:
109
grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise}
11-
grafana_version: ${GRAFANA_VERSION:-10.3.6}
10+
grafana_version: ${GRAFANA_VERSION:-latest}
1211
ports:
1312
- 3000:3000/tcp
1413
volumes:
1514
- ./dist:/var/lib/grafana/plugins/grafana-timestream-datasource
1615
- ./provisioning:/etc/grafana/provisioning
16+
17+
environment:
18+
ACCESS_KEY: ${ACCESS_KEY}
19+
SECRET_KEY: ${SECRET_KEY}

package.json

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
"scripts": {
66
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
77
"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
8-
"e2e": "yarn exec cypress install && yarn exec grafana-e2e run",
9-
"e2e:open": "grafana-e2e open",
10-
"e2e:update": "yarn exec cypress install && yarn exec grafana-e2e run --update-screenshots",
8+
"e2e": "playwright test",
119
"lint": "eslint --cache .",
1210
"lint:fix": "yarn run lint --fix",
1311
"server": "docker compose up --build",
@@ -39,10 +37,10 @@
3937
"@eslint/eslintrc": "^3.2.0",
4038
"@eslint/js": "^9.18.0",
4139
"@grafana/aws-sdk": "0.6.0",
42-
"@grafana/e2e": "10.3.6",
43-
"@grafana/e2e-selectors": "10.3.6",
4440
"@grafana/eslint-config": "^8.0.0",
41+
"@grafana/plugin-e2e": "^1.16.3",
4542
"@grafana/tsconfig": "^2.0.0",
43+
"@playwright/test": "^1.50.0",
4644
"@stylistic/eslint-plugin-ts": "^2.13.0",
4745
"@swc/core": "^1.10.7",
4846
"@swc/helpers": "^0.5.15",
@@ -59,7 +57,6 @@
5957
"copy-webpack-plugin": "^12.0.2",
6058
"cspell": "^8.17.2",
6159
"css-loader": "^7.1.2",
62-
"cypress": "13.17.0",
6360
"eslint": "^9.18.0",
6461
"eslint-config-prettier": "^10.0.1",
6562
"eslint-plugin-deprecation": "^3.0.0",
@@ -92,7 +89,6 @@
9289
"webpack-virtual-modules": "^0.6.2"
9390
},
9491
"resolutions": {
95-
"@cypress/request": "3.0.1",
9692
"braces": "3.0.3",
9793
"cosmiconfig": "8.3.6",
9894
"debug": "4.3.5",

playwright.config.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { dirname } from 'path';
2+
import { defineConfig, devices } from '@playwright/test';
3+
import type { PluginOptions } from '@grafana/plugin-e2e';
4+
5+
const pluginE2eAuth = `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`;
6+
7+
/**
8+
* Read environment variables from file.
9+
* https://github.com/motdotla/dotenv
10+
*/
11+
// import dotenv from 'dotenv';
12+
// import path from 'path';
13+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
14+
15+
/**
16+
* See https://playwright.dev/docs/test-configuration.
17+
*/
18+
export default defineConfig<PluginOptions>({
19+
testDir: './tests',
20+
/* Run tests in files in parallel */
21+
fullyParallel: true,
22+
/* Fail the build on CI if you accidentally left test.only in the source code. */
23+
forbidOnly: !!process.env.CI,
24+
/* Retry on CI only */
25+
retries: process.env.CI ? 2 : 0,
26+
/* Opt out of parallel tests on CI. */
27+
workers: process.env.CI ? 1 : undefined,
28+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
29+
reporter: 'html',
30+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
31+
use: {
32+
/* Base URL to use in actions like `await page.goto('/')`. */
33+
baseURL: 'http://localhost:3000',
34+
35+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
36+
trace: 'on-first-retry',
37+
},
38+
39+
/* Configure projects for major browsers */
40+
projects: [
41+
{
42+
name: 'auth',
43+
testDir: pluginE2eAuth,
44+
testMatch: [/.*\.js/],
45+
},
46+
{
47+
name: 'run-tests',
48+
use: {
49+
...devices['Desktop Chrome'],
50+
// @grafana/plugin-e2e writes the auth state to this file,
51+
// the path should not be modified
52+
storageState: 'playwright/.auth/admin.json',
53+
},
54+
dependencies: ['auth'],
55+
},
56+
],
57+
});

0 commit comments

Comments
 (0)