From 2e30b772e552d41fd149f4d706f12530c11186cf Mon Sep 17 00:00:00 2001 From: snomiao Date: Tue, 25 Nov 2025 06:17:02 +0000 Subject: [PATCH] [bugfix] Add vite-define shim for Playwright i18n collection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes the ReferenceError for __DISTRIBUTION__ when running i18n collection tests. Previously, Playwright's test runner would fail when importing code that uses Vite define variables (like __DISTRIBUTION__) because these variables are only replaced during Vite's build/dev process. Solution: - Created scripts/vite-define-shim.ts that defines all Vite define variables as global constants before tests run - Import the shim at the top of collect-i18n-general.ts - Also provides a minimal window shim for Node environment This allows the i18n collection process to import and evaluate coreMenuCommands which uses isCloud (which depends on __DISTRIBUTION__). Related to PR #6879 which added conditional menu commands based on distribution. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- scripts/collect-i18n-general.ts | 3 +++ scripts/vite-define-shim.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 scripts/vite-define-shim.ts diff --git a/scripts/collect-i18n-general.ts b/scripts/collect-i18n-general.ts index 1bbcb20605..5165e89bef 100644 --- a/scripts/collect-i18n-general.ts +++ b/scripts/collect-i18n-general.ts @@ -1,5 +1,8 @@ import * as fs from 'fs' +// Import Vite define shim to make __DISTRIBUTION__ and other define variables available +import './vite-define-shim' + import { DESKTOP_DIALOGS } from '../apps/desktop-ui/src/constants/desktopDialogs' import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage' import { diff --git a/scripts/vite-define-shim.ts b/scripts/vite-define-shim.ts new file mode 100644 index 0000000000..7c7f8ccfac --- /dev/null +++ b/scripts/vite-define-shim.ts @@ -0,0 +1,33 @@ +/** + * Shim for Vite define variables to make them available during Playwright test execution + * This file should be imported before any code that uses Vite define variables + */ + +// Define global constants that Vite would normally replace at build time +declare global { + const __COMFYUI_FRONTEND_VERSION__: string + const __SENTRY_ENABLED__: boolean + const __SENTRY_DSN__: string + const __ALGOLIA_APP_ID__: string + const __ALGOLIA_API_KEY__: string + const __USE_PROD_CONFIG__: boolean + const __DISTRIBUTION__: 'desktop' | 'localhost' | 'cloud' +} + +// Set default values for Playwright test environment +;(globalThis as any).__COMFYUI_FRONTEND_VERSION__ = + process.env.npm_package_version || '1.0.0' +;(globalThis as any).__SENTRY_ENABLED__ = false +;(globalThis as any).__SENTRY_DSN__ = '' +;(globalThis as any).__ALGOLIA_APP_ID__ = '' +;(globalThis as any).__ALGOLIA_API_KEY__ = '' +;(globalThis as any).__USE_PROD_CONFIG__ = false +;(globalThis as any).__DISTRIBUTION__ = 'localhost' + +// Provide a minimal window shim for Node environment +// This is needed for code that checks window existence during imports +if (typeof window === 'undefined') { + ;(globalThis as any).window = {} +} + +export {}