diff --git a/.eslintignore b/.eslintignore index cd4c57f..0958598 100644 --- a/.eslintignore +++ b/.eslintignore @@ -12,4 +12,4 @@ xml-server/ # Playwright tests playwright.config.ts -test/panel.spec.ts +test/ diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 85da8d7..c52b602 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -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() }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b3f0744..cea40b9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9acfae4..eb2a88c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 9210b5d..5a379b1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,8 @@ services: volumes: - ./dist:/var/lib/grafana/plugins/volkovlabs-rss-datasource - ./provisioning:/etc/grafana/provisioning + profiles: + - dev server: container_name: xml-server @@ -21,3 +23,35 @@ services: 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 diff --git a/package.json b/package.json index 0bc8d71..fe188e0 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/playwright.config.ts b/playwright.config.ts index 19d75ed..0233990 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -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 */ @@ -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. @@ -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. diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..60553ca --- /dev/null +++ b/test/Dockerfile @@ -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"] diff --git a/test/docker-compose.yml b/test/docker-compose.yml deleted file mode 100644 index cb301e9..0000000 --- a/test/docker-compose.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: '3.4' - -services: - grafana: - container_name: grafana - image: grafana/grafana:main - ports: - - 3000:3000/tcp - environment: - - GF_USERS_DEFAULT_THEME=light - - GF_INSTALL_PLUGINS=marcusolsson-dynamictext-panel - volumes: - - ../dist:/var/lib/grafana/plugins/volkovlabs-rss-datasource - - ../provisioning:/etc/grafana/provisioning diff --git a/test/panel.spec.ts b/test/panel.spec.ts index b2cf1ef..68a9149 100644 --- a/test/panel.spec.ts +++ b/test/panel.spec.ts @@ -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