diff --git a/package.json b/package.json index 130a7e2b211d7..c01cf7743450c 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "dev:be": "turbo run dev --parallel --env-mode=loose --filter=!@n8n/design-system --filter=!@n8n/chat --filter=!@n8n/task-runner --filter=!n8n-editor-ui", "dev:ai": "turbo run dev --parallel --env-mode=loose --filter=@n8n/nodes-langchain --filter=n8n --filter=n8n-core", "dev:fe": "run-p start \"dev:fe:editor --filter=@n8n/design-system\"", - "dev:fe:e2e": "run-p start dev:fe:editor", "dev:fe:editor": "turbo run dev --parallel --env-mode=loose --filter=n8n-editor-ui", "dev:e2e": "pnpm --filter=n8n-playwright dev --ui", "clean": "turbo run clean", diff --git a/packages/testing/playwright/global-teardown.ts b/packages/testing/playwright/global-teardown.ts new file mode 100644 index 0000000000000..26da3204223a0 --- /dev/null +++ b/packages/testing/playwright/global-teardown.ts @@ -0,0 +1,27 @@ +import { execSync } from 'child_process'; + +function globalTeardown() { + console.log('๐Ÿงน Starting global teardown...'); + + const ports = [5678, 8080]; + + for (const port of ports) { + try { + // Find process ID using the port + const pid = execSync(`lsof -ti :${port}`, { encoding: 'utf-8' }).trim(); + + if (pid) { + console.log(`- Killing process ${pid} on port ${port}`); + execSync(`kill -9 ${pid}`); + } + } catch (error) { + // lsof returns non-zero exit code if no process is found + console.log(`- No process found on port ${port}`); + } + } + + console.log('๐Ÿ Global teardown completed'); +} + +// eslint-disable-next-line import-x/no-default-export +export default globalTeardown; diff --git a/packages/testing/playwright/playwright.config.ts b/packages/testing/playwright/playwright.config.ts index 70afd5ba27d14..698e992add41e 100644 --- a/packages/testing/playwright/playwright.config.ts +++ b/packages/testing/playwright/playwright.config.ts @@ -2,6 +2,7 @@ import type { CurrentsFixtures, CurrentsWorkerFixtures } from '@currents/playwright'; import { currentsReporter } from '@currents/playwright'; import { defineConfig } from '@playwright/test'; +import type { PlaywrightTestConfig } from '@playwright/test'; import os from 'os'; import path from 'path'; @@ -39,13 +40,49 @@ const WORKERS = IS_DEV ? 1 : IS_CI ? CI_WORKERS : LOCAL_WORKERS; const BACKEND_URL = getBackendUrl(); const FRONTEND_URL = getFrontendUrl(); -const START_COMMAND = IS_DEV ? 'pnpm dev:fe:e2e' : 'pnpm start'; const WEB_SERVER_URL = FRONTEND_URL ?? BACKEND_URL; const EXPECT_TIMEOUT = IS_DEV ? 20000 : 10000; +const webServer: PlaywrightTestConfig['webServer'] = []; + +if (BACKEND_URL) { + webServer.push({ + command: 'cd .. && pnpm start', + url: `${BACKEND_URL}/favicon.ico`, + timeout: 30000, + reuseExistingServer: IS_DEV ? false : true, + env: { + DB_SQLITE_POOL_SIZE: '40', + E2E_TESTS: 'true', + N8N_PORT: getPortFromUrl(BACKEND_URL), + N8N_USER_FOLDER: USER_FOLDER, + N8N_LOG_LEVEL: 'debug', + N8N_METRICS: 'true', + N8N_RESTRICT_FILE_ACCESS_TO: '', + N8N_DYNAMIC_BANNERS_ENABLED: 'false', + ...getTestEnv(), + }, + }); +} + +if (FRONTEND_URL) { + webServer.push({ + command: 'cd .. && pnpm dev:fe:editor', + url: `${FRONTEND_URL}/favicon.ico`, + timeout: 30000, + reuseExistingServer: IS_DEV ? false : true, + env: { + E2E_TESTS: 'true', + N8N_PORT: getPortFromUrl(FRONTEND_URL), + ...getTestEnv(), + }, + }); +} + export default defineConfig({ globalSetup: './global-setup.ts', + globalTeardown: IS_DEV ? './global-teardown.ts' : undefined, forbidOnly: IS_CI, retries: IS_CI ? 2 : 0, workers: WORKERS, @@ -56,27 +93,10 @@ export default defineConfig({ projects: getProjects(), // We use this if an n8n url is passed in. If the server is already running, we reuse it. - webServer: BACKEND_URL - ? { - command: `cd .. && ${START_COMMAND}`, - url: `${WEB_SERVER_URL}/favicon.ico`, - timeout: 30000, - reuseExistingServer: true, - env: { - DB_SQLITE_POOL_SIZE: '40', - E2E_TESTS: 'true', - N8N_PORT: getPortFromUrl(BACKEND_URL), - N8N_USER_FOLDER: USER_FOLDER, - N8N_LOG_LEVEL: 'debug', - N8N_METRICS: 'true', - N8N_RESTRICT_FILE_ACCESS_TO: '', - N8N_DYNAMIC_BANNERS_ENABLED: 'false', - ...getTestEnv(), - }, - } - : undefined, + webServer, use: { + baseURL: WEB_SERVER_URL, trace: 'on', video: 'on', screenshot: 'on',