From 4217bfe02db38a018437eabd5b422a0a9928f580 Mon Sep 17 00:00:00 2001 From: EYHN Date: Wed, 21 May 2025 04:07:46 +0000 Subject: [PATCH] chore(infra): add url test to playwright (#11795) ## Summary by CodeRabbit - **Chores** - Updated Playwright test configurations to use full URL strings instead of port numbers for web server identification. - Unified server startup approach in test environments by integrating web server configuration directly into Playwright, replacing custom setup scripts. - Removed obsolete development server setup files to streamline test initialization. --- .../affine-cloud-copilot/playwright.config.ts | 4 +-- tests/affine-cloud/playwright.config.ts | 4 +-- .../affine-desktop-cloud/playwright.config.ts | 4 +-- tests/affine-desktop/playwright.config.ts | 2 +- tests/affine-local/dev-server.ts | 26 ------------------- tests/affine-local/playwright.config.ts | 12 ++++++++- tests/affine-mobile/playwright.config.ts | 2 +- tests/blocksuite/playwright.config.ts | 2 +- 8 files changed, 20 insertions(+), 36 deletions(-) delete mode 100644 tests/affine-local/dev-server.ts diff --git a/tests/affine-cloud-copilot/playwright.config.ts b/tests/affine-cloud-copilot/playwright.config.ts index e221744361..cb36b41687 100644 --- a/tests/affine-cloud-copilot/playwright.config.ts +++ b/tests/affine-cloud-copilot/playwright.config.ts @@ -29,7 +29,6 @@ const config: PlaywrightTestConfig = { webServer: [ { command: 'yarn run -T affine dev -p @affine/web', - port: 8080, stdout: 'ignore', stderr: 'ignore', timeout: 120 * 1000, @@ -37,10 +36,10 @@ const config: PlaywrightTestConfig = { env: { COVERAGE: process.env.COVERAGE || 'false', }, + url: 'http://localhost:8080', }, { command: 'yarn run -T affine dev -p @affine/server', - port: 3010, timeout: 120 * 1000, reuseExistingServer: !process.env.CI, stdout: 'ignore', @@ -60,6 +59,7 @@ const config: PlaywrightTestConfig = { MAILER_USER: 'noreply@toeverything.info', MAILER_PASSWORD: 'affine', }, + url: 'http://localhost:3010/graphql', }, ], }; diff --git a/tests/affine-cloud/playwright.config.ts b/tests/affine-cloud/playwright.config.ts index 452d8cfe65..dd014e6b3a 100644 --- a/tests/affine-cloud/playwright.config.ts +++ b/tests/affine-cloud/playwright.config.ts @@ -32,16 +32,15 @@ const config: PlaywrightTestConfig = { // we could download the builds from archives // and then run the web with simple http serve, it's will be faster command: 'yarn run -T affine dev -p @affine/web', - port: 8080, timeout: 120 * 1000, reuseExistingServer: !process.env.CI, env: { COVERAGE: process.env.COVERAGE || 'false', }, + url: 'http://localhost:8080', }, { command: 'yarn run -T affine dev -p @affine/server', - port: 3010, timeout: 120 * 1000, reuseExistingServer: !process.env.CI, env: { @@ -59,6 +58,7 @@ const config: PlaywrightTestConfig = { MAILER_USER: 'noreply@toeverything.info', MAILER_PASSWORD: 'affine', }, + url: 'http://localhost:3010/graphql', }, ], }; diff --git a/tests/affine-desktop-cloud/playwright.config.ts b/tests/affine-desktop-cloud/playwright.config.ts index 7a244b6255..64b5bb07e9 100644 --- a/tests/affine-desktop-cloud/playwright.config.ts +++ b/tests/affine-desktop-cloud/playwright.config.ts @@ -24,7 +24,6 @@ const config: PlaywrightTestConfig = { // Intentionally not building the web, reminds you to run it by yourself. { command: 'yarn run -T affine dev -p @affine/electron-renderer', - port: 8080, timeout: 120 * 1000, reuseExistingServer: !process.env.CI, stdout: 'pipe', @@ -32,10 +31,10 @@ const config: PlaywrightTestConfig = { COVERAGE: process.env.COVERAGE || 'false', DISTRIBUTION: 'desktop', }, + url: 'http://localhost:8080', }, { command: 'yarn run -T affine dev -p @affine/server', - port: 3010, timeout: 120 * 1000, reuseExistingServer: !process.env.CI, stdout: 'pipe', @@ -51,6 +50,7 @@ const config: PlaywrightTestConfig = { DEBUG_COLORS: 'true', MAILER_SENDER: 'noreply@toeverything.info', }, + url: 'http://localhost:3010/graphql', }, ], }; diff --git a/tests/affine-desktop/playwright.config.ts b/tests/affine-desktop/playwright.config.ts index 323b52e5db..f72a52d835 100644 --- a/tests/affine-desktop/playwright.config.ts +++ b/tests/affine-desktop/playwright.config.ts @@ -41,12 +41,12 @@ if (process.env.DEV_SERVER_URL) { config.webServer = [ { command: 'yarn run -T affine bundle -p @affine/electron-renderer --dev', - port: 8080, timeout: 120 * 1000, reuseExistingServer: !process.env.CI, env: { COVERAGE: process.env.COVERAGE || 'false', }, + url: 'http://localhost:8080', }, ]; } diff --git a/tests/affine-local/dev-server.ts b/tests/affine-local/dev-server.ts deleted file mode 100644 index 401116e140..0000000000 --- a/tests/affine-local/dev-server.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { BundleCommand } from '@affine-tools/cli/bundle'; -import { Package } from '@affine-tools/utils/workspace'; - -export default async () => { - await new Promise((resolve, reject) => { - BundleCommand.dev(new Package('@affine/web'), { - onListening: server => { - // dev server has already started - if (server.options.port !== 8080) { - server.compiler.close(reject); - server.stop().catch(reject); - resolve(); - } else { - server.middleware?.waitUntilValid?.(stats => { - if (stats?.hasErrors()) { - reject(new Error('Webpack build failed')); - } else { - resolve(); - } - }); - } - }, - }).catch(reject); - }); - console.log('Dev server started'); -}; diff --git a/tests/affine-local/playwright.config.ts b/tests/affine-local/playwright.config.ts index cf86af2383..d4a8592630 100644 --- a/tests/affine-local/playwright.config.ts +++ b/tests/affine-local/playwright.config.ts @@ -18,7 +18,6 @@ const config: PlaywrightTestConfig = { fullyParallel: true, timeout: process.env.CI ? 50_000 : 30_000, outputDir: testResultDir, - globalSetup: './dev-server.ts', use: { baseURL: 'http://localhost:8080/', browserName: @@ -42,6 +41,17 @@ const config: PlaywrightTestConfig = { // default 'list' when running locally // See https://playwright.dev/docs/test-reporters#github-actions-annotations reporter: process.env.CI ? 'github' : 'list', + webServer: [ + { + command: 'yarn run -T affine dev -p @affine/web', + timeout: 120 * 1000, + reuseExistingServer: !process.env.CI, + env: { + COVERAGE: process.env.COVERAGE || 'false', + }, + url: 'http://localhost:8080', + }, + ], }; if (process.env.CI) { diff --git a/tests/affine-mobile/playwright.config.ts b/tests/affine-mobile/playwright.config.ts index 6b14373e0d..b683977473 100644 --- a/tests/affine-mobile/playwright.config.ts +++ b/tests/affine-mobile/playwright.config.ts @@ -50,12 +50,12 @@ const config: PlaywrightTestConfig = { // Intentionally not building the web, reminds you to run it by yourself. { command: 'yarn run -T affine dev -p @affine/mobile', - port: 8080, timeout: 120 * 1000, reuseExistingServer: !process.env.CI, env: { COVERAGE: process.env.COVERAGE || 'false', }, + url: 'http://localhost:8080', }, ], }; diff --git a/tests/blocksuite/playwright.config.ts b/tests/blocksuite/playwright.config.ts index 74c565234e..0fd650eabd 100644 --- a/tests/blocksuite/playwright.config.ts +++ b/tests/blocksuite/playwright.config.ts @@ -15,11 +15,11 @@ export default defineConfig({ command: process.env.CI ? 'yarn workspace @blocksuite/playground run preview' : 'yarn workspace @blocksuite/playground run dev', - port: process.env.CI ? 4173 : 5173, reuseExistingServer: !process.env.CI, env: { COVERAGE: process.env.COVERAGE ?? '', }, + url: process.env.CI ? 'http://localhost:4173' : 'http://localhost:5173', }, use: { browserName: