Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/testing/store-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Basic setup for testing Pinia stores:

```typescript
// Example from: tests-ui/tests/store/workflowStore.test.ts
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { useWorkflowStore } from '@/domains/workflow/ui/stores/workflowStore'
Expand All @@ -27,8 +28,8 @@ describe('useWorkflowStore', () => {
let store: ReturnType<typeof useWorkflowStore>

beforeEach(() => {
// Create a fresh pinia and activate it for each test
setActivePinia(createPinia())
// Create a fresh testing pinia and activate it for each test
setActivePinia(createTestingPinia({ stubActions: false }))

// Initialize the store
store = useWorkflowStore()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type * as VueI18nModule from 'vue-i18n'

Expand Down Expand Up @@ -79,7 +80,7 @@ describe('useSubscriptionCredits', () => {
let authStore: ReturnType<typeof useFirebaseAuthStore>

beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
authStore = useFirebaseAuthStore()
vi.clearAllMocks()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { until } from '@vueuse/core'
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ref } from 'vue'

Expand Down Expand Up @@ -40,7 +41,7 @@ describe('useVersionCompatibilityStore', () => {
let mockSettingStore: { get: ReturnType<typeof vi.fn> }

beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))

// Clear the mock dismissal storage
mockDismissalStorage.value = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { nextTick } from 'vue'

Expand Down Expand Up @@ -66,7 +67,7 @@ describe('useWorkflowStore', () => {
}

beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
store = useWorkflowStore()
bookmarkStore = useWorkflowBookmarkStore()
vi.clearAllMocks()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type * as I18n from 'vue-i18n'

Expand Down Expand Up @@ -108,7 +109,7 @@ describe('useWorkflowPersistence', () => {
beforeEach(() => {
vi.useFakeTimers()
vi.setSystemTime(new Date('2025-01-01T00:00:00Z'))
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
localStorage.clear()
sessionStorage.clear()
vi.clearAllMocks()
Expand Down
5 changes: 3 additions & 2 deletions src/platform/workspace/stores/teamWorkspaceStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

import { useTeamWorkspaceStore } from './teamWorkspaceStore'
Expand Down Expand Up @@ -111,7 +112,7 @@ const mockMemberWorkspace = {

describe('useTeamWorkspaceStore', () => {
beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
vi.clearAllMocks()
vi.stubGlobal('localStorage', mockLocalStorage)
sessionStorage.clear()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { useSettingStore } from '@/platform/settings/settingStore'
Expand All @@ -15,7 +16,7 @@ vi.mock('@/stores/workspace/colorPaletteStore', () => ({

describe('useMinimapSettings', () => {
beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
vi.clearAllMocks()
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createTestingPinia } from '@pinia/testing'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import { setActivePinia } from 'pinia'
import PrimeVue from 'primevue/config'
import InputText from 'primevue/inputtext'
import { describe, expect, it, vi } from 'vitest'
Expand Down Expand Up @@ -29,7 +30,7 @@ const makeNodeData = (overrides: Partial<VueNodeData> = {}): VueNodeData => ({
})

const setupMockStores = () => {
const pinia = createPinia()
const pinia = createTestingPinia({ stubActions: false })
setActivePinia(pinia)

const settingStore = useSettingStore()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable vue/one-component-per-file */
import { createTestingPinia } from '@pinia/testing'
import { mount } from '@vue/test-utils'
import { createPinia } from 'pinia'
import { describe, expect, it } from 'vitest'
import { defineComponent } from 'vue'
import type { PropType } from 'vue'
Expand Down Expand Up @@ -84,7 +84,7 @@ const mountSlots = (nodeData: VueNodeData, readonly = false) => {
})
return mount(NodeSlots, {
global: {
plugins: [i18n, createPinia()],
plugins: [i18n, createTestingPinia({ stubActions: false })],
stubs: {
InputSlot: InputSlotStub,
OutputSlot: OutputSlotStub
Expand Down
5 changes: 3 additions & 2 deletions src/services/keybindingService.escape.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { CORE_KEYBINDINGS } from '@/constants/coreKeybindings'
Expand Down Expand Up @@ -30,7 +31,7 @@ describe('keybindingService - Escape key handling', () => {

beforeEach(() => {
vi.clearAllMocks()
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))

// Mock command store execute
const commandStore = useCommandStore()
Expand Down
5 changes: 3 additions & 2 deletions src/services/keybindingService.forwarding.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { app } from '@/scripts/app'
Expand Down Expand Up @@ -68,7 +69,7 @@ describe('keybindingService - Event Forwarding', () => {

beforeEach(() => {
vi.clearAllMocks()
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))

// Mock command store execute
const commandStore = useCommandStore()
Expand Down
5 changes: 3 additions & 2 deletions src/stores/comfyRegistryStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ref } from 'vue'

Expand Down Expand Up @@ -83,7 +84,7 @@ describe('useComfyRegistryStore', () => {
}

beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
vi.clearAllMocks()
mockRegistryService = {
isLoading: ref(false),
Expand Down
5 changes: 3 additions & 2 deletions src/stores/dialogStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it } from 'vitest'
import { defineComponent } from 'vue'

Expand All @@ -11,7 +12,7 @@ const MockComponent = defineComponent({

describe('dialogStore', () => {
beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
})

describe('priority system', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/stores/domWidgetStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it } from 'vitest'

import { useDomWidgetStore } from '@/stores/domWidgetStore'
Expand Down Expand Up @@ -30,7 +31,7 @@ describe('domWidgetStore', () => {
let store: ReturnType<typeof useDomWidgetStore>

beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
store = useDomWidgetStore()
})

Expand Down
7 changes: 4 additions & 3 deletions src/stores/executionStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { app } from '@/scripts/app'
Expand Down Expand Up @@ -59,7 +60,7 @@ describe('useExecutionStore - NodeLocatorId conversions', () => {
mockNodeIdToNodeLocatorId.mockReset()
mockNodeLocatorIdToNodeExecutionId.mockReset()

setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
store = useExecutionStore()
})

Expand Down Expand Up @@ -137,7 +138,7 @@ describe('useExecutionStore - Node Error Lookups', () => {

beforeEach(() => {
vi.clearAllMocks()
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
store = useExecutionStore()
})

Expand Down
7 changes: 4 additions & 3 deletions src/stores/firebaseAuthStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FirebaseError } from 'firebase/app'
import * as firebaseAuth from 'firebase/auth'
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import * as vuefire from 'vuefire'

Expand Down Expand Up @@ -153,7 +154,7 @@ describe('useFirebaseAuthStore', () => {
})

// Initialize Pinia
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
store = useFirebaseAuthStore()

// Reset and set up getIdToken mock
Expand All @@ -175,7 +176,7 @@ describe('useFirebaseAuthStore', () => {

vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(mockAuth as any)

setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
store = useFirebaseAuthStore()
})

Expand Down
5 changes: 3 additions & 2 deletions src/stores/imagePreviewStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
Expand Down Expand Up @@ -30,7 +31,7 @@ const createMockOutputs = (

describe('imagePreviewStore getPreviewParam', () => {
beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
vi.clearAllMocks()
vi.mocked(litegraphUtil.isVideoNode).mockReturnValue(false)
})
Expand Down
5 changes: 3 additions & 2 deletions src/stores/keybindingStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it } from 'vitest'

import { KeybindingImpl, useKeybindingStore } from '@/stores/keybindingStore'

describe('useKeybindingStore', () => {
beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
})

it('should add and retrieve default keybindings', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/stores/modelStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { assetService } from '@/platform/assets/services/assetService'
Expand Down Expand Up @@ -89,7 +90,7 @@ describe('useModelStore', () => {
let store: ReturnType<typeof useModelStore>

beforeEach(async () => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
vi.resetAllMocks()
})

Expand Down
9 changes: 5 additions & 4 deletions src/stores/modelToNodeStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema'
Expand Down Expand Up @@ -82,7 +83,7 @@ vi.mock('@/stores/nodeDefStore', async (importOriginal) => {

describe('useModelToNodeStore', () => {
beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
vi.clearAllMocks()
})

Expand Down Expand Up @@ -330,7 +331,7 @@ describe('useModelToNodeStore', () => {

it('should not register when nodeDefStore is empty', () => {
// Create fresh Pinia for this test to avoid state persistence
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))

vi.mocked(useNodeDefStore, { partial: true }).mockReturnValue({
nodeDefsByName: {}
Expand All @@ -355,7 +356,7 @@ describe('useModelToNodeStore', () => {

it('should return empty Record when nodeDefStore is empty', () => {
// Create fresh Pinia for this test to avoid state persistence
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))

vi.mocked(useNodeDefStore, { partial: true }).mockReturnValue({
nodeDefsByName: {}
Expand Down
5 changes: 3 additions & 2 deletions src/stores/nodeDefStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it } from 'vitest'

import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
Expand All @@ -9,7 +10,7 @@ describe('useNodeDefStore', () => {
let store: ReturnType<typeof useNodeDefStore>

beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
store = useNodeDefStore()
})

Expand Down
5 changes: 3 additions & 2 deletions src/stores/queueStore.loadWorkflow.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createPinia, setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import type {
Expand Down Expand Up @@ -71,7 +72,7 @@ describe('TaskItemImpl.loadWorkflow - workflow fetching', () => {
let mockFetchApi: ReturnType<typeof vi.fn>

beforeEach(() => {
setActivePinia(createPinia())
setActivePinia(createTestingPinia({ stubActions: false }))
vi.clearAllMocks()

mockFetchApi = vi.fn()
Expand Down
Loading