Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b4c2dc33e | ||
|
|
d08c77d8cc | ||
|
|
9083381f6f | ||
|
|
41a30cb66a | ||
|
|
7acd879523 | ||
|
|
1594617d0c | ||
|
|
d661b3f297 |
No files matched your search
@@ -39,6 +39,17 @@ Frontend runs at `http://localhost:3000`.
|
||||
- **Type-Level Contract Testing**: When defining shared TypeScript interfaces/contracts (e.g., in `wwv-plugin-sdk`), you MUST use `expectTypeOf` from `vitest` to assert the actual contract shapes at compile-time instead of writing literal-value identity runtime assertions. You must also enforce `@ts-expect-error` negative type tests to ensure missing or invalid fields trigger compilation errors.
|
||||
- **Key test files**: `rateLimit.test.ts`, `edition.test.ts`, `demoAdmin.test.ts`, `DeclarativePlugin.test.ts`, `cors.test.ts`, `repository.test.ts`, `marketplaceToken.test.ts`
|
||||
|
||||
### E2E Testing (Playwright)
|
||||
|
||||
WorldWideView uses Playwright for End-to-End browser testing to verify the complete UI integration including NextAuth.
|
||||
|
||||
- **Run**: `pnpm run test:e2e` (Ensure your database is running before executing)
|
||||
- **Auth Bypass**: Playwright uses a `global.setup.ts` to directly insert a test user into the database and simulate a UI login to capture a `storageState.json` cookie file. This allows all tests to run pre-authenticated without bypassing production security logic.
|
||||
- **Database Access in Setup**: Because Playwright setup scripts run in a vanilla Node context, importing Next.js backend utilities like `src/lib/db.ts` will crash with `next/headers` resolution errors. You MUST instantiate `PrismaClient` directly using `@prisma/adapter-pg` in any Playwright `setup` or `teardown` scripts.
|
||||
- **Component Synchronization**: Do not use arbitrary timeouts. Tests MUST wait for the application boot sequence to finish by waiting for the `[data-testid="app-ready"]` marker on the `AppShell` to be attached.
|
||||
- **Stable Selectors**: Always use `data-testid` properties (e.g. `data-testid="panel-toggle-left"`) for interacting with UI components in E2E tests rather than fragile CSS classes or dynamic text.
|
||||
- **Worktree Port Conflicts**: If you are testing in a git worktree, configure `playwright.config.ts` to spawn the `webServer` on an alternative port (e.g. `3001`) to avoid colliding with other running worktrees.
|
||||
|
||||
## Security Headers
|
||||
|
||||
Configured in `next.config.ts` `headers()`:
|
||||
@@ -248,6 +259,9 @@ The production Coolify instance runs on a local server at `192.168.68.64`. Direc
|
||||
1. Push to `silvertakana/worldwideview`
|
||||
2. Coolify webhook triggers → automated BuildKit deployment on the host server.
|
||||
|
||||
**GitHub Actions Workflows:**
|
||||
- **Minimal Permissions:** CodeQL and GitHub security best practices dictate that `GITHUB_TOKEN` permissions should always be explicitly constrained. When creating or modifying `.github/workflows/*.yml` files, you MUST always include an explicit `permissions` block (e.g., `permissions: { contents: read }` or similar required scopes) at the top level or job level to adhere to the principle of least privilege.
|
||||
|
||||
**Coolify Deployment Rules & Gotchas (The "Redis 500k" Rule):**
|
||||
- **Coolify Pulls from GitHub:** Coolify does *not* deploy your local workspace files. It strictly clones the repository from GitHub.
|
||||
- **Push Before You Deploy:** If you make a critical infrastructure or optimization fix locally (e.g., swapping a massive `HSET` pipeline for a compressed 5-min throttled `setLiveSnapshot`), you **must** `git commit` and `git push` those changes to the `main` branch before triggering a Coolify deployment.
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
---
|
||||
trigger: testing
|
||||
description: Guidelines and architecture for the Playwright End-to-End (E2E) testing infrastructure.
|
||||
---
|
||||
|
||||
# E2E Testing Infrastructure
|
||||
|
||||
The WorldWideView project uses **Playwright** for end-to-end (E2E) testing. This document outlines the boundaries, architectural decisions, and conventions required when authoring or modifying E2E tests.
|
||||
|
||||
## 1. Resource Constraints & Parallelism
|
||||
- **Worker Limits:** The Playwright configuration (`playwright.config.ts`) is strictly limited to a maximum of **2 workers**.
|
||||
- **Reasoning:** Running Next.js compilation alongside a heavy Prisma connection pool inside multiple parallel test workers will lead to database connection exhaustion and resource contention on CI and local environments. Do not increase the worker count beyond 2 without careful consideration of the database pool limits.
|
||||
|
||||
## 2. Test User Lifecycle
|
||||
E2E tests require an authenticated user to access core application features. We manage this test user securely to ensure the environment stays pristine:
|
||||
|
||||
- **Setup (`tests/global.setup.ts`):** Before tests run, the global setup script defensively deletes any existing test user (`[email protected]`) and creates a fresh instance with the `ADMIN` role. It then performs a UI login to capture the authentication state, which is shared across all test files.
|
||||
- **Teardown (`tests/global.teardown.ts`):** After the entire test suite completes (regardless of success or failure), the global teardown script runs and completely purges the test user from the database.
|
||||
- **Safety:** Do not use `[email protected]` for manual testing. It is volatile and intended exclusively for the CI test runner.
|
||||
|
||||
## 3. UI Interaction Conventions
|
||||
- **Strict Selector Usage:** Always use `data-testid` selectors (e.g., `getByTestId('panel-toggle-left')`) for DOM interactions. Do not rely on brittle CSS classes or deep DOM structures. If a `data-testid` is missing from an element you need to test, add it to the React component first.
|
||||
- **Dialog Interception:** WorldWideView relies on heavy frontend plugin discovery and dynamic rendering. For example, the `UnverifiedPluginBatchDialog` may unexpectedly appear and block UI interactions in a fresh browser context.
|
||||
- *Mitigation:* Ensure your test suites either explicitly handle these dialogs (e.g., in a `beforeEach` block) or inject mock plugins that bypass the verification flow entirely.
|
||||
|
||||
## 4. Mock Plugins
|
||||
- **Injection:** We inject safe, deterministic mock plugins into the database during the `global.setup.ts` phase to test the core rendering pipeline without relying on external APIs.
|
||||
- **Location:** Mock plugin configurations and manifests are stored in `public/e2e-fixtures/`. When modifying the rendering engine, ensure you also update the mock plugin (`public/e2e-fixtures/mock-plugin.js`) to reflect any changes in the Plugin SDK capabilities.
|
||||
|
||||
## 5. Security Permissions
|
||||
- When integrating Playwright tests into GitHub Actions (e.g., `.github/workflows/playwright.yml`), you MUST include an explicit permissions block (e.g., `permissions: { contents: read }`) to adhere to CodeQL and least-privilege scoping rules.
|
||||
|
||||
> [!WARNING]
|
||||
> If you encounter flaky tests or `ECONNREFUSED` errors during Playwright runs, check if the local Next.js dev server or the Docker engine stack is competing for ports (e.g., port 5432 or 3000). Ensure `pnpm run dev:backends` is running and stable before launching the test suite.
|
||||
@@ -0,0 +1,42 @@
|
||||
name: Playwright Tests
|
||||
on:
|
||||
push:
|
||||
branches: [ main, master ]
|
||||
pull_request:
|
||||
branches: [ main, master ]
|
||||
permissions:
|
||||
contents: read
|
||||
jobs:
|
||||
test:
|
||||
timeout-minutes: 60
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: pnpm/action-setup@v3
|
||||
with:
|
||||
version: 9.15.4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: 'pnpm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Install Playwright Browsers
|
||||
run: pnpm exec playwright install --with-deps
|
||||
|
||||
- name: Run Project Setup
|
||||
run: pnpm run setup
|
||||
|
||||
- name: Run Playwright tests
|
||||
run: pnpm test:e2e
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: ${{ !cancelled() }}
|
||||
with:
|
||||
name: playwright-report
|
||||
path: playwright-report/
|
||||
retention-days: 30
|
||||
+6
-1
@@ -127,4 +127,9 @@ skills-lock.json
|
||||
/wwv-seeders/
|
||||
/wwv-seeders-private/
|
||||
/wwv-test/
|
||||
worldwideview.code-workspace
|
||||
worldwideview.code-workspace
|
||||
|
||||
# Playwright
|
||||
/playwright-report/
|
||||
/test-results/
|
||||
/playwright/.auth/
|
||||
@@ -155,6 +155,7 @@ Read the relevant rule file when working in that domain:
|
||||
| `continuous-improvement` | When to create/update rules, skills, or workflows | `.agents/rules/continuous-improvement.md` |
|
||||
| `context-and-memory` | How to orient and maintain project context between sessions | `.agents/rules/context-and-memory.md` |
|
||||
| `troubleshooting-and-debugging` | Resolving plugin latency, namespace collisions, or deployment issues | `.agents/rules/troubleshooting-and-debugging.md` |
|
||||
| `e2e-testing` | Guidelines and architecture for the Playwright End-to-End (E2E) testing infrastructure | `.agents/rules/e2e-testing.md` |
|
||||
|
||||
---
|
||||
|
||||
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "worldwideview",
|
||||
"version": "2.14.1",
|
||||
"version": "2.14.4",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"packageManager": "[email protected]",
|
||||
@@ -18,6 +18,7 @@
|
||||
"build": "next build --webpack",
|
||||
"start": "next start",
|
||||
"test": "vitest run",
|
||||
"test:e2e": "playwright test",
|
||||
"test:mutate": "stryker run",
|
||||
"lint": "eslint .",
|
||||
"db:reset": "npx prisma migrate reset --force",
|
||||
@@ -60,6 +61,7 @@
|
||||
"zustand": "^5.0.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.60.0",
|
||||
"@stryker-mutator/core": "^9.6.1",
|
||||
"@stryker-mutator/vitest-runner": "^9.6.1",
|
||||
"@testing-library/dom": "^10.4.1",
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* See https://playwright.dev/docs/test-configuration.
|
||||
*/
|
||||
export default defineConfig({
|
||||
timeout: 60000,
|
||||
expect: {
|
||||
timeout: 10000,
|
||||
},
|
||||
globalSetup: './tests/global.setup.ts',
|
||||
globalTeardown: './tests/global.teardown.ts',
|
||||
testDir: './tests',
|
||||
/* Run tests in files in parallel */
|
||||
fullyParallel: true,
|
||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||
forbidOnly: !!process.env.CI,
|
||||
/* Retry on CI only */
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
/* Opt out of parallel tests on CI. Restrict to 2 locally to prevent Next.js compilation overload. */
|
||||
workers: process.env.CI ? 1 : 2,
|
||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||
reporter: 'html',
|
||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||
use: {
|
||||
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||
baseURL: 'http://localhost:3001',
|
||||
|
||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||
trace: 'on-first-retry',
|
||||
},
|
||||
|
||||
/* Configure projects for major browsers */
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
storageState: 'playwright/.auth/user.json'
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
/* Run your local dev server before starting the tests */
|
||||
webServer: {
|
||||
command: 'pnpm dev',
|
||||
env: { PORT: '3001' },
|
||||
url: 'http://localhost:3001',
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120 * 1000,
|
||||
},
|
||||
});
|
||||
Generated
+50
-11
@@ -32,7 +32,7 @@ importers:
|
||||
version: 7.8.0
|
||||
'@sentry/nextjs':
|
||||
specifier: ^10.52.0
|
||||
version: 10.52.0(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected](@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))
|
||||
version: 10.52.0(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))
|
||||
'@supabase/supabase-js':
|
||||
specifier: ^2.105.4
|
||||
version: 2.105.4
|
||||
@@ -41,7 +41,7 @@ importers:
|
||||
version: 8.20.0
|
||||
'@vercel/analytics':
|
||||
specifier: ^1.6.1
|
||||
version: 1.6.1([email protected](@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected])
|
||||
version: 1.6.1([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])
|
||||
'@worldwideview/wwv-plugin-sdk':
|
||||
specifier: workspace:*
|
||||
version: link:packages/wwv-plugin-sdk
|
||||
@@ -68,10 +68,10 @@ importers:
|
||||
version: 1.14.0([email protected])
|
||||
next:
|
||||
specifier: 16.2.6
|
||||
version: 16.2.6(@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected])
|
||||
version: 16.2.6(@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected])
|
||||
next-auth:
|
||||
specifier: ^5.0.0-beta.30
|
||||
version: 5.0.0-beta.30([email protected](@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected])
|
||||
version: 5.0.0-beta.30([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])
|
||||
openid-client:
|
||||
specifier: ^6.8.4
|
||||
version: 6.8.4
|
||||
@@ -115,6 +115,9 @@ importers:
|
||||
specifier: ^5.0.13
|
||||
version: 5.0.13(@types/[email protected])([email protected])([email protected]([email protected]))
|
||||
devDependencies:
|
||||
'@playwright/test':
|
||||
specifier: ^1.60.0
|
||||
version: 1.60.0
|
||||
'@stryker-mutator/core':
|
||||
specifier: ^9.6.1
|
||||
version: 9.6.1(@types/[email protected])
|
||||
@@ -1350,6 +1353,11 @@ packages:
|
||||
'@panva/[email protected]':
|
||||
resolution: {integrity: sha512-6oclG6Y3PiDFcoyk8srjLfVKyMfVCKJ27JwNPViuXziFpmdz+MZnZN/aKY0JGXgYuO/VghU0jcOAZgWXZ1Dmrw==}
|
||||
|
||||
'@playwright/[email protected]':
|
||||
resolution: {integrity: sha512-O71yZIbAh/PxDMNGns37GHBIfrVkEVyn+AXyIa5dOTfb4/xNvRWV+Vv/NMbNCtODB/pO7vLlF2OTmMVLhmr7Ag==}
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
|
||||
'@prisma/[email protected]':
|
||||
resolution: {integrity: sha512-ygb3UkerK3v8MDpXVgCISdRNDozpxh6+JVJgiIGbSr5KBgz10LLf5ejUskPGoXlsIjxsOu6nuy1JVQr2EKGSlg==}
|
||||
|
||||
@@ -3308,6 +3316,11 @@ packages:
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==}
|
||||
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
|
||||
os: [darwin]
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==}
|
||||
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
|
||||
@@ -4339,6 +4352,16 @@ packages:
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-z/T8hJGaTkHT9vdXgWdOgF37eB1FV7/j52VXQZ2lgEhpru9oT8TaUWIxp6GoxTnhPBM4X6nSbpkAHrT7UTjUKg==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-9bW6zvX/m0lEbgTKJ6YppOKx8H3VOPBMOCFh2irXFOT4BbHgrx5hPjwJYLT40Lu+4qtD36qKc/Hn56StUW57IA==}
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-hheHdokM8cdqCb0lcE3s+zT4t4W+vvjpGxsZlDnikarzx8tSzMebh3UiFtgqwFwnTnjYQcsyMF8ei2mCO/tpeA==}
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -6468,6 +6491,10 @@ snapshots:
|
||||
|
||||
'@panva/[email protected]': {}
|
||||
|
||||
'@playwright/[email protected]':
|
||||
dependencies:
|
||||
playwright: 1.60.0
|
||||
|
||||
'@prisma/[email protected]':
|
||||
dependencies:
|
||||
'@prisma/driver-adapter-utils': 7.8.0
|
||||
@@ -6869,7 +6896,7 @@ snapshots:
|
||||
|
||||
'@sentry/[email protected]': {}
|
||||
|
||||
'@sentry/[email protected](@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected](@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))':
|
||||
'@sentry/[email protected](@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))':
|
||||
dependencies:
|
||||
'@opentelemetry/api': 1.9.1
|
||||
'@opentelemetry/semantic-conventions': 1.40.0
|
||||
@@ -6882,7 +6909,7 @@ snapshots:
|
||||
'@sentry/react': 10.52.0([email protected])
|
||||
'@sentry/vercel-edge': 10.52.0
|
||||
'@sentry/webpack-plugin': 5.2.1([email protected]([email protected]))
|
||||
next: 16.2.6(@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected])
|
||||
next: 16.2.6(@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected])
|
||||
rollup: 4.60.3
|
||||
stacktrace-parser: 0.1.11
|
||||
transitivePeerDependencies:
|
||||
@@ -7410,9 +7437,9 @@ snapshots:
|
||||
'@unrs/[email protected]':
|
||||
optional: true
|
||||
|
||||
'@vercel/[email protected]([email protected](@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected])':
|
||||
'@vercel/[email protected]([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])':
|
||||
optionalDependencies:
|
||||
next: 16.2.6(@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected])
|
||||
next: 16.2.6(@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected])
|
||||
react: 19.2.6
|
||||
|
||||
'@vimeo/[email protected]':
|
||||
@@ -8713,6 +8740,9 @@ snapshots:
|
||||
[email protected]:
|
||||
optional: true
|
||||
|
||||
[email protected]:
|
||||
optional: true
|
||||
|
||||
[email protected]:
|
||||
optional: true
|
||||
|
||||
@@ -9465,13 +9495,13 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]([email protected](@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected]):
|
||||
[email protected]([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected]):
|
||||
dependencies:
|
||||
'@auth/core': 0.41.0
|
||||
next: 16.2.6(@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected])
|
||||
next: 16.2.6(@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected])
|
||||
react: 19.2.6
|
||||
|
||||
[email protected](@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected]):
|
||||
[email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]):
|
||||
dependencies:
|
||||
'@next/env': 16.2.6
|
||||
'@swc/helpers': 0.5.15
|
||||
@@ -9491,6 +9521,7 @@ snapshots:
|
||||
'@next/swc-win32-arm64-msvc': 16.2.6
|
||||
'@next/swc-win32-x64-msvc': 16.2.6
|
||||
'@opentelemetry/api': 1.9.1
|
||||
'@playwright/test': 1.60.0
|
||||
sharp: 0.34.5
|
||||
transitivePeerDependencies:
|
||||
- '@babel/core'
|
||||
@@ -9711,6 +9742,14 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- react
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
playwright-core: 1.60.0
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.2
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]:
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"id": "e2e-mock-plugin",
|
||||
"name": "E2E Mock Plugin",
|
||||
"version": "1.0.0",
|
||||
"description": "A static mock plugin used for Playwright E2E tests.",
|
||||
"author": "WorldWideView Automated Tests",
|
||||
"type": "extension",
|
||||
"format": "bundle",
|
||||
"trust": "unverified",
|
||||
"entry": "/e2e-fixtures/mock-plugin.js",
|
||||
"capabilities": ["ui:sidebar"],
|
||||
"category": "utility",
|
||||
"extends": ["sidebar"]
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// This file is loaded by the plugin manager in the E2E test environment.
|
||||
// It bypasses the build step and directly uses the host's injected React instance.
|
||||
|
||||
export default {
|
||||
// Basic plugin metadata required by WorldPlugin interface
|
||||
id: "e2e-mock-plugin",
|
||||
name: "E2E Mock Plugin",
|
||||
description: "A mock plugin for E2E testing.",
|
||||
icon: "data:image/svg+xml;base64,PHN2Zz48L3N2Zz4=", // Empty SVG as fallback
|
||||
category: "custom",
|
||||
version: "1.0.0",
|
||||
|
||||
// Lifecycle
|
||||
initialize: async (ctx) => {
|
||||
console.log("[e2e-mock-plugin] Initialized");
|
||||
},
|
||||
destroy: () => {
|
||||
console.log("[e2e-mock-plugin] Destroyed");
|
||||
},
|
||||
|
||||
// Data
|
||||
fetch: async (timeRange) => {
|
||||
return []; // No entities for this mock
|
||||
},
|
||||
getPollingInterval: () => {
|
||||
return 60000;
|
||||
},
|
||||
|
||||
// Rendering
|
||||
getLayerConfig: () => {
|
||||
return {
|
||||
color: "#00FF00",
|
||||
clusterEnabled: false,
|
||||
clusterDistance: 50
|
||||
};
|
||||
},
|
||||
renderEntity: (entity) => {
|
||||
return {
|
||||
type: "point",
|
||||
color: "#00FF00",
|
||||
size: 5
|
||||
};
|
||||
},
|
||||
|
||||
// Provide a UI component using the host's React instance
|
||||
getSidebarComponent: () => {
|
||||
// Access React from the global host object injected by WorldWideView
|
||||
const React = globalThis.__WWV_HOST__.React;
|
||||
|
||||
if (!React) {
|
||||
console.error("[e2e-mock-plugin] Failed to resolve React from __WWV_HOST__");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return a component function, not just an element
|
||||
return function MockSidebar() {
|
||||
return React.createElement(
|
||||
"div",
|
||||
{ "data-testid": "e2e-mock-panel", style: { padding: "16px", background: "rgba(0, 255, 0, 0.1)", border: "1px solid green" } },
|
||||
"Mock Panel (E2E Test)"
|
||||
);
|
||||
};
|
||||
}
|
||||
};
|
||||
+2
-2
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import concurrently from 'concurrently';
|
||||
import kill from 'tree-kill';
|
||||
import kill from 'tree-kill/index.js';
|
||||
import { execSync } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import process from 'process';
|
||||
@@ -40,7 +40,7 @@ const teardownDbOnExit = process.env.WWV_TEARDOWN_DB_ON_EXIT === 'true' || proce
|
||||
const { result, commands } = concurrently(
|
||||
[
|
||||
{ command: 'pnpm run dev:plugins', name: 'plugins', prefixColor: 'magenta' },
|
||||
{ command: 'next dev', name: 'next', prefixColor: 'blue' }
|
||||
{ command: 'pnpm exec next dev', name: 'next', prefixColor: 'blue' }
|
||||
],
|
||||
{
|
||||
prefix: 'name',
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
const dbUrl = process.env.DATABASE_URL || '';
|
||||
|
||||
if (!dbUrl) {
|
||||
console.error("❌ ERROR: DATABASE_URL is missing.");
|
||||
console.error(" Did you forget to run 'pnpm run setup' to generate your .env file?");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const isLocal = dbUrl.includes('localhost') || dbUrl.includes('127.0.0.1') || dbUrl.includes('host.docker.internal') || dbUrl.includes('postgres:postgres@db:5432');
|
||||
|
||||
if (!isLocal) {
|
||||
|
||||
@@ -169,7 +169,7 @@ export function AppShell() {
|
||||
].filter(Boolean).join(" ");
|
||||
|
||||
return (
|
||||
<div className={rootClasses}>
|
||||
<div className={rootClasses} data-testid={!isBooting ? "app-ready" : undefined}>
|
||||
<BootOverlay visible={boot.phase === "loading"} />
|
||||
|
||||
<div className="app-shell__globe">
|
||||
|
||||
@@ -48,6 +48,7 @@ export function PanelToggleArrows() {
|
||||
className={`panel-toggle-btn panel-toggle-btn--left ${isLeftOpen ? "panel-toggle-btn--open" : ""} ${isMobile ? "panel-toggle-btn--mobile" : ""}`}
|
||||
onClick={handleLeftToggle}
|
||||
title="Toggle Layers Panel"
|
||||
data-testid="panel-toggle-left"
|
||||
>
|
||||
{isLeftOpen ? <ChevronLeft size={24} /> : <ChevronRight size={24} />}
|
||||
</button>
|
||||
@@ -57,6 +58,7 @@ export function PanelToggleArrows() {
|
||||
className={`panel-toggle-btn panel-toggle-btn--right ${isRightOpen ? "panel-toggle-btn--open" : ""} ${isMobile ? "panel-toggle-btn--mobile" : ""} ${isMobile && mobileRightPanelGlow ? "panel-toggle-btn--glow" : ""}`}
|
||||
onClick={handleRightToggle}
|
||||
title="Toggle Data Configuration"
|
||||
data-testid="panel-toggle-right"
|
||||
>
|
||||
{isRightOpen ? <ChevronRight size={24} /> : <ChevronLeft size={24} />}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test('has title and boots app completely', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
|
||||
// Expect a title "to contain" a substring.
|
||||
await expect(page).toHaveTitle(/WorldWideView/i);
|
||||
|
||||
// Wait for the boot sequence to finish and plugins to load
|
||||
await page.waitForSelector('[data-testid="app-ready"]', { state: 'attached', timeout: 30000 });
|
||||
|
||||
// Verify that the element is actually present
|
||||
const appReady = await page.locator('[data-testid="app-ready"]');
|
||||
await expect(appReady).toBeAttached();
|
||||
});
|
||||
@@ -0,0 +1,140 @@
|
||||
import { chromium, type FullConfig } from '@playwright/test';
|
||||
import { PrismaClient } from '../src/generated/prisma/index.js';
|
||||
import { PrismaPg } from "@prisma/adapter-pg";
|
||||
import { Pool } from "pg";
|
||||
import bcrypt from 'bcryptjs';
|
||||
import crypto from 'crypto';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export const TEST_USER_EMAIL = '[email protected]';
|
||||
|
||||
function loadEnv() {
|
||||
try {
|
||||
const envPath = path.resolve(process.cwd(), '.env');
|
||||
if (fs.existsSync(envPath)) {
|
||||
const content = fs.readFileSync(envPath, 'utf8');
|
||||
content.split('\n').forEach(line => {
|
||||
const match = line.match(/^\s*([\w.-]+)\s*=\s*(.*)?\s*$/);
|
||||
if (match) {
|
||||
const key = match[1];
|
||||
let value = match[2] || '';
|
||||
if (value.startsWith('"') && value.endsWith('"')) value = value.slice(1, -1);
|
||||
if (value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
||||
process.env[key] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore read errors
|
||||
}
|
||||
}
|
||||
|
||||
async function globalSetup(config: FullConfig) {
|
||||
loadEnv();
|
||||
const { storageState, baseURL } = config.projects[0].use;
|
||||
|
||||
if (!baseURL) {
|
||||
throw new Error('baseURL is not defined in Playwright config');
|
||||
}
|
||||
|
||||
const pool = new Pool({ connectionString: process.env.DATABASE_URL || "postgresql://postgres:[email protected]:5432/worldwideview?schema=public" });
|
||||
const adapter = new PrismaPg(pool);
|
||||
const prisma = new PrismaClient({ adapter });
|
||||
|
||||
try {
|
||||
// 1. Retry/poll mechanism for database connectivity
|
||||
let dbConnected = false;
|
||||
for (let i = 0; i < 5; i++) {
|
||||
try {
|
||||
await prisma.$queryRaw`SELECT 1`;
|
||||
dbConnected = true;
|
||||
break;
|
||||
} catch (e) {
|
||||
console.log(`[Setup] Waiting for database (attempt ${i + 1}/5)...`);
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
}
|
||||
}
|
||||
|
||||
if (!dbConnected) {
|
||||
throw new Error('[Setup] Could not connect to database after 5 attempts.');
|
||||
}
|
||||
|
||||
// 2. Generate a secure random password and hash it
|
||||
const password = crypto.randomUUID();
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
|
||||
// 2.5 Defensive Cleanup for Mock Plugin
|
||||
console.log(`[Setup] Cleaning up any existing mock plugins...`);
|
||||
await prisma.installedPlugin.deleteMany({
|
||||
where: { pluginId: 'e2e-mock-plugin' }
|
||||
});
|
||||
|
||||
// 3. Clean up any orphaned user and create the test user
|
||||
console.log(`[Setup] Upserting test user: ${TEST_USER_EMAIL}`);
|
||||
await prisma.user.deleteMany({
|
||||
where: { email: TEST_USER_EMAIL }
|
||||
});
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
email: TEST_USER_EMAIL,
|
||||
name: 'Playwright E2E Tester',
|
||||
hashedPassword: hashedPassword,
|
||||
role: 'ADMIN',
|
||||
},
|
||||
});
|
||||
|
||||
// 3.5 Inject the mock plugin for the test environment
|
||||
console.log(`[Setup] Injecting mock plugin into database...`);
|
||||
const manifestPath = path.join(process.cwd(), 'public', 'e2e-fixtures', 'manifest.json');
|
||||
const manifestStr = fs.readFileSync(manifestPath, 'utf-8');
|
||||
await prisma.installedPlugin.create({
|
||||
data: {
|
||||
pluginId: 'e2e-mock-plugin',
|
||||
version: '1.0.0',
|
||||
config: manifestStr,
|
||||
enabled: true
|
||||
}
|
||||
});
|
||||
|
||||
// Ensure playwright auth directory exists
|
||||
if (typeof storageState === 'string') {
|
||||
const authDir = path.dirname(storageState);
|
||||
if (!fs.existsSync(authDir)) {
|
||||
fs.mkdirSync(authDir, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Perform UI Login
|
||||
console.log(`[Setup] Logging in via UI to generate storage state...`);
|
||||
const browser = await chromium.launch();
|
||||
const page = await browser.newPage();
|
||||
|
||||
await page.goto(`${baseURL}/login`);
|
||||
await page.fill('input[name="email"]', TEST_USER_EMAIL);
|
||||
await page.fill('input[name="password"]', password);
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// Wait for redirect to home
|
||||
await page.waitForURL(baseURL);
|
||||
|
||||
// 5. Save storage state
|
||||
if (typeof storageState === 'string') {
|
||||
await page.context().storageState({ path: storageState });
|
||||
} else {
|
||||
console.warn("Storage state path is not a string, skipping saving context.")
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
console.log(`[Setup] Global setup complete.`);
|
||||
} catch (error) {
|
||||
console.error(`[Setup] Error during global setup:`, error);
|
||||
throw error;
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
export default globalSetup;
|
||||
@@ -0,0 +1,53 @@
|
||||
import { type FullConfig } from '@playwright/test';
|
||||
import { PrismaClient } from '../src/generated/prisma/index.js';
|
||||
import { PrismaPg } from "@prisma/adapter-pg";
|
||||
import { Pool } from "pg";
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export const TEST_USER_EMAIL = '[email protected]';
|
||||
|
||||
function loadEnv() {
|
||||
try {
|
||||
const envPath = path.resolve(process.cwd(), '.env');
|
||||
if (fs.existsSync(envPath)) {
|
||||
const content = fs.readFileSync(envPath, 'utf8');
|
||||
content.split('\n').forEach(line => {
|
||||
const match = line.match(/^\s*([\w.-]+)\s*=\s*(.*)?\s*$/);
|
||||
if (match) {
|
||||
const key = match[1];
|
||||
let value = match[2] || '';
|
||||
if (value.startsWith('"') && value.endsWith('"')) value = value.slice(1, -1);
|
||||
if (value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
||||
process.env[key] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore read errors
|
||||
}
|
||||
}
|
||||
|
||||
async function globalTeardown(config: FullConfig) {
|
||||
loadEnv();
|
||||
const pool = new Pool({ connectionString: process.env.DATABASE_URL || "postgresql://postgres:[email protected]:5432/worldwideview?schema=public" });
|
||||
const adapter = new PrismaPg(pool);
|
||||
const prisma = new PrismaClient({ adapter });
|
||||
console.log(`[Teardown] Cleaning up test user: ${TEST_USER_EMAIL}`);
|
||||
try {
|
||||
console.log(`[Teardown] Cleaning up mock plugin...`);
|
||||
await prisma.installedPlugin.deleteMany({
|
||||
where: { pluginId: 'e2e-mock-plugin' }
|
||||
});
|
||||
await prisma.user.deleteMany({
|
||||
where: { email: TEST_USER_EMAIL },
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`[Teardown] Failed to delete test user:`, e);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
export default globalTeardown;
|
||||
@@ -0,0 +1,60 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('Dynamic Plugin System', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Navigate to root and wait for app to be completely booted
|
||||
await page.goto('/');
|
||||
await page.waitForSelector('[data-testid="app-ready"]', { state: 'attached', timeout: 45000 });
|
||||
});
|
||||
|
||||
test('successfully discovers, loads, and renders a mock dynamic plugin', async ({ page }) => {
|
||||
// Log console messages from the browser
|
||||
page.on('console', msg => {
|
||||
console.log(`[Browser Console] ${msg.type()}: ${msg.text()}`);
|
||||
if (msg.type() === 'error') {
|
||||
console.log(`[Browser Error] ${msg.location().url}:${msg.location().lineNumber}`);
|
||||
}
|
||||
});
|
||||
|
||||
// We expect the mock plugin to register its component in the sidebar.
|
||||
// The LeftPanel or RightPanel (depending on how the plugin manager handles generic 'sidebar' capabilities)
|
||||
// should render the component returned by getSidebarComponent().
|
||||
|
||||
// The mock plugin returns: <div data-testid="e2e-mock-panel">Mock Panel (E2E Test)</div>
|
||||
const mockPanel = page.locator('[data-testid="e2e-mock-panel"]');
|
||||
|
||||
// The unverified plugin dialog might appear for the mock plugin.
|
||||
const installBtn = page.getByRole('button', { name: /Install Selected/ });
|
||||
try {
|
||||
// Wait a short time for the dialog to appear
|
||||
await installBtn.waitFor({ state: 'visible', timeout: 5000 });
|
||||
await installBtn.click();
|
||||
console.log('Clicked "Install Selected" in unverified plugin dialog.');
|
||||
} catch (e) {
|
||||
// Dialog didn't appear, possibly because it's a verified plugin or already approved
|
||||
console.log('Unverified plugin dialog did not appear.');
|
||||
}
|
||||
|
||||
// To ensure the UI is in a state where it might be visible,
|
||||
// let's check if we need to open the right panel first. Plugins might inject into the right panel.
|
||||
const rightToggle = page.locator('[data-testid="panel-toggle-right"]');
|
||||
if (await rightToggle.count() > 0) {
|
||||
const isInitiallyOpen = await rightToggle.evaluate((node) => node.classList.contains('panel-toggle-btn--open'));
|
||||
if (!isInitiallyOpen) {
|
||||
await rightToggle.click();
|
||||
}
|
||||
}
|
||||
|
||||
// Click the layer item in the left panel to select it and display its config in the right panel
|
||||
const layerItem = page.locator('.layer-item', { hasText: 'E2E Mock Plugin' });
|
||||
await expect(layerItem).toBeVisible({ timeout: 10000 });
|
||||
await layerItem.click();
|
||||
|
||||
// Wait for the mock panel to be visible or attached.
|
||||
// Plugins might take a moment to dynamically load their chunks over HTTP.
|
||||
await expect(mockPanel).toBeAttached({ timeout: 10000 });
|
||||
|
||||
// Assert it contains the expected text
|
||||
await expect(mockPanel).toContainText('Mock Panel (E2E Test)');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,84 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('UI Navigation and Panels', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Navigate to root and wait for app to be completely booted
|
||||
await page.goto('/');
|
||||
await page.waitForSelector('[data-testid="app-ready"]', { state: 'attached', timeout: 45000 });
|
||||
|
||||
// Dismiss unverified plugin dialog if it appears
|
||||
const installBtn = page.getByRole('button', { name: /Install Selected/ });
|
||||
try {
|
||||
await installBtn.waitFor({ state: 'visible', timeout: 2000 });
|
||||
await installBtn.click();
|
||||
} catch (e) {
|
||||
// Ignore if it doesn't appear
|
||||
}
|
||||
});
|
||||
|
||||
test('can toggle left layers panel', async ({ page }) => {
|
||||
const leftToggle = page.locator('[data-testid="panel-toggle-left"]');
|
||||
await expect(leftToggle).toBeVisible();
|
||||
|
||||
// The left panel should open/close. We can check the class or state.
|
||||
// If we click it, it should toggle the 'panel-toggle-btn--open' class.
|
||||
|
||||
// Check initial state (should probably be open by default on desktop, but let's just toggle it and verify class changes)
|
||||
const isInitiallyOpen = await leftToggle.evaluate((node) => node.classList.contains('panel-toggle-btn--open'));
|
||||
|
||||
await leftToggle.click();
|
||||
|
||||
if (isInitiallyOpen) {
|
||||
await expect(leftToggle).not.toHaveClass(/panel-toggle-btn--open/);
|
||||
} else {
|
||||
await expect(leftToggle).toHaveClass(/panel-toggle-btn--open/);
|
||||
}
|
||||
});
|
||||
|
||||
test('can toggle right config panel', async ({ page }) => {
|
||||
const rightToggle = page.locator('[data-testid="panel-toggle-right"]');
|
||||
await expect(rightToggle).toBeVisible();
|
||||
|
||||
const isInitiallyOpen = await rightToggle.evaluate((node) => node.classList.contains('panel-toggle-btn--open'));
|
||||
|
||||
await rightToggle.click();
|
||||
|
||||
if (isInitiallyOpen) {
|
||||
await expect(rightToggle).not.toHaveClass(/panel-toggle-btn--open/);
|
||||
} else {
|
||||
await expect(rightToggle).toHaveClass(/panel-toggle-btn--open/);
|
||||
}
|
||||
});
|
||||
|
||||
test('can interact with timeline controls', async ({ page }) => {
|
||||
// The browser subagent identified button.timeline-close-btn
|
||||
const timelineCloseBtn = page.locator('button.timeline-close-btn');
|
||||
// Ensure it exists in the DOM. Wait for it just in case.
|
||||
if (await timelineCloseBtn.count() > 0) {
|
||||
await expect(timelineCloseBtn).toBeVisible();
|
||||
await timelineCloseBtn.click();
|
||||
// Test timeline mode toggle
|
||||
const modeToggle = page.locator('label.timeline__mode-toggle');
|
||||
if (await modeToggle.count() > 0) {
|
||||
await expect(modeToggle).toBeVisible();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('can switch left panel tabs', async ({ page }) => {
|
||||
// The panel tabs
|
||||
const dataLayersTab = page.locator('button.panel-tab[title="Data Layers"]');
|
||||
const imageryTab = page.locator('button.panel-tab[title="Imagery"]');
|
||||
|
||||
if (await dataLayersTab.count() > 0 && await imageryTab.count() > 0) {
|
||||
await expect(dataLayersTab).toBeVisible();
|
||||
await expect(imageryTab).toBeVisible();
|
||||
|
||||
await imageryTab.click();
|
||||
await expect(imageryTab).toHaveClass(/panel-tab--active/);
|
||||
|
||||
await dataLayersTab.click();
|
||||
await expect(dataLayersTab).toHaveClass(/panel-tab--active/);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user