From e0ca8235c8c5be100e21e6739b59e6e5f410583d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Sun, 29 Mar 2026 14:32:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(ts):=20=E4=BF=AE=E5=A4=8DTypeScript?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. playwright.config.ts: - 添加类型断言 'fast' | 'standard' | 'deep' - 为tierConfig添加明确的Record类型 - 移除不必要的fallback 2. test-data-cleaner.ts: - 修复Object is possibly 'undefined'错误 - 添加可选链和空值检查 --- playwright.config.ts | 10 +++++++--- src/test-utils/test-data-cleaner.ts | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/playwright.config.ts b/playwright.config.ts index 60707b0..4ef3c0f 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,10 +1,14 @@ import { defineConfig, devices } from '@playwright/test'; const isCI = !!process.env.CI; -const testTier = process.env.TEST_TIER || 'standard'; +const testTier = (process.env.TEST_TIER || 'standard') as 'fast' | 'standard' | 'deep'; const baseURL = process.env.BASE_URL || (isCI ? 'http://localhost:3000' : 'https://novalon.cn'); -const tierConfig = { +const tierConfig: Record<'fast' | 'standard' | 'deep', { + timeout: number; + retries: number; + workers: number | undefined; +}> = { fast: { timeout: 15000, retries: 0, @@ -22,7 +26,7 @@ const tierConfig = { }, }; -const config = tierConfig[testTier] || tierConfig.standard; +const config = tierConfig[testTier]; export default defineConfig({ testDir: './e2e', diff --git a/src/test-utils/test-data-cleaner.ts b/src/test-utils/test-data-cleaner.ts index 09bab85..7be2eaa 100644 --- a/src/test-utils/test-data-cleaner.ts +++ b/src/test-utils/test-data-cleaner.ts @@ -71,8 +71,11 @@ export class TestDataCleaner { static clearCookies(): void { if (typeof document !== 'undefined' && document.cookie) { document.cookie.split(';').forEach(cookie => { - const name = cookie.split('=')[0].trim(); - document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`; + const parts = cookie.split('='); + const name = parts[0]?.trim(); + if (name) { + document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`; + } }); } }