From 18c2163625deff63b7aab3b31228182a9a87f960 Mon Sep 17 00:00:00 2001 From: snomiao Date: Sun, 31 Aug 2025 13:51:38 +0000 Subject: [PATCH] [fix] Fix collect-i18n script compilation error with TypeScript declare fields The collect-i18n script was failing with babel transformer error when encountering TypeScript declare fields in litegraph classes. Root cause: - Playwright internal TypeScript compilation does not handle declare fields properly - i18n test files imported ComfyNodeDefImpl which imports litegraph types Solution: - Move i18n tests to browser_tests/tests/ with .spec.ts extension - Remove direct imports of types that reference litegraph - Process node definitions in browser context where types are available - Use nx e2e command for consistency with other browser tests Fixes regression introduced after Nx integration --- .../tests/collect-i18n-general.spec.ts | 12 +++--- .../tests/collect-i18n-node-defs.spec.ts | 42 +++++++++++-------- package.json | 2 +- playwright.i18n.config.ts | 12 ------ 4 files changed, 31 insertions(+), 37 deletions(-) rename scripts/collect-i18n-general.ts => browser_tests/tests/collect-i18n-general.spec.ts (91%) rename scripts/collect-i18n-node-defs.ts => browser_tests/tests/collect-i18n-node-defs.spec.ts (82%) delete mode 100644 playwright.i18n.config.ts diff --git a/scripts/collect-i18n-general.ts b/browser_tests/tests/collect-i18n-general.spec.ts similarity index 91% rename from scripts/collect-i18n-general.ts rename to browser_tests/tests/collect-i18n-general.spec.ts index 63d97d530..5944a1548 100644 --- a/scripts/collect-i18n-general.ts +++ b/browser_tests/tests/collect-i18n-general.spec.ts @@ -1,11 +1,11 @@ import * as fs from 'fs' -import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage' -import { CORE_MENU_COMMANDS } from '../src/constants/coreMenuCommands' -import { SERVER_CONFIG_ITEMS } from '../src/constants/serverConfig' -import type { ComfyCommandImpl } from '../src/stores/commandStore' -import type { FormItem, SettingParams } from '../src/types/settingTypes' -import { formatCamelCase, normalizeI18nKey } from '../src/utils/formatUtil' +import { CORE_MENU_COMMANDS } from '../../src/constants/coreMenuCommands' +import { SERVER_CONFIG_ITEMS } from '../../src/constants/serverConfig' +import type { ComfyCommandImpl } from '../../src/stores/commandStore' +import type { FormItem, SettingParams } from '../../src/types/settingTypes' +import { formatCamelCase, normalizeI18nKey } from '../../src/utils/formatUtil' +import { comfyPageFixture as test } from '../fixtures/ComfyPage' const localePath = './src/locales/en/main.json' const commandsPath = './src/locales/en/commands.json' diff --git a/scripts/collect-i18n-node-defs.ts b/browser_tests/tests/collect-i18n-node-defs.spec.ts similarity index 82% rename from scripts/collect-i18n-node-defs.ts rename to browser_tests/tests/collect-i18n-node-defs.spec.ts index ed443015a..6873b7e58 100644 --- a/scripts/collect-i18n-node-defs.ts +++ b/browser_tests/tests/collect-i18n-node-defs.spec.ts @@ -1,33 +1,39 @@ import * as fs from 'fs' -import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage' -import type { ComfyNodeDef } from '../src/schemas/nodeDefSchema' -import type { ComfyApi } from '../src/scripts/api' -import { ComfyNodeDefImpl } from '../src/stores/nodeDefStore' -import { normalizeI18nKey } from '../src/utils/formatUtil' +import { normalizeI18nKey } from '../../src/utils/formatUtil' +import { comfyPageFixture as test } from '../fixtures/ComfyPage' const localePath = './src/locales/en/main.json' const nodeDefsPath = './src/locales/en/nodeDefs.json' test('collect-i18n-node-defs', async ({ comfyPage }) => { // Mock view route - comfyPage.page.route('**/view**', async (route) => { + await comfyPage.page.route('**/view**', async (route) => { await route.fulfill({ body: JSON.stringify({}) }) }) - const nodeDefs: ComfyNodeDefImpl[] = ( - Object.values( - await comfyPage.page.evaluate(async () => { - const api = window['app'].api as ComfyApi - return await api.getNodeDefs() + const nodeDefs = await comfyPage.page.evaluate(async () => { + const api = window['app'].api + const defs = await api.getNodeDefs() + // Process node definitions in the browser context where ComfyNodeDefImpl is available + return Object.values(defs) + .filter((def: any) => !def.name.startsWith('DevTools')) + .map((def: any) => { + // Create ComfyNodeDefImpl in browser context + const impl = new (window as any).ComfyNodeDefImpl(def) + // Return a plain object with the needed properties + return { + name: impl.name, + display_name: impl.display_name, + description: impl.description, + category: impl.category, + inputs: impl.inputs, + outputs: impl.outputs + } }) - ) as ComfyNodeDef[] - ) - // Ignore DevTools nodes (used for internal testing) - .filter((def) => !def.name.startsWith('DevTools')) - .map((def) => new ComfyNodeDefImpl(def)) + }) console.log(`Collected ${nodeDefs.length} node definitions`) @@ -100,7 +106,7 @@ test('collect-i18n-node-defs', async ({ comfyPage }) => { const nodeDefLabels = await extractWidgetLabels() - function extractInputs(nodeDef: ComfyNodeDefImpl) { + function extractInputs(nodeDef: any) { const inputs = Object.fromEntries( Object.values(nodeDef.inputs).flatMap((input) => { const name = input.name @@ -124,7 +130,7 @@ test('collect-i18n-node-defs', async ({ comfyPage }) => { return Object.keys(inputs).length > 0 ? inputs : undefined } - function extractOutputs(nodeDef: ComfyNodeDefImpl) { + function extractOutputs(nodeDef: any) { const outputs = Object.fromEntries( nodeDef.outputs.flatMap((output, i) => { // Ignore data types if they are already translated in allDataTypesLocale. diff --git a/package.json b/package.json index 73eea1c80..dfd273e00 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "knip": "knip --cache", "knip:no-cache": "knip", "locale": "lobe-i18n locale", - "collect-i18n": "npx playwright test --config=playwright.i18n.config.ts", + "collect-i18n": "nx run @comfyorg/comfyui-frontend:e2e --grep=\"collect-i18n\"", "json-schema": "tsx scripts/generate-json-schema.ts", "storybook": "nx storybook -p 6006", "build-storybook": "storybook build" diff --git a/playwright.i18n.config.ts b/playwright.i18n.config.ts deleted file mode 100644 index 70c3a0c81..000000000 --- a/playwright.i18n.config.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { defineConfig } from '@playwright/test' - -export default defineConfig({ - testDir: './scripts', - use: { - baseURL: 'http://localhost:5173', - headless: true - }, - reporter: 'list', - timeout: 60000, - testMatch: /collect-i18n-.*\.ts/ -})