mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 06:47:33 +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>
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
/**
|
|
* Babel plugin to inject global setup imports into specific test files
|
|
*
|
|
* This plugin automatically adds an import for browser globals setup
|
|
* at the beginning of files matching a specific pattern
|
|
*/
|
|
|
|
const nodePath = require('path')
|
|
|
|
module.exports = function (babel, options = {}) {
|
|
const { filenamePattern = 'collect-i18n-', setupFile = './setup-i18n-globals.mjs' } = options
|
|
|
|
return {
|
|
name: 'babel-plugin-inject-globals',
|
|
|
|
visitor: {
|
|
Program: {
|
|
enter(path, state) {
|
|
const filename = state.file.opts.filename
|
|
|
|
// Only process files matching the pattern
|
|
if (!filename || !filename.includes(filenamePattern)) {
|
|
return
|
|
}
|
|
|
|
// Check if setup import already exists
|
|
const hasSetupImport = path.node.body.some(
|
|
(node) =>
|
|
node.type === 'ImportDeclaration' &&
|
|
node.source.value.includes('setup-i18n-globals')
|
|
)
|
|
|
|
if (hasSetupImport) {
|
|
return
|
|
}
|
|
|
|
// Create the import statement
|
|
const importDeclaration = babel.types.importDeclaration(
|
|
[],
|
|
babel.types.stringLiteral(setupFile)
|
|
)
|
|
|
|
// Add the import at the beginning of the file
|
|
path.node.body.unshift(importDeclaration)
|
|
|
|
console.log(`[babel-plugin-inject-globals] Injected setup into ${nodePath.basename(filename)}`)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|