Skip to content

Commit f0fa1fd

Browse files
committed
test: install Pinia before constructing graphs
Amp-Thread-ID: https://ampcode.com/threads/T-019fef81-c9e1-7658-a571-55818c44c32a
1 parent a13af19 commit f0fa1fd

6 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/lib/litegraph/src/LGraphCanvas.linkDragAutoPan.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createTestingPinia } from '@pinia/testing'
2+
import { setActivePinia } from 'pinia'
13
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
24

35
import { LGraph, LGraphCanvas } from '@/lib/litegraph/src/litegraph'
@@ -10,6 +12,7 @@ describe('LGraphCanvas link drag auto-pan', () => {
1012
let canvasElement: HTMLCanvasElement
1113

1214
beforeEach(() => {
15+
setActivePinia(createTestingPinia({ stubActions: false }))
1316
vi.useFakeTimers()
1417

1518
canvasElement = document.createElement('canvas')

src/lib/litegraph/src/LGraphCanvas.onMenuAdd.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createTestingPinia } from '@pinia/testing'
2+
import { setActivePinia } from 'pinia'
13
import { fromPartial } from '@total-typescript/shoehorn'
24
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
35

@@ -60,6 +62,7 @@ describe('LGraphCanvas.onMenuAdd category sorting', () => {
6062
const capturedEntries: MenuEntry[][] = []
6163

6264
beforeEach(() => {
65+
setActivePinia(createTestingPinia({ stubActions: false }))
6366
graph = new LGraph()
6467
canvas = createCanvas(graph)
6568
LGraphCanvas.active_canvas = canvas

src/lib/litegraph/src/LGraphCanvas.renderInfo.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createTestingPinia } from '@pinia/testing'
2+
import { setActivePinia } from 'pinia'
13
import { beforeEach, describe, expect, it, vi } from 'vitest'
24

35
import { LGraph, LGraphCanvas } from '@/lib/litegraph/src/litegraph'
@@ -7,6 +9,7 @@ describe('LGraphCanvas.renderInfo', () => {
79
let ctx: CanvasRenderingContext2D
810

911
beforeEach(() => {
12+
setActivePinia(createTestingPinia({ stubActions: false }))
1013
const canvasElement = document.createElement('canvas')
1114
ctx = {
1215
save: vi.fn(),

src/lib/litegraph/src/LGraphCanvas.titleButtons.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createTestingPinia } from '@pinia/testing'
2+
import { setActivePinia } from 'pinia'
13
import { beforeEach, describe, expect, it, vi } from 'vitest'
24

35
import {
@@ -13,6 +15,7 @@ describe('LGraphCanvas Title Button Rendering', () => {
1315
let node: LGraphNode
1416

1517
beforeEach(() => {
18+
setActivePinia(createTestingPinia({ stubActions: false }))
1619
// Create a mock canvas element
1720
const canvasElement = document.createElement('canvas')
1821
ctx = {

src/lib/litegraph/src/LGraphGroup.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { createUuidv4 } from '@/utils/uuid'
1111

1212
import { test } from './__fixtures__/testExtensions'
1313

14+
beforeEach(() => setActivePinia(createTestingPinia({ stubActions: false })))
15+
1416
describe('LGraphGroup', () => {
1517
test('serializes to the existing format', () => {
1618
const link = new LGraphGroup('title', 929)
@@ -87,9 +89,6 @@ describe('LGraphGroup', () => {
8789
})
8890

8991
describe('group layout in layoutStore', () => {
90-
// graph.add(node) registers node state, which needs a store.
91-
beforeEach(() => setActivePinia(createTestingPinia({ stubActions: false })))
92-
9392
function addedGroup(graph: LGraph, id: GroupId) {
9493
const group = new LGraphGroup('group', id)
9594
group.pos = [100, 100]

src/renderer/extensions/vueNodes/components/LGraphNode.subgraph.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ vi.mock('@/i18n', () => ({
6262
}))
6363

6464
describe('Vue Node - Subgraph Functionality', () => {
65-
const rootGraph = new LGraph()
65+
let rootGraph: LGraph
66+
let pinia: ReturnType<typeof createTestingPinia>
6667

6768
// Helper to setup common mocks
6869
const setupMocks = async (isSubgraph = true, hasGraph = true) => {
@@ -75,6 +76,9 @@ describe('Vue Node - Subgraph Functionality', () => {
7576
}
7677

7778
beforeEach(() => {
79+
pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false })
80+
setActivePinia(pinia)
81+
rootGraph = new LGraph()
7882
vi.clearAllMocks()
7983
})
8084

@@ -90,8 +94,6 @@ describe('Vue Node - Subgraph Functionality', () => {
9094
})
9195

9296
const renderComponent = (props: { nodeData: NodeState }) => {
93-
const pinia = createTestingPinia({ createSpy: vi.fn })
94-
setActivePinia(pinia)
9597
useCanvasStore().currentGraph = rootGraph
9698
return render(LGraphNode, {
9799
props,

0 commit comments

Comments
 (0)