Files
ComfyUI_frontend/browser_tests/i18nSetup.ts
snomiao 4c2715e480 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>
2025-09-02 03:33:16 +00:00

62 lines
1.9 KiB
TypeScript

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