Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.

Commit 30f9752

Browse files
authored
Add E2E Cypress testing (#27)
* Add E2E Cypress testing * Update README.md
1 parent fab3830 commit 30f9752

File tree

10 files changed

+1453
-105
lines changed

10 files changed

+1453
-105
lines changed

.github/workflows/e2e.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: E2E
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
tests:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Setup Node.js environment
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: '16'
22+
cache: 'yarn'
23+
24+
- name: Install dependencies
25+
run: yarn install --frozen-lockfile
26+
27+
- name: Development build
28+
run: yarn dev
29+
30+
- name: Start Grafana
31+
run: docker-compose up -d
32+
33+
- name: Run e2e tests
34+
run: yarn run e2e
35+
36+
- name: Stop Grafana
37+
run: docker-compose down
38+
39+
- uses: actions/upload-artifact@v3
40+
if: failure()
41+
with:
42+
path: |
43+
cypress/videos
44+
cypress/screenshots/actual

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ e2e-results/
2929
# Editor
3030
.idea
3131
.DS_Store
32+
33+
# Cypress
34+
cypress/report.json
35+
cypress/videos/
36+
cypress/screenshots/actual

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Update CI and Release Workflows to use setup-node cache (#24)
88
- Rebuild using 9.5.2 (#25)
99
- Add testing-library/react (#26)
10+
- Add E2E Cypress testing (#27)
1011

1112
## 2.2.0 (2023-02-16)
1213

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
![Dashboard](https://github.com/VolkovLabs/volkovlabs-abc-panel/raw/main/src/img/dashboard.png)
44

5-
[![Grafana 9](https://img.shields.io/badge/Grafana-9.3.6-orange)](https://www.grafana.com)
5+
[![Grafana 9](https://img.shields.io/badge/Grafana-9.5.2-orange)](https://www.grafana.com)
66
![CI](https://github.com/volkovlabs/volkovlabs-abc-panel/workflows/CI/badge.svg)
7+
![E2E](https://github.com/volkovlabs/volkovlabs-abc-panel/workflows/E2E/badge.svg)
78
[![codecov](https://codecov.io/gh/VolkovLabs/volkovlabs-abc-panel/branch/main/graph/badge.svg?token=0m6f0ktUar)](https://codecov.io/gh/VolkovLabs/volkovlabs-abc-panel)
89
[![CodeQL](https://github.com/VolkovLabs/volkovlabs-abc-panel/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/VolkovLabs/volkovlabs-abc-panel/actions/workflows/codeql-analysis.yml)
910

1011
## Introduction
1112

1213
The Abc panel is a template we created to streamline our development process and gladly share it with the Grafana community.
1314

14-
We created many Grafana panels to this moment. To make the creation process efficient, starting with a well-constructed template is always easier.
15+
To make the creation process efficient, starting with a well-constructed template is always easier.
1516

16-
Generate an application template with [https://github.com/VolkovLabs/volkovlabs-abc-panel/generate](https://github.com/VolkovLabs/volkovlabs-abc-panel/generate).
17+
Generate a template with [https://github.com/VolkovLabs/volkovlabs-abc-panel/generate](https://github.com/VolkovLabs/volkovlabs-abc-panel/generate).
1718

1819
## Requirements
1920

@@ -47,7 +48,7 @@ yarn sign
4748
yarn run start
4849
```
4950

50-
## Features
51+
## Highlights
5152

5253
- Use `docker-compose` to start the development environment with provisioned data source and a dashboard.
5354
- Provides unit test configuration.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { e2e } from '@grafana/e2e';
2+
import { TestIds } from '../../src/constants';
3+
4+
/**
5+
* Dashboard
6+
*/
7+
const json = require('../../provisioning/dashboards/panels.json');
8+
const testedPanel = json.panels[0];
9+
10+
/**
11+
* Selector
12+
*/
13+
const getTestIdSelector = (testId: string) => `[data-testid="${testId}"]`;
14+
15+
/**
16+
* Panel
17+
*/
18+
describe('Viewing an Abc panel', () => {
19+
beforeEach(() => {
20+
e2e.flows.openDashboard({
21+
uid: json.uid,
22+
});
23+
});
24+
25+
it('Should display a Hello World', () => {
26+
const currentPanel = e2e.components.Panels.Panel.title(testedPanel.title);
27+
currentPanel.should('be.visible');
28+
29+
/**
30+
* Root
31+
*/
32+
const chart = currentPanel.find(getTestIdSelector(TestIds.panel.root));
33+
chart.should('be.visible');
34+
35+
/**
36+
* Screenshot
37+
*/
38+
chart.screenshot(testedPanel.title);
39+
e2e().compareScreenshots({ name: testedPanel.title, threshold: 0.05 });
40+
});
41+
});
4.18 KB
Loading

cypress/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"types": ["cypress"]
4+
},
5+
"extends": "../tsconfig.json"
6+
}

docker-compose.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ services:
77
ports:
88
- 3000:3000/tcp
99
environment:
10-
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
11-
- GF_AUTH_ANONYMOUS_ENABLED=true
12-
- GF_AUTH_BASIC_ENABLED=false
13-
- GF_ENABLE_GZIP=true
1410
- GF_DEFAULT_APP_MODE=development
1511
- GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/etc/grafana/provisioning/dashboards/panels.json
1612
- GF_INSTALL_PLUGINS=marcusolsson-static-datasource
1713
volumes:
1814
- ./dist:/var/lib/grafana/plugins/volkovlabs-abc-panel
1915
- ./provisioning:/etc/grafana/provisioning
20-
# Uncomment to preserve Grafana configuration
21-
# - ./data:/var/lib/grafana

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"description": "Template to create a new Grafana panel plugin",
44
"devDependencies": {
55
"@grafana/data": "9.5.2",
6+
"@grafana/e2e": "^9.5.2",
7+
"@grafana/e2e-selectors": "^9.5.2",
68
"@grafana/runtime": "9.5.2",
79
"@grafana/toolkit": "9.5.2",
810
"@grafana/ui": "9.5.2",
@@ -19,6 +21,8 @@
1921
"scripts": {
2022
"build": "grafana-toolkit plugin:build --coverage",
2123
"dev": "grafana-toolkit plugin:dev",
24+
"e2e:update": "yarn cypress install && yarn grafana-e2e run --update-screenshots",
25+
"e2e": "yarn cypress install && yarn grafana-e2e run",
2226
"levitate": "npx @grafana/levitate@latest is-compatible --path src/module.ts --target @grafana/data,@grafana/runtime,@grafana/ui",
2327
"sign": "grafana-toolkit plugin:sign --rootUrls http://localhost:3000/",
2428
"start": "docker-compose pull && docker-compose up",

0 commit comments

Comments
 (0)