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

Update E2E tests to use Docker #80

Merged
merged 3 commits into from
Jul 10, 2024
Merged
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ xml-server/

# Playwright tests
playwright.config.ts
test/panel.spec.ts
test/
9 changes: 3 additions & 6 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ jobs:
- name: Build
run: npm run build

- name: Setup playwright browser
run: npx playwright install --with-deps chromium

- name: Start Grafana
run: docker-compose up -d
run: docker compose --profile dev up -d

- name: Run e2e tests
run: npm run test:e2e
run: npm run test:e2e:docker

- name: Stop Grafana
run: docker-compose down
run: docker compose down

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
Expand Down
21 changes: 10 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,18 @@ jobs:
- name: Build
run: npm run build

- name: Sign plugin
run: npm run sign
env:
GRAFANA_ACCESS_POLICY_TOKEN: ${{ secrets.GRAFANA_ACCESS_POLICY_TOKEN }}

- name: Setup playwright browser
run: npx playwright install --with-deps chromium

- name: Start Grafana
run: docker-compose -f test/docker-compose.yml up -d
run: docker compose --profile main up -d

- name: Run e2e tests
run: npm run test:e2e
run: docker compose down

- name: Stop Grafana
run: docker-compose down
run: docker compose down

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 4.2.0 (IN PROGRESS)

### Features / Enhancements

- Updated E2E tests to use Docker (#80)

## 4.1.0 (2024-06-07)

### Features / Enhancements
Expand Down
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,44 @@ services:
volumes:
- ./dist:/var/lib/grafana/plugins/volkovlabs-rss-datasource
- ./provisioning:/etc/grafana/provisioning
profiles:
- dev

server:
container_name: xml-server
build:
context: ./xml-server
ports:
- 8001:8001
profiles:
- dev
- main

grafana-main:
container_name: grafana-main
image: grafana/grafana:main
ports:
- 3000:3000/tcp
environment:
- GF_DEFAULT_APP_MODE=development
- GF_USERS_DEFAULT_THEME=light
- GF_INSTALL_PLUGINS=marcusolsson-dynamictext-panel,yesoreyeram-infinity-datasource
volumes:
- ./dist:/var/lib/grafana/plugins/volkovlabs-rss-datasource
- ./provisioning:/etc/grafana/provisioning
profiles:
- main

test:
container_name: test-e2e
build:
context: .
dockerfile: test/Dockerfile
environment:
- GRAFANA_URL=http://127.0.0.1:3000
volumes:
- ./test:/app/test
- ./playwright-report:/app/playwright-report
network_mode: host
profiles:
- e2e
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@
"lint": "eslint --ignore-path ./.eslintignore --ext .js,.jsx,.ts,.tsx .",
"lint:fix": "eslint --fix --ignore-path ./.eslintignore --ext .js,.jsx,.ts,.tsx .",
"sign": "npx --yes @grafana/sign-plugin@latest",
"start": "docker-compose pull && docker-compose up",
"start:e2e": "docker-compose -f test/docker-compose.yml up",
"stop": "docker-compose down",
"stop:e2e": "docker-compose -f test/docker-compose.yml down",
"start": "docker compose pull grafana && docker compose --profile dev up",
"start:main": "docker compose pull grafana-main && docker compose --profile main up",
"stop": "docker compose down",
"test": "jest --watch --onlyChanged",
"test:e2e": "npx playwright test",
"test:e2e:docker": "docker compose --profile e2e up --exit-code-from test",
"test:ci": "jest --maxWorkers 4 --coverage",
"upgrade": "npm upgrade --save"
},
"version": "4.1.0"
"version": "4.2.0"
}
8 changes: 6 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const pluginE2eAuth = `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`;
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
/**
* Directory with tests
*/
testDir: './test',

/**
* Run tests in files in parallel
*/
Expand All @@ -26,7 +30,7 @@ export default defineConfig({
/**
* Reporter to use. See https://playwright.dev/docs/test-reporters
*/
reporter: 'html',
reporter: [['html', { open: 'never' }]],

/**
* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions.
Expand All @@ -35,7 +39,7 @@ export default defineConfig({
/**
* Base URL to use in actions like `await page.goto('/')`.
*/
baseURL: 'http://127.0.0.1:3000',
baseURL: process.env.GRAFANA_URL || 'http://localhost:3000',

/**
* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer.
Expand Down
17 changes: 17 additions & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Get the latest version of Playwright
FROM mcr.microsoft.com/playwright:focal

# Set the work directory for the application
WORKDIR app

# COPY the needed files to the app folder in Docker image
COPY .. .

# Install the dependencies in Node environment
RUN npm install --only=dev

# Install browsers
RUN npx playwright install --with-deps chromium

# Run tests
CMD ["npm", "run", "test:e2e"]
14 changes: 0 additions & 14 deletions test/docker-compose.yml

This file was deleted.

5 changes: 5 additions & 0 deletions test/panel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { test, expect } from '@grafana/plugin-e2e';

test.describe('RSS datasource', () => {
test('Check grafana version', async ({ grafanaVersion }) => {
console.log('Grafana version: ', grafanaVersion);
expect(grafanaVersion).toEqual(grafanaVersion);
});

test('Should display a Dynamic Text with Data Source', async ({ gotoDashboardPage, dashboardPage, page }) => {
/**
* Go To panels dashboard panels.json
Expand Down
Loading