refactor: Replace script-based litegraph preprocessing with integrated Playwright setup

- Remove prebuild-litegraph.js and restore-litegraph.js scripts
- Add i18nSetup.ts module for litegraph TypeScript 'declare' keyword preprocessing
- Create ComfyPageNoUser fixture to avoid user creation conflicts in i18n tests
- Update playwright.i18n.config.ts to use integrated setup/teardown
- Simplify collect-i18n command to just run Playwright tests
- Ensure pnpm collect-i18n works correctly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
snomiao
2025-09-02 03:33:16 +00:00
parent 83de398b21
commit 4c2715e480
14 changed files with 218 additions and 211 deletions

View File

@@ -0,0 +1,27 @@
import { test as base } from '@playwright/test'
import { ComfyPage } from './ComfyPage'
/**
* Simplified fixture for i18n collection that doesn't require user setup
*/
export const comfyPageNoUserFixture = base.extend<{
comfyPage: ComfyPage
}>({
comfyPage: async ({ page, request }, use) => {
const comfyPage = new ComfyPage(page, request)
// Navigate directly to the app without user setup
await comfyPage.goto()
// Wait for the app to be fully initialized
await page.waitForFunction(
() => window['app']?.extensionManager !== undefined,
{ timeout: 30000 }
)
// Use the page
await use(comfyPage)
}
})
export const test = comfyPageNoUserFixture

View File

@@ -0,0 +1,30 @@
/**
* Combined global setup for i18n collection tests
* Includes both regular setup and litegraph preprocessing
*/
import globalSetup from './globalSetup'
import { preprocessLitegraph } from './i18nSetup'
export default async function globalSetupWithI18n() {
// First preprocess litegraph files
await preprocessLitegraph()
// Then run regular global setup
await globalSetup()
// Register cleanup handlers
const cleanup = async () => {
const { restoreLitegraph } = await import('./i18nSetup')
await restoreLitegraph()
}
process.on('exit', cleanup)
process.on('SIGINT', async () => {
await cleanup()
process.exit(0)
})
process.on('SIGTERM', async () => {
await cleanup()
process.exit(0)
})
}

View File

@@ -0,0 +1,14 @@
/**
* Combined global teardown for i18n collection tests
* Includes both regular teardown and litegraph restoration
*/
import globalTeardown from './globalTeardown'
import { restoreLitegraph } from './i18nSetup'
export default async function globalTeardownWithI18n() {
// First run regular teardown
await globalTeardown()
// Then restore litegraph files
await restoreLitegraph()
}

View File

@@ -0,0 +1,62 @@
/**
* Setup for i18n collection tests
* Handles preprocessing of litegraph files that contain TypeScript 'declare' keywords
*/
import * as fs from 'fs'
import * as path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const rootDir = path.resolve(__dirname, '..')
const litegraphSrcDir = path.join(rootDir, 'src/lib/litegraph/src')
const filesToProcess = [
'LGraphNode.ts',
'widgets/BaseWidget.ts',
'subgraph/SubgraphInput.ts',
'subgraph/SubgraphNode.ts',
'subgraph/SubgraphOutput.ts',
'subgraph/EmptySubgraphInput.ts',
'subgraph/EmptySubgraphOutput.ts'
]
const backupMap = new Map<string, string>()
export async function preprocessLitegraph() {
console.log('Preprocessing litegraph files for i18n collection...')
for (const relativePath of filesToProcess) {
const filePath = path.join(litegraphSrcDir, relativePath)
if (fs.existsSync(filePath)) {
const originalContent = fs.readFileSync(filePath, 'utf-8')
// Only process if file contains 'declare' keywords
if (originalContent.includes('declare ')) {
// Store original content in memory
backupMap.set(filePath, originalContent)
// Remove 'declare' keyword from class properties
const modifiedContent = originalContent.replace(
/^(\s*)declare\s+/gm,
'$1// @ts-ignore - removed declare for Playwright\n$1'
)
// Write modified content
fs.writeFileSync(filePath, modifiedContent)
console.log(` ✓ Processed ${relativePath}`)
}
}
}
}
export async function restoreLitegraph() {
console.log('Restoring original litegraph files...')
for (const [filePath, originalContent] of backupMap.entries()) {
fs.writeFileSync(filePath, originalContent)
console.log(` ✓ Restored ${path.relative(litegraphSrcDir, filePath)}`)
}
backupMap.clear()
}

View File

@@ -31,9 +31,7 @@
"knip": "knip --cache",
"knip:no-cache": "knip",
"locale": "lobe-i18n locale",
"prebuild:litegraph": "node scripts/prebuild-litegraph.js",
"restore:litegraph": "node scripts/restore-litegraph.js",
"collect-i18n": "pnpm prebuild:litegraph && npx playwright test --config=playwright.i18n.config.ts; pnpm restore:litegraph",
"collect-i18n": "npx playwright test --config=playwright.i18n.config.ts",
"json-schema": "tsx scripts/generate-json-schema.ts",
"storybook": "nx storybook -p 6006",
"build-storybook": "storybook build"

View File

@@ -2,14 +2,13 @@ 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/,
// Use the same global setup as regular tests to ensure proper environment
globalSetup: './browser_tests/globalSetup.ts',
globalTeardown: './browser_tests/globalTeardown.ts'
// Run tests sequentially to avoid conflicts
workers: 1,
fullyParallel: false,
// Use combined setup that includes litegraph preprocessing
globalSetup: './browser_tests/globalSetupWithI18n.ts',
globalTeardown: './browser_tests/globalTeardownWithI18n.ts'
})

View File

@@ -1,6 +1,6 @@
import * as fs from 'fs'
import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage'
import { test } from '../browser_tests/fixtures/ComfyPageNoUser'
import { CORE_MENU_COMMANDS } from '../src/constants/coreMenuCommands'
import { SERVER_CONFIG_ITEMS } from '../src/constants/serverConfig'
import type { ComfyCommandImpl } from '../src/stores/commandStore'

View File

@@ -1,6 +1,6 @@
import * as fs from 'fs'
import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage'
import { test } from '../browser_tests/fixtures/ComfyPageNoUser'
import type { ComfyNodeDef } from '../src/schemas/nodeDefSchema'
import type { ComfyApi } from '../src/scripts/api'
import { ComfyNodeDefImpl } from '../src/stores/nodeDefStore'

View File

@@ -1,69 +0,0 @@
#!/usr/bin/env node
/**
* Prebuild script for litegraph to ensure compatibility with Playwright
* This script removes TypeScript 'declare' keyword that Playwright/Babel can't handle
* The files remain as TypeScript but with the problematic syntax removed
*/
import fs from 'fs-extra'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const rootDir = path.resolve(__dirname, '..')
const litegraphSrcDir = path.join(rootDir, 'src/lib/litegraph/src')
async function prebuildLitegraph() {
console.log('Pre-processing litegraph for Playwright compatibility...')
try {
// Find all TypeScript files that use 'declare'
const filesToProcess = [
'LGraphNode.ts',
'widgets/BaseWidget.ts',
'subgraph/SubgraphInput.ts',
'subgraph/SubgraphNode.ts',
'subgraph/SubgraphOutput.ts',
'subgraph/EmptySubgraphInput.ts',
'subgraph/EmptySubgraphOutput.ts'
]
let processedCount = 0
for (const relativePath of filesToProcess) {
const filePath = path.join(litegraphSrcDir, relativePath)
if (await fs.pathExists(filePath)) {
const originalContent = await fs.readFile(filePath, 'utf-8')
// Remove 'declare' keyword from class properties
// This regex matches 'declare' at the start of a line (with optional whitespace)
const modifiedContent = originalContent.replace(
/^(\s*)declare\s+/gm,
'$1// @ts-ignore\n$1'
)
if (originalContent !== modifiedContent) {
// Create backup
const backupPath = filePath + '.backup'
if (!(await fs.pathExists(backupPath))) {
await fs.writeFile(backupPath, originalContent)
}
// Write modified content
await fs.writeFile(filePath, modifiedContent)
processedCount++
console.log(` ✓ Processed ${relativePath}`)
}
}
}
console.log(`✅ Pre-processed ${processedCount} files successfully`)
} catch (error) {
console.error('❌ Failed to pre-process litegraph:', error.message)
// eslint-disable-next-line no-undef
process.exit(1)
}
}
// Run the prebuild
prebuildLitegraph().catch(console.error)

View File

@@ -1,52 +0,0 @@
#!/usr/bin/env node
/**
* Restore script for litegraph after Playwright tests
* This script restores the original TypeScript files from backups
*/
import fs from 'fs-extra'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const rootDir = path.resolve(__dirname, '..')
const litegraphSrcDir = path.join(rootDir, 'src/lib/litegraph/src')
async function restoreLitegraph() {
console.log('Restoring original litegraph files...')
try {
const filesToRestore = [
'LGraphNode.ts',
'widgets/BaseWidget.ts',
'subgraph/SubgraphInput.ts',
'subgraph/SubgraphNode.ts',
'subgraph/SubgraphOutput.ts',
'subgraph/EmptySubgraphInput.ts',
'subgraph/EmptySubgraphOutput.ts'
]
let restoredCount = 0
for (const relativePath of filesToRestore) {
const filePath = path.join(litegraphSrcDir, relativePath)
const backupPath = filePath + '.backup'
if (await fs.pathExists(backupPath)) {
const backupContent = await fs.readFile(backupPath, 'utf-8')
await fs.writeFile(filePath, backupContent)
await fs.remove(backupPath)
restoredCount++
console.log(` ✓ Restored ${relativePath}`)
}
}
console.log(`✅ Restored ${restoredCount} files successfully`)
} catch (error) {
console.error('❌ Failed to restore litegraph:', error.message)
// eslint-disable-next-line no-undef
process.exit(1)
}
}
// Run the restore
restoreLitegraph().catch(console.error)

View File

@@ -1,40 +1,4 @@
{
"Comfy-Desktop_CheckForUpdates": {
"label": "Check for Updates"
},
"Comfy-Desktop_Folders_OpenCustomNodesFolder": {
"label": "Open Custom Nodes Folder"
},
"Comfy-Desktop_Folders_OpenInputsFolder": {
"label": "Open Inputs Folder"
},
"Comfy-Desktop_Folders_OpenLogsFolder": {
"label": "Open Logs Folder"
},
"Comfy-Desktop_Folders_OpenModelConfig": {
"label": "Open extra_model_paths.yaml"
},
"Comfy-Desktop_Folders_OpenModelsFolder": {
"label": "Open Models Folder"
},
"Comfy-Desktop_Folders_OpenOutputsFolder": {
"label": "Open Outputs Folder"
},
"Comfy-Desktop_OpenDevTools": {
"label": "Open DevTools"
},
"Comfy-Desktop_OpenUserGuide": {
"label": "Desktop User Guide"
},
"Comfy-Desktop_Quit": {
"label": "Quit"
},
"Comfy-Desktop_Reinstall": {
"label": "Reinstall"
},
"Comfy-Desktop_Restart": {
"label": "Restart"
},
"Comfy_3DViewer_Open3DViewer": {
"label": "Open 3D Viewer (Beta) for Selected Node"
},
@@ -173,6 +137,12 @@
"Comfy_Manager_CustomNodesManager": {
"label": "Toggle the Custom Nodes Manager"
},
"Comfy_Manager_CustomNodesManager_ToggleVisibility": {
"label": "Toggle Custom Nodes Manager Visibility"
},
"Comfy_Manager_Menu_ToggleVisibility": {
"label": "Toggle Manager Menu Visibility"
},
"Comfy_Manager_ToggleManagerProgressDialog": {
"label": "Toggle the Custom Nodes Manager Progress Bar"
},
@@ -257,9 +227,6 @@
"Workspace_ToggleBottomPanel_Shortcuts": {
"label": "Show Keybindings Dialog"
},
"Workspace_ToggleBottomPanelTab_command-terminal": {
"label": "Toggle Terminal Bottom Panel"
},
"Workspace_ToggleBottomPanelTab_logs-terminal": {
"label": "Toggle Logs Bottom Panel"
},

View File

@@ -958,18 +958,6 @@
"File": "File",
"Edit": "Edit",
"Help": "Help",
"Check for Updates": "Check for Updates",
"Open Custom Nodes Folder": "Open Custom Nodes Folder",
"Open Inputs Folder": "Open Inputs Folder",
"Open Logs Folder": "Open Logs Folder",
"Open extra_model_paths_yaml": "Open extra_model_paths.yaml",
"Open Models Folder": "Open Models Folder",
"Open Outputs Folder": "Open Outputs Folder",
"Open DevTools": "Open DevTools",
"Desktop User Guide": "Desktop User Guide",
"Quit": "Quit",
"Reinstall": "Reinstall",
"Restart": "Restart",
"Open 3D Viewer (Beta) for Selected Node": "Open 3D Viewer (Beta) for Selected Node",
"Browse Templates": "Browse Templates",
"Delete Selected Items": "Delete Selected Items",
@@ -1016,6 +1004,8 @@
"Interrupt": "Interrupt",
"Load Default Workflow": "Load Default Workflow",
"Toggle the Custom Nodes Manager": "Toggle the Custom Nodes Manager",
"Toggle Custom Nodes Manager Visibility": "Toggle Custom Nodes Manager Visibility",
"Toggle Manager Menu Visibility": "Toggle Manager Menu Visibility",
"Toggle the Custom Nodes Manager Progress Bar": "Toggle the Custom Nodes Manager Progress Bar",
"Decrease Brush Size in MaskEditor": "Decrease Brush Size in MaskEditor",
"Increase Brush Size in MaskEditor": "Increase Brush Size in MaskEditor",
@@ -1044,7 +1034,6 @@
"Toggle Search Box": "Toggle Search Box",
"Bottom Panel": "Bottom Panel",
"Show Keybindings Dialog": "Show Keybindings Dialog",
"Toggle Terminal Bottom Panel": "Toggle Terminal Bottom Panel",
"Toggle Logs Bottom Panel": "Toggle Logs Bottom Panel",
"Toggle Essential Bottom Panel": "Toggle Essential Bottom Panel",
"Toggle View Controls Bottom Panel": "Toggle View Controls Bottom Panel",
@@ -1290,6 +1279,7 @@
"Gemini": "Gemini",
"text": "text",
"gligen": "gligen",
"HotReload": "HotReload",
"video_models": "video_models",
"Ideogram": "Ideogram",
"postprocessing": "postprocessing",
@@ -1329,6 +1319,7 @@
"style_model": "style_model",
"Tripo": "Tripo",
"Veo": "Veo",
"processing": "processing",
"Vidu": "Vidu",
"camera": "camera"
},

View File

@@ -2196,6 +2196,9 @@
}
}
},
"HotReload_Terminal": {
"display_name": "Terminal"
},
"Hunyuan3Dv2Conditioning": {
"display_name": "Hunyuan3Dv2Conditioning",
"inputs": {
@@ -3360,6 +3363,9 @@
"denoise": {
"name": "denoise",
"tooltip": "The amount of denoising applied, lower values will maintain the structure of the initial image allowing for image to image sampling."
},
"control_after_generate": {
"name": "control after generate"
}
},
"outputs": {
@@ -3409,6 +3415,9 @@
},
"return_with_leftover_noise": {
"name": "return_with_leftover_noise"
},
"control_after_generate": {
"name": "control after generate"
}
}
},
@@ -3864,6 +3873,9 @@
"inputs": {
"image": {
"name": "image"
},
"upload": {
"name": "choose file to upload"
}
}
},
@@ -3875,6 +3887,9 @@
},
"channel": {
"name": "channel"
},
"upload": {
"name": "choose file to upload"
}
}
},
@@ -3884,6 +3899,11 @@
"inputs": {
"image": {
"name": "image"
},
"Auto-refresh after generation": {},
"refresh": {},
"upload": {
"name": "choose file to upload"
}
}
},
@@ -10787,6 +10807,46 @@
}
}
},
"VideoCropNode": {
"display_name": "Video Crop (FFmpeg)",
"inputs": {
"video": {
"name": "video"
},
"x": {
"name": "x"
},
"y": {
"name": "y"
},
"width": {
"name": "width"
},
"height": {
"name": "height"
},
"output_format": {
"name": "output_format"
},
"codec": {
"name": "codec"
},
"quality": {
"name": "quality"
},
"fps": {
"name": "fps"
},
"extra_ffmpeg_args": {
"name": "extra_ffmpeg_args"
}
},
"outputs": {
"0": {
"name": "cropped_video"
}
}
},
"VideoLinearCFGGuidance": {
"display_name": "VideoLinearCFGGuidance",
"inputs": {

View File

@@ -1,30 +1,4 @@
{
"Comfy-Desktop_AutoUpdate": {
"name": "Automatically check for updates"
},
"Comfy-Desktop_SendStatistics": {
"name": "Send anonymous usage metrics"
},
"Comfy-Desktop_UV_PypiInstallMirror": {
"name": "Pypi Install Mirror",
"tooltip": "Default pip install mirror"
},
"Comfy-Desktop_UV_PythonInstallMirror": {
"name": "Python Install Mirror",
"tooltip": "Managed Python installations are downloaded from the Astral python-build-standalone project. This variable can be set to a mirror URL to use a different source for Python installations. The provided URL will replace https://github.com/astral-sh/python-build-standalone/releases/download in, e.g., https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz. Distributions can be read from a local directory by using the file:// URL scheme."
},
"Comfy-Desktop_UV_TorchInstallMirror": {
"name": "Torch Install Mirror",
"tooltip": "Pip install mirror for pytorch"
},
"Comfy-Desktop_WindowStyle": {
"name": "Window Style",
"tooltip": "Custom: Replace the system title bar with ComfyUI's Top menu",
"options": {
"default": "default",
"custom": "custom"
}
},
"Comfy_Canvas_BackgroundImage": {
"name": "Canvas background image",
"tooltip": "Image URL for the canvas background. You can right-click an image in the outputs panel and select \"Set as Background\" to use it, or upload your own image using the upload button."
@@ -388,6 +362,12 @@
"Topbar (2nd-row)": "Topbar (2nd-row)"
}
},
"HotReload_config": {
"name": "Hot Reload Configuration"
},
"HotReload_language": {
"name": "Language"
},
"LiteGraph_Canvas_LowQualityRenderingZoomThreshold": {
"name": "Low quality rendering zoom threshold",
"tooltip": "Zoom level threshold for performance mode. Lower values (0.1) = quality at all zoom levels. Higher values (1.0) = performance mode even when zoomed in. Performance mode simplifies rendering by hiding text labels, shadows, and details."