diff --git a/apps/e2e-tests/package.json b/apps/e2e-tests/package.json index dc3f112ea..5aba7aba8 100644 --- a/apps/e2e-tests/package.json +++ b/apps/e2e-tests/package.json @@ -3,6 +3,7 @@ "version": "0.0.1", "private": true, "scripts": { - "e2e": "PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=false npx playwright test" + "e2e": "PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=false npx playwright test", + "e2e:lightpanda": "playwright test --config=playwright.lightpanda.config.ts" } } diff --git a/apps/e2e-tests/playwright.lightpanda.config.ts b/apps/e2e-tests/playwright.lightpanda.config.ts new file mode 100644 index 000000000..cc1939313 --- /dev/null +++ b/apps/e2e-tests/playwright.lightpanda.config.ts @@ -0,0 +1,26 @@ +import { defineConfig } from '@playwright/test'; +import { nxE2EPreset } from '@nx/playwright/preset'; + +const baseURL = process.env['BASE_URL'] || 'http://localhost:4200'; +const isCI = !!process.env.CI; + +export default defineConfig({ + ...nxE2EPreset(__filename, { testDir: './src' }), + reporter: [['html', { open: isCI ? 'never' : 'on-failure' }]], + use: { + baseURL, + trace: 'on-first-retry', + // video and screenshot disabled — Lightpanda has no rendering engine + video: 'off', + screenshot: 'off', + // Empty locale prevents Playwright from calling Emulation.setUserAgentOverride, + // which Lightpanda does not implement. Playwright's default is "en-US" which + // triggers that CDP command unconditionally (crPage.js: if options.locale → _updateUserAgent). + locale: '', + }, + projects: [ + { + name: 'lightpanda', + }, + ], +}); diff --git a/apps/e2e-tests/src/fixtures/packmindTest.ts b/apps/e2e-tests/src/fixtures/packmindTest.ts index 43a4a174b..09c261a64 100644 --- a/apps/e2e-tests/src/fixtures/packmindTest.ts +++ b/apps/e2e-tests/src/fixtures/packmindTest.ts @@ -1,4 +1,5 @@ -import { test as base } from '@playwright/test'; +import { test as base, Browser } from '@playwright/test'; +import { chromium } from 'playwright-core'; import { v4 as uuidv4 } from 'uuid'; import { IPackmindApi } from '../domain/api/IPackmindApi'; import { PackmindApi } from '../infra/api/PackmindApi'; @@ -6,7 +7,30 @@ import { SignUpWithOrganizationCommand } from '@packmind/types'; import { IDashboardPage, IPageFactory } from '../domain/pages'; import { PageFactory } from '../infra/PageFactory'; -export const testWithUserData = base.extend<{ +// Override the built-in browser fixture to support Lightpanda via CDP +const testBase = base.extend, { browser: Browser }>({ + browser: [ + // eslint-disable-next-line no-empty-pattern + async ({}, use) => { + const wsEndpoint = process.env['LIGHTPANDA_WS_ENDPOINT']; + if (wsEndpoint) { + const browser = await chromium.connectOverCDP({ + endpointURL: wsEndpoint, + }); + await use(browser as unknown as Browser); + // Browser.disconnect() does not exist on CDP-connected browsers in playwright-core. + // The connection closes naturally when the worker process exits; Lightpanda keeps running. + } else { + const browser = await chromium.launch(); + await use(browser); + await browser.close(); + } + }, + { scope: 'worker' }, + ], +}); + +export const testWithUserData = testBase.extend<{ userData: SignUpWithOrganizationCommand; }>({ // eslint-disable-next-line no-empty-pattern diff --git a/docker-compose.yml b/docker-compose.yml index dbaaec054..0af355991 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -309,6 +309,19 @@ services: run-migrations: condition: service_completed_successfully + lightpanda: + profiles: + - e2e-lightpanda + image: lightpanda/browser:nightly + container_name: ${COMPOSE_PROJECT_NAME:-dev}-lightpanda + environment: + LIGHTPANDA_DISABLE_TELEMETRY: 'true' + healthcheck: + test: ['CMD', 'bash', '-c', '