mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-05 13:10:24 +00:00
Implements a solution to handle Vite define replacements during Playwright's Babel compilation for i18n collection tests. This resolves ReferenceErrors caused by unprocessed compile-time constants like __DISTRIBUTION__. Changes: - Add babel-plugin-vite-define.cjs to replace Vite define constants - Add babel-plugin-inject-globals.cjs to inject browser globals setup - Add setup-i18n-globals.mjs for JSDOM-based browser environment - Update playwright.i18n.config.ts with Babel plugin configuration - Install babel-plugin-module-resolver for @ alias support The implementation follows the approach from PR #5515 but is adapted for the current codebase structure. The Babel plugins run during Playwright's test compilation to ensure all Vite define constants are replaced with their actual values before execution. Fixes #10981 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { defineConfig } from '@playwright/test'
|
|
import path from 'path'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
|
|
const config = defineConfig({
|
|
testDir: './scripts',
|
|
use: {
|
|
baseURL: 'http://localhost:5173',
|
|
headless: true
|
|
},
|
|
reporter: 'list',
|
|
workers: 1,
|
|
timeout: 60000,
|
|
testMatch: /collect-i18n-.*\.ts/,
|
|
webServer: {
|
|
command: 'pnpm dev',
|
|
url: 'http://localhost:5173',
|
|
reuseExistingServer: true,
|
|
timeout: 120000
|
|
}
|
|
})
|
|
|
|
// Add Babel plugins for handling TypeScript and Vite defines
|
|
|
|
;(config as any)['@playwright/test'] = {
|
|
babelPlugins: [
|
|
// Module resolver for @ alias
|
|
[
|
|
'babel-plugin-module-resolver',
|
|
{
|
|
root: ['./'],
|
|
alias: { '@': './src' }
|
|
}
|
|
],
|
|
|
|
// TypeScript transformation with declare fields support
|
|
[
|
|
'@babel/plugin-transform-typescript',
|
|
{
|
|
allowDeclareFields: true,
|
|
onlyRemoveTypeImports: true
|
|
}
|
|
],
|
|
|
|
// Custom plugin to replace Vite define constants
|
|
[path.join(__dirname, 'scripts/babel-plugin-vite-define.cjs')],
|
|
|
|
// Inject browser globals setup for i18n collection tests
|
|
[
|
|
path.join(__dirname, 'scripts/babel-plugin-inject-globals.cjs'),
|
|
{
|
|
filenamePattern: 'collect-i18n-',
|
|
setupFile: './setup-i18n-globals.mjs'
|
|
}
|
|
]
|
|
]
|
|
}
|
|
|
|
export default config
|