-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
140 lines (129 loc) · 3.72 KB
/
Copy pathvitest.setup.ts
File metadata and controls
140 lines (129 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import {
authMock,
databaseMock,
drizzleOrmMock,
hybridAuthMock,
loggerMock,
requestUtilsMock,
schemaMock,
setupGlobalFetchMock,
setupGlobalStorageMocks,
terminalConsoleMock,
workflowAuthzMock,
} from '@sim/testing'
import { afterAll, vi } from 'vitest'
import '@testing-library/jest-dom/vitest'
setupGlobalFetchMock()
setupGlobalStorageMocks()
vi.mock('@sim/db', () => databaseMock)
vi.mock('@sim/db/schema', () => schemaMock)
vi.mock('drizzle-orm', () => drizzleOrmMock)
vi.mock('@sim/logger', () => loggerMock)
vi.mock('@sim/platform-authz/workflow', () => workflowAuthzMock)
vi.mock('@/lib/auth', () => authMock)
vi.mock('@/lib/auth/hybrid', () => hybridAuthMock)
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
vi.mock('@/stores/console/store', () => ({
useConsoleStore: {
getState: vi.fn().mockReturnValue({
addConsole: vi.fn(),
}),
},
}))
vi.mock('@/stores/terminal', () => terminalConsoleMock)
vi.mock('@/stores/terminal/console/store', () => terminalConsoleMock)
vi.mock('@/stores/execution/store', () => ({
useExecutionStore: {
getState: vi.fn().mockReturnValue({
getWorkflowExecution: vi.fn().mockReturnValue({
status: 'idle',
isExecuting: false,
isDebugging: false,
activeBlockIds: new Set(),
pendingBlocks: [],
executor: null,
debugContext: null,
lastRunPath: new Map(),
lastRunEdges: new Map(),
}),
setStatus: vi.fn(),
setIsExecuting: vi.fn(),
setIsDebugging: vi.fn(),
setPendingBlocks: vi.fn(),
reset: vi.fn(),
setActiveBlocks: vi.fn(),
setBlockRunStatus: vi.fn(),
setEdgeRunStatus: vi.fn(),
clearRunPath: vi.fn(),
}),
},
useCurrentWorkflowExecution: vi.fn().mockReturnValue({
status: 'idle',
isExecuting: false,
isDebugging: false,
activeBlockIds: new Set(),
pendingBlocks: [],
executor: null,
debugContext: null,
lastRunPath: new Map(),
lastRunEdges: new Map(),
}),
useIsBlockActive: vi.fn().mockReturnValue(false),
useIsCurrentWorkflowExecuting: vi.fn().mockReturnValue(false),
useLastRunPath: vi.fn().mockReturnValue(new Map()),
useLastRunEdges: vi.fn().mockReturnValue(new Map()),
}))
vi.mock('@/blocks/registry', () => ({
getBlock: vi.fn(() => ({
name: 'Mock Block',
description: 'Mock block description',
icon: () => null,
subBlocks: [],
outputs: {},
})),
getAllBlocks: vi.fn(() => []),
getLatestBlock: vi.fn(() => undefined),
getBlockByToolName: vi.fn((toolName: string) =>
toolName.startsWith('gmail_')
? {
name: 'Gmail',
description: 'Gmail integration',
icon: () => null,
subBlocks: [],
outputs: {},
}
: undefined
),
}))
vi.mock('@trigger.dev/sdk', () => ({
task: vi.fn(() => ({ trigger: vi.fn() })),
tasks: {
trigger: vi.fn().mockResolvedValue({ id: 'mock-task-id' }),
batchTrigger: vi.fn().mockResolvedValue([{ id: 'mock-task-id' }]),
},
runs: {
retrieve: vi.fn().mockResolvedValue({ id: 'mock-run-id', status: 'COMPLETED' }),
},
configure: vi.fn(),
}))
const originalConsoleError = console.error
const originalConsoleWarn = console.warn
console.error = (...args: any[]) => {
if (args[0] === 'Workflow execution failed:' && args[1]?.message === 'Test error') {
return
}
if (typeof args[0] === 'string' && args[0].includes('[zustand persist middleware]')) {
return
}
originalConsoleError(...args)
}
console.warn = (...args: any[]) => {
if (typeof args[0] === 'string' && args[0].includes('[zustand persist middleware]')) {
return
}
originalConsoleWarn(...args)
}
afterAll(() => {
console.error = originalConsoleError
console.warn = originalConsoleWarn
})