Files
ComfyUI_frontend/src/extensions/core/saveImageExtraOutput.test.ts
Terry Jia 5da5ee5031 feat: wire up Save 3D (Advanced) node family (CORE-329) (#13330)
## Summary
Register the save-side advanced nodes in the Load3D viewer
infrastructure: Save3DAdvanced reuses the mesh advanced extension, while
SaveGaussianSplat and SavePointCloud reuse the splat/point cloud preview
extensions.

Parameterize both extension factories with a loadFolder so save nodes
load the persisted file from the output folder instead of temp, and add
the node types to the lazy-load and viewport-state sets.

BE change https://github.com/Comfy-Org/ComfyUI/pull/14701
## Screenshots (if applicable)
Save 3D (Advanced)
<img width="1328" height="939" alt="image"
src="https://github.com/user-attachments/assets/c5f3cbe0-6e57-463c-9128-67490c2fc89e"
/>

Save Splat
<img width="1296" height="1052" alt="image"
src="https://github.com/user-attachments/assets/f05bbcf8-9794-4861-9dd7-3015d38b11d9"
/>
2026-07-10 15:39:51 +00:00

105 lines
2.5 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { LGraph } from '@/lib/litegraph/src/litegraph'
import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
import type { ComfyExtension } from '@/types/comfy'
const { app } = vi.hoisted(() => ({
app: {
registerExtension: vi.fn(),
graph: undefined as unknown as LGraph
}
}))
vi.mock('@/scripts/app', () => ({ app }))
type BeforeRegisterNodeDef = NonNullable<
ComfyExtension['beforeRegisterNodeDef']
>
interface FilenamePrefixWidget {
name: string
value: unknown
serializeValue?: () => string
}
async function loadExtension(): Promise<ComfyExtension> {
vi.resetModules()
app.registerExtension.mockClear()
await import('./saveImageExtraOutput')
return app.registerExtension.mock.calls[0][0] as ComfyExtension
}
async function createNodeWithFilenamePrefix(
nodeName: string,
prefix: string
): Promise<FilenamePrefixWidget> {
const ext = await loadExtension()
const nodeType = {
prototype: {}
} as unknown as Parameters<BeforeRegisterNodeDef>[0]
const nodeData = { name: nodeName } as ComfyNodeDef
await ext.beforeRegisterNodeDef!(
nodeType,
nodeData,
{} as Parameters<BeforeRegisterNodeDef>[2]
)
const widget: FilenamePrefixWidget = {
name: 'filename_prefix',
value: prefix
}
const node = { widgets: [widget] }
const proto = nodeType.prototype as { onNodeCreated?: () => void }
proto.onNodeCreated!.call(node)
return widget
}
describe('Comfy.SaveImageExtraOutput', () => {
beforeEach(() => {
const graph = new LGraph()
graph.add({
properties: { 'Node name for S&R': 'Sampler' },
widgets: [{ name: 'seed', value: 12345 }]
} as unknown as LGraphNode)
app.graph = graph
})
it.each([
'SaveImage',
'SaveImageAdvanced',
'SaveSVGNode',
'SaveVideo',
'SaveAnimatedWEBP',
'SaveWEBM',
'SaveAudio',
'SaveAudioMP3',
'SaveAudioOpus',
'SaveAudioAdvanced',
'SaveGLB',
'Save3DAdvanced',
'SaveGaussianSplat',
'SavePointCloud',
'SaveAnimatedPNG',
'CLIPSave',
'VAESave',
'ModelSave',
'LoraSave',
'SaveLatent'
])(
'resolves text replacements in the filename_prefix of %s on serialize',
async (nodeName) => {
const widget = await createNodeWithFilenamePrefix(
nodeName,
'ComfyUI_%Sampler.seed%'
)
expect(widget.serializeValue!()).toBe('ComfyUI_12345')
}
)
})