From 35e56a441cdbdcba1bed3d47dfd577d68d02048d Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 13 Sep 2025 10:27:34 +0000 Subject: [PATCH] [auto-fix] Apply ESLint and Prettier fixes --- browser_tests/helpers/locationMock.ts | 16 +++-- browser_tests/locationMock.example.test.ts | 15 +++-- scripts/collect-i18n-general.ts | 2 +- scripts/collect-i18n-node-defs.ts | 4 +- scripts/setup-browser-globals.js | 75 ++++++++++++---------- 5 files changed, 64 insertions(+), 48 deletions(-) diff --git a/browser_tests/helpers/locationMock.ts b/browser_tests/helpers/locationMock.ts index d04d48540..766bca072 100644 --- a/browser_tests/helpers/locationMock.ts +++ b/browser_tests/helpers/locationMock.ts @@ -74,12 +74,14 @@ export class LocationMock { /** * Update the mock location during test execution */ - async updateLocation(updates: Partial<{ - href: string - pathname: string - search: string - hash: string - }>) { + async updateLocation( + updates: Partial<{ + href: string + pathname: string + search: string + hash: string + }> + ) { await this.page.evaluate((updates) => { const location = window.location as any Object.keys(updates).forEach((key) => { @@ -139,4 +141,4 @@ export class LocationMock { location.reload() }) } -} \ No newline at end of file +} diff --git a/browser_tests/locationMock.example.test.ts b/browser_tests/locationMock.example.test.ts index 5e73169a3..d0cde7477 100644 --- a/browser_tests/locationMock.example.test.ts +++ b/browser_tests/locationMock.example.test.ts @@ -1,4 +1,5 @@ import { expect } from '@playwright/test' + import { comfyPageFixture as test } from './fixtures/ComfyPage' import { LocationMock } from './helpers/locationMock' @@ -66,9 +67,15 @@ test.describe('Location Mock Example', () => { await locationMock.reload() // Verify mock methods were called - expect(consoleMessages.some((msg) => msg.includes('location.assign'))).toBeTruthy() - expect(consoleMessages.some((msg) => msg.includes('location.replace'))).toBeTruthy() - expect(consoleMessages.some((msg) => msg.includes('location.reload'))).toBeTruthy() + expect( + consoleMessages.some((msg) => msg.includes('location.assign')) + ).toBeTruthy() + expect( + consoleMessages.some((msg) => msg.includes('location.replace')) + ).toBeTruthy() + expect( + consoleMessages.some((msg) => msg.includes('location.reload')) + ).toBeTruthy() }) test('should work with Happy DOM globals', async ({ page, comfyPage }) => { @@ -93,4 +100,4 @@ test.describe('Location Mock Example', () => { expect(location.canReplace).toBeTruthy() expect(location.canReload).toBeTruthy() }) -}) \ No newline at end of file +}) diff --git a/scripts/collect-i18n-general.ts b/scripts/collect-i18n-general.ts index 62cd4bedb..0a6452c8a 100644 --- a/scripts/collect-i18n-general.ts +++ b/scripts/collect-i18n-general.ts @@ -1,4 +1,3 @@ -import './setup-browser-globals.js' import * as fs from 'fs' import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage' @@ -7,6 +6,7 @@ import { SERVER_CONFIG_ITEMS } from '../src/constants/serverConfig' import type { ComfyCommandImpl } from '../src/stores/commandStore' import type { FormItem, SettingParams } from '../src/types/settingTypes' import { formatCamelCase, normalizeI18nKey } from '../src/utils/formatUtil' +import './setup-browser-globals.js' const localePath = './src/locales/en/main.json' const commandsPath = './src/locales/en/commands.json' diff --git a/scripts/collect-i18n-node-defs.ts b/scripts/collect-i18n-node-defs.ts index db1301db3..dc7554fc5 100644 --- a/scripts/collect-i18n-node-defs.ts +++ b/scripts/collect-i18n-node-defs.ts @@ -1,12 +1,12 @@ // Setup browser globals before any other imports that might use them -import './setup-browser-globals.js' - import * as fs from 'fs' + import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage' import type { ComfyNodeDef } from '../src/schemas/nodeDefSchema' import type { ComfyApi } from '../src/scripts/api' import { ComfyNodeDefImpl } from '../src/stores/nodeDefStore' import { normalizeI18nKey } from '../src/utils/formatUtil' +import './setup-browser-globals.js' const localePath = './src/locales/en/main.json' const nodeDefsPath = './src/locales/en/nodeDefs.json' diff --git a/scripts/setup-browser-globals.js b/scripts/setup-browser-globals.js index faf683f73..91d7b5af2 100644 --- a/scripts/setup-browser-globals.js +++ b/scripts/setup-browser-globals.js @@ -1,18 +1,21 @@ // Polyfill browser globals for Node.js context during test imports -import { Window } from 'happy-dom'; +import { Window } from 'happy-dom' // Define build-time constants if (typeof globalThis.__USE_PROD_CONFIG__ === 'undefined') { - globalThis.__USE_PROD_CONFIG__ = false; + globalThis.__USE_PROD_CONFIG__ = false } // Create a happy-dom window instance with configurable URL -const defaultUrl = (typeof globalThis.process !== 'undefined' && globalThis.process.env?.HAPPY_DOM_URL) || 'http://localhost:5173/'; +const defaultUrl = + (typeof globalThis.process !== 'undefined' && + globalThis.process.env?.HAPPY_DOM_URL) || + 'http://localhost:5173/' const window = new Window({ url: defaultUrl, width: 1024, height: 768 -}); +}) // Mock location with additional properties for testing const mockLocation = { @@ -27,65 +30,69 @@ const mockLocation = { search: new URL(defaultUrl).search, hash: new URL(defaultUrl).hash, assign: (url) => { - console.log(`[Mock] location.assign called with: ${url}`); - mockLocation.href = url; + console.log(`[Mock] location.assign called with: ${url}`) + mockLocation.href = url }, replace: (url) => { - console.log(`[Mock] location.replace called with: ${url}`); - mockLocation.href = url; + console.log(`[Mock] location.replace called with: ${url}`) + mockLocation.href = url }, reload: () => { - console.log('[Mock] location.reload called'); + console.log('[Mock] location.reload called') } -}; +} // Expose DOM globals (only set if not already defined) -if (!globalThis.window) globalThis.window = window; -if (!globalThis.document) globalThis.document = window.document; -if (!globalThis.location) globalThis.location = mockLocation; +if (!globalThis.window) globalThis.window = window +if (!globalThis.document) globalThis.document = window.document +if (!globalThis.location) globalThis.location = mockLocation if (!globalThis.navigator) { try { - globalThis.navigator = window.navigator; + globalThis.navigator = window.navigator } catch (e) { // navigator might be read-only in some environments } } -if (!globalThis.HTMLElement) globalThis.HTMLElement = window.HTMLElement; -if (!globalThis.Element) globalThis.Element = window.Element; -if (!globalThis.Node) globalThis.Node = window.Node; -if (!globalThis.NodeList) globalThis.NodeList = window.NodeList; -if (!globalThis.DOMParser) globalThis.DOMParser = window.DOMParser; -if (!globalThis.XMLSerializer) globalThis.XMLSerializer = window.XMLSerializer; -if (!globalThis.localStorage) globalThis.localStorage = window.localStorage; -if (!globalThis.sessionStorage) globalThis.sessionStorage = window.sessionStorage; -if (!globalThis.CustomEvent) globalThis.CustomEvent = window.CustomEvent; -if (!globalThis.Event) globalThis.Event = window.Event; -if (!globalThis.MouseEvent) globalThis.MouseEvent = window.MouseEvent; -if (!globalThis.KeyboardEvent) globalThis.KeyboardEvent = window.KeyboardEvent; -if (!globalThis.getComputedStyle) globalThis.getComputedStyle = window.getComputedStyle; -if (!globalThis.requestAnimationFrame) globalThis.requestAnimationFrame = window.requestAnimationFrame; -if (!globalThis.cancelAnimationFrame) globalThis.cancelAnimationFrame = window.cancelAnimationFrame; +if (!globalThis.HTMLElement) globalThis.HTMLElement = window.HTMLElement +if (!globalThis.Element) globalThis.Element = window.Element +if (!globalThis.Node) globalThis.Node = window.Node +if (!globalThis.NodeList) globalThis.NodeList = window.NodeList +if (!globalThis.DOMParser) globalThis.DOMParser = window.DOMParser +if (!globalThis.XMLSerializer) globalThis.XMLSerializer = window.XMLSerializer +if (!globalThis.localStorage) globalThis.localStorage = window.localStorage +if (!globalThis.sessionStorage) + globalThis.sessionStorage = window.sessionStorage +if (!globalThis.CustomEvent) globalThis.CustomEvent = window.CustomEvent +if (!globalThis.Event) globalThis.Event = window.Event +if (!globalThis.MouseEvent) globalThis.MouseEvent = window.MouseEvent +if (!globalThis.KeyboardEvent) globalThis.KeyboardEvent = window.KeyboardEvent +if (!globalThis.getComputedStyle) + globalThis.getComputedStyle = window.getComputedStyle +if (!globalThis.requestAnimationFrame) + globalThis.requestAnimationFrame = window.requestAnimationFrame +if (!globalThis.cancelAnimationFrame) + globalThis.cancelAnimationFrame = window.cancelAnimationFrame // Add ResizeObserver polyfill if (!globalThis.ResizeObserver) { globalThis.ResizeObserver = class ResizeObserver { constructor(callback) { - this.callback = callback; + this.callback = callback } observe() {} unobserve() {} disconnect() {} - }; + } } // Add IntersectionObserver polyfill if (!globalThis.IntersectionObserver) { globalThis.IntersectionObserver = class IntersectionObserver { constructor(callback) { - this.callback = callback; + this.callback = callback } observe() {} unobserve() {} disconnect() {} - }; -} \ No newline at end of file + } +}