mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-08 00:50:05 +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.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
/**
|
|
* Setup browser globals for i18n collection in Node.js environment
|
|
*
|
|
* This file is imported at the top of i18n collection test files to provide
|
|
* browser globals that are referenced in the codebase but not available in Node.js
|
|
*/
|
|
|
|
import { JSDOM } from 'jsdom'
|
|
|
|
// Create a minimal JSDOM instance
|
|
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>', {
|
|
url: 'http://localhost:5173',
|
|
pretendToBeVisual: true,
|
|
resources: 'usable'
|
|
})
|
|
|
|
// Set up global window and document
|
|
global.window = dom.window
|
|
global.document = dom.window.document
|
|
|
|
// Use defineProperty for read-only globals
|
|
Object.defineProperty(global, 'navigator', {
|
|
value: dom.window.navigator,
|
|
writable: true,
|
|
configurable: true
|
|
})
|
|
|
|
// Set up other common browser globals
|
|
global.HTMLElement = dom.window.HTMLElement
|
|
global.Element = dom.window.Element
|
|
global.Node = dom.window.Node
|
|
global.NodeList = dom.window.NodeList
|
|
global.MutationObserver = dom.window.MutationObserver
|
|
global.ResizeObserver = dom.window.ResizeObserver || class ResizeObserver {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
}
|
|
global.IntersectionObserver = dom.window.IntersectionObserver || class IntersectionObserver {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
}
|
|
|
|
// Set up basic localStorage and sessionStorage
|
|
global.localStorage = {
|
|
getItem: () => null,
|
|
setItem: () => {},
|
|
removeItem: () => {},
|
|
clear: () => {}
|
|
}
|
|
global.sessionStorage = {
|
|
getItem: () => null,
|
|
setItem: () => {},
|
|
removeItem: () => {},
|
|
clear: () => {}
|
|
}
|
|
|
|
// Mock requestAnimationFrame
|
|
global.requestAnimationFrame = (callback) => setTimeout(callback, 0)
|
|
global.cancelAnimationFrame = (id) => clearTimeout(id)
|