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()
}