Skip to content

Commit 70604e6

Browse files
christian-byrneampagent
authored andcommitted
test: type the serialized payload instead of relying on JSON.parse's any
1 parent 6cdb6b7 commit 70604e6

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/lib/litegraph/src/LGraph.configureStoreScope.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, test } from 'vitest'
22

3+
import type { ISerialisedGraph } from '@/lib/litegraph/src/litegraph'
34
import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph'
45
import { usePreviewExposureStore } from '@/stores/previewExposureStore'
56
import { renameWidget } from '@/utils/widgetUtil'
@@ -37,16 +38,20 @@ describe('LGraph.configure clears graph-scoped stores for the incoming id', () =
3738
return { graph, node }
3839
}
3940

41+
function serializeToJson(graph: LGraph): ISerialisedGraph {
42+
return JSON.parse(JSON.stringify(graph.serialize())) as ISerialisedGraph
43+
}
44+
4045
test('a reloaded widget label is read from the payload, never inherited from the live store', () => {
4146
const graph = new LGraph()
4247
const dropped = addLabelledNode(graph, 'Dropped Label')
4348
const kept = addLabelledNode(graph, 'Kept Label')
4449

45-
const payload = JSON.parse(JSON.stringify(graph.serialize()))
50+
const payload = serializeToJson(graph)
4651
const droppedData = payload.nodes.find(
47-
(n: { id: unknown }) => String(n.id) === String(dropped.id)
48-
)
49-
delete droppedData.inputs[0].label
52+
(n) => String(n.id) === String(dropped.id)
53+
)!
54+
delete droppedData.inputs![0].label
5055

5156
const restored = new LGraph()
5257
restored.configure(payload)
@@ -63,7 +68,7 @@ describe('LGraph.configure clears graph-scoped stores for the incoming id', () =
6368
{ sourceNodeId: '1', sourcePreviewName: 'preview', name: 'preview' }
6469
])
6570

66-
const payload = JSON.parse(JSON.stringify(graph.serialize()))
71+
const payload = serializeToJson(graph)
6772

6873
const restored = new LGraph()
6974
restored.configure(payload)

0 commit comments

Comments
 (0)