-
Notifications
You must be signed in to change notification settings - Fork 461
Chore: Typescript cleanup (1 / N) #7817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2ef9999
6542975
70adacc
087c298
071213b
c192c7b
31307fa
f8c8e4b
f92f832
a41cbab
34fa21c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,21 +27,18 @@ export class SceneManager implements SceneManagerInterface { | |
| private renderer: THREE.WebGLRenderer | ||
|
|
||
| private getActiveCamera: () => THREE.Camera | ||
| // @ts-expect-error unused variable | ||
| private getControls: () => OrbitControls | ||
|
|
||
| constructor( | ||
| renderer: THREE.WebGLRenderer, | ||
| getActiveCamera: () => THREE.Camera, | ||
| getControls: () => OrbitControls, | ||
| _getControls: () => OrbitControls, | ||
| eventManager: EventManagerInterface | ||
| ) { | ||
| this.renderer = renderer | ||
| this.eventManager = eventManager | ||
| this.scene = new THREE.Scene() | ||
|
|
||
| this.getActiveCamera = getActiveCamera | ||
|
Comment on lines
31
to
41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: rg -n -C3 'new\s+SceneManager\s*\(' --type=tsRepository: Comfy-Org/ComfyUI_frontend Length of output: 531 🏁 Script executed: # Get full context of SceneManager constructor call in Load3d.ts
rg -n -A 5 'this.sceneManager = new SceneManager' src/extensions/core/load3d/Load3d.ts
# Check if _getControls is referenced anywhere in SceneManager
rg -n '_getControls\|getControls\|controls' src/extensions/core/load3d/SceneManager.tsRepository: Comfy-Org/ComfyUI_frontend Length of output: 254 🏁 Script executed: # Check entire SceneManager.ts file structure
cat src/extensions/core/load3d/SceneManager.tsRepository: Comfy-Org/ComfyUI_frontend Length of output: 13165 Remove the unused The 🤖 Prompt for AI Agents |
||
| this.getControls = getControls | ||
|
|
||
| this.gridHelper = new THREE.GridHelper(20, 20) | ||
| this.gridHelper.position.set(0, 0, 0) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { | ||
| LGraph, | ||
| LGraphCanvas, | ||
| LGraphNode, | ||
| LiteGraph | ||
|
|
@@ -46,8 +47,8 @@ describe('LGraphCanvas Title Button Rendering', () => { | |
|
|
||
| canvasElement.getContext = vi.fn().mockReturnValue(ctx) | ||
|
|
||
| // @ts-expect-error TODO: Fix after merge - LGraphCanvas constructor type issues | ||
| canvas = new LGraphCanvas(canvasElement, null, { | ||
| const graph = new LGraph() | ||
| canvas = new LGraphCanvas(canvasElement, graph, { | ||
| skip_render: true, | ||
| skip_events: true | ||
| }) | ||
|
|
@@ -56,43 +57,41 @@ describe('LGraphCanvas Title Button Rendering', () => { | |
| node.pos = [100, 200] | ||
| node.size = [200, 100] | ||
|
|
||
| // Mock required methods | ||
| node.drawTitleBarBackground = vi.fn() | ||
| // @ts-expect-error Property 'drawTitleBarText' does not exist on type 'LGraphNode' | ||
| node.drawTitleBarText = vi.fn() | ||
| node.drawBadges = vi.fn() | ||
| // @ts-expect-error TODO: Fix after merge - drawToggles not defined in type | ||
| node.drawToggles = vi.fn() | ||
| // @ts-expect-error TODO: Fix after merge - drawNodeShape not defined in type | ||
| node.drawNodeShape = vi.fn() | ||
| node.drawSlots = vi.fn() | ||
| // @ts-expect-error TODO: Fix after merge - drawContent not defined in type | ||
| node.drawContent = vi.fn() | ||
| node.drawWidgets = vi.fn() | ||
| node.drawCollapsedSlots = vi.fn() | ||
| node.drawTitleBox = vi.fn() | ||
| node.drawTitleText = vi.fn() | ||
| node.drawProgressBar = vi.fn() | ||
| node._setConcreteSlots = vi.fn() | ||
| node.arrange = vi.fn() | ||
| // @ts-expect-error TODO: Fix after merge - isSelectable not defined in type | ||
| node.isSelectable = vi.fn().mockReturnValue(true) | ||
|
|
||
| const nodeWithMocks = node as LGraphNode & { | ||
| drawTitleBarText: ReturnType<typeof vi.fn> | ||
| drawToggles: ReturnType<typeof vi.fn> | ||
| drawNodeShape: ReturnType<typeof vi.fn> | ||
| drawContent: ReturnType<typeof vi.fn> | ||
| isSelectable: ReturnType<typeof vi.fn> | ||
| } | ||
| nodeWithMocks.drawTitleBarText = vi.fn() | ||
| nodeWithMocks.drawToggles = vi.fn() | ||
| nodeWithMocks.drawNodeShape = vi.fn() | ||
| nodeWithMocks.drawContent = vi.fn() | ||
| nodeWithMocks.isSelectable = vi.fn().mockReturnValue(true) | ||
|
Comment on lines
+70
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial
The Consider simplifying by assigning mocks directly to 🔎 Suggested simplification- const nodeWithMocks = node as LGraphNode & {
- drawTitleBarText: ReturnType<typeof vi.fn>
- drawToggles: ReturnType<typeof vi.fn>
- drawNodeShape: ReturnType<typeof vi.fn>
- drawContent: ReturnType<typeof vi.fn>
- isSelectable: ReturnType<typeof vi.fn>
- }
- nodeWithMocks.drawTitleBarText = vi.fn()
- nodeWithMocks.drawToggles = vi.fn()
- nodeWithMocks.drawNodeShape = vi.fn()
- nodeWithMocks.drawContent = vi.fn()
- nodeWithMocks.isSelectable = vi.fn().mockReturnValue(true)
+ // Assign additional mocks needed by drawNode
+ ;(node as LGraphNode & { drawTitleBarText: unknown }).drawTitleBarText = vi.fn()
+ ;(node as LGraphNode & { drawToggles: unknown }).drawToggles = vi.fn()
+ ;(node as LGraphNode & { drawNodeShape: unknown }).drawNodeShape = vi.fn()
+ ;(node as LGraphNode & { drawContent: unknown }).drawContent = vi.fn()
+ ;(node as LGraphNode & { isSelectable: unknown }).isSelectable = vi.fn().mockReturnValue(true)Or alternatively, use 🤖 Prompt for AI Agents |
||
| }) | ||
|
|
||
| describe('drawNode title button rendering', () => { | ||
| it('should render visible title buttons', () => { | ||
| const button1 = node.addTitleButton({ | ||
| name: 'button1', | ||
| text: 'A', | ||
| // @ts-expect-error TODO: Fix after merge - visible property not in LGraphButtonOptions | ||
| visible: true | ||
| text: 'A' | ||
| }) | ||
|
|
||
| const button2 = node.addTitleButton({ | ||
| name: 'button2', | ||
| text: 'B', | ||
| // @ts-expect-error TODO: Fix after merge - visible property not in LGraphButtonOptions | ||
| visible: true | ||
| text: 'B' | ||
| }) | ||
|
|
||
| // Mock button methods | ||
|
|
@@ -127,9 +126,7 @@ describe('LGraphCanvas Title Button Rendering', () => { | |
| it('should skip invisible title buttons', () => { | ||
| const visibleButton = node.addTitleButton({ | ||
| name: 'visible', | ||
| text: 'V', | ||
| // @ts-expect-error TODO: Fix after merge - visible property not in LGraphButtonOptions | ||
| visible: true | ||
| text: 'V' | ||
| }) | ||
|
|
||
| const invisibleButton = node.addTitleButton({ | ||
|
|
@@ -171,9 +168,7 @@ describe('LGraphCanvas Title Button Rendering', () => { | |
| for (let i = 0; i < 3; i++) { | ||
| const button = node.addTitleButton({ | ||
| name: `button${i}`, | ||
| text: String(i), | ||
| // @ts-expect-error TODO: Fix after merge - visible property not in LGraphButtonOptions | ||
| visible: true | ||
| text: String(i) | ||
| }) | ||
| button.getWidth = vi.fn().mockReturnValue(15) // All same width for simplicity | ||
| const spy = vi.spyOn(button, 'draw') | ||
|
|
@@ -196,18 +191,12 @@ describe('LGraphCanvas Title Button Rendering', () => { | |
| it('should render buttons in low quality mode', () => { | ||
| const button = node.addTitleButton({ | ||
| name: 'test', | ||
| text: 'T', | ||
| // @ts-expect-error TODO: Fix after merge - visible property not in LGraphButtonOptions | ||
| visible: true | ||
| text: 'T' | ||
| }) | ||
|
|
||
| button.getWidth = vi.fn().mockReturnValue(20) | ||
| const drawSpy = vi.spyOn(button, 'draw') | ||
|
|
||
| // Set low quality rendering | ||
| // @ts-expect-error TODO: Fix after merge - lowQualityRenderingRequired not defined in type | ||
| canvas.lowQualityRenderingRequired = true | ||
|
|
||
| canvas.drawNode(node, ctx) | ||
|
|
||
| // Buttons should still be rendered in low quality mode | ||
|
|
@@ -219,16 +208,12 @@ describe('LGraphCanvas Title Button Rendering', () => { | |
| it('should handle buttons with different widths', () => { | ||
| const smallButton = node.addTitleButton({ | ||
| name: 'small', | ||
| text: 'S', | ||
| // @ts-expect-error TODO: Fix after merge - visible property not in LGraphButtonOptions | ||
| visible: true | ||
| text: 'S' | ||
| }) | ||
|
|
||
| const largeButton = node.addTitleButton({ | ||
| name: 'large', | ||
| text: 'LARGE', | ||
| // @ts-expect-error TODO: Fix after merge - visible property not in LGraphButtonOptions | ||
| visible: true | ||
| text: 'LARGE' | ||
| }) | ||
|
|
||
| smallButton.getWidth = vi.fn().mockReturnValue(15) | ||
|
|
@@ -256,9 +241,7 @@ describe('LGraphCanvas Title Button Rendering', () => { | |
|
|
||
| const button = node.addTitleButton({ | ||
| name: 'test', | ||
| text: 'X', | ||
| // @ts-expect-error TODO: Fix after merge - visible property not in LGraphButtonOptions | ||
| visible: true | ||
| text: 'X' | ||
| }) | ||
|
|
||
| button.getWidth = vi.fn().mockReturnValue(20) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silent failure: early return without notification.
The early return when
nodeDefis undefined causesregisterTypeto fail silently. This could make debugging difficult if something goes wrong during node definition construction.🔎 Consider adding error logging or throwing an error