From 07bbdddbee3d9b4c13879fdc3156a699abd48444 Mon Sep 17 00:00:00 2001 From: Chris Farhood Date: Tue, 5 May 2026 14:04:03 +0000 Subject: [PATCH] Add Playwright E2E test infrastructure to argocd-plugin - Add @playwright/test and playwright as devDependencies - Add e2e and e2e:headed scripts - Add playwright.config.ts - Add basic e2e test and auth.setup.ts This fixes the E2E workflow which was failing at the Playwright install step because the project lacked Playwright dependencies. Co-Authored-By: Paperclip --- e2e/auth.setup.ts | 16 ++++++++++++++++ e2e/basic.spec.ts | 16 ++++++++++++++++ package.json | 6 +++++- playwright.config.ts | 27 +++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 e2e/auth.setup.ts create mode 100644 e2e/basic.spec.ts create mode 100644 playwright.config.ts diff --git a/e2e/auth.setup.ts b/e2e/auth.setup.ts new file mode 100644 index 0000000..08652b2 --- /dev/null +++ b/e2e/auth.setup.ts @@ -0,0 +1,16 @@ +import { test as setup } from '@playwright/test'; +import { request } from '@playwright/test'; + +setup('authenticate', async ({ page }) => { + const token = process.env.HEADLAMP_TOKEN; + const url = process.env.HEADLAMP_URL; + + if (!token || !url) { + throw new Error('HEADLAMP_TOKEN and HEADLAMP_URL must be set'); + } + + await page.goto(url); + await page.evaluate((t) => { + localStorage.setItem('token', t); + }, token); +}); \ No newline at end of file diff --git a/e2e/basic.spec.ts b/e2e/basic.spec.ts new file mode 100644 index 0000000..85c90be --- /dev/null +++ b/e2e/basic.spec.ts @@ -0,0 +1,16 @@ +import { test, expect } from '@playwright/test'; + +test.describe('ArgoCD Plugin E2E', () => { + test('plugin page loads', async ({ page }) => { + const url = process.env.HEADLAMP_URL; + if (!url) { + throw new Error('HEADLAMP_URL must be set'); + } + + await page.goto(url); + await page.waitForLoadState('networkidle'); + + const title = await page.title(); + expect(title).toBeTruthy(); + }); +}); \ No newline at end of file diff --git a/package.json b/package.json index eaf7886..ad292b3 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,9 @@ "format": "prettier --write src/", "format:check": "prettier --check src/", "test": "vitest run", - "test:watch": "vitest" + "test:watch": "vitest", + "e2e": "playwright test", + "e2e:headed": "playwright test --headed" }, "peerDependencies": { "react": "^18.0.0", @@ -39,6 +41,7 @@ "devDependencies": { "@kinvolk/headlamp-plugin": "^0.13.0", "@mui/material": "^5.15.14", + "@playwright/test": "^1.58.2", "@testing-library/jest-dom": "^6.4.8", "@testing-library/react": "^16.0.0", "@testing-library/user-event": "^14.5.2", @@ -48,6 +51,7 @@ "@headlamp-k8s/eslint-config": "^0.6.0", "eslint": "^8.57.0", "jsdom": "^24.0.0", + "playwright": "^1.58.2", "prettier": "^2.8.8", "react": "^18.3.1", "react-dom": "^18.3.1", diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..6ee9428 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,27 @@ +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + testDir: './e2e', + timeout: 30_000, + expect: { timeout: 10_000 }, + fullyParallel: false, + forbidOnly: !!process.env.CI, + retries: process.env.CI ? 1 : 0, + reporter: 'list', + use: { + baseURL: process.env.HEADLAMP_URL || (() => { throw new Error('HEADLAMP_URL is required — run scripts/deploy-e2e-headlamp.sh first'); })(), + trace: 'on-first-retry', + screenshot: 'only-on-failure', + }, + projects: [ + { name: 'setup', testMatch: /auth\.setup\.ts/, timeout: 60_000 }, + { + name: 'chromium', + use: { + ...devices['Desktop Chrome'], + storageState: 'e2e/.auth/state.json', + }, + dependencies: ['setup'], + }, + ], +}); \ No newline at end of file