Repository navigation
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
148 lines (129 loc) · 3.62 KB
/
Copy pathvitest.setup.ts
File metadata and controls
148 lines (129 loc) · 3.62 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
141
142
143
144
145
146
147
148
import '@testing-library/jest-dom'
import React from 'react'
import { vi } from 'vitest'
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: (query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: () => {},
removeListener: () => {},
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => false
})
})
class ResizeObserverMock {
observe() {}
unobserve() {}
disconnect() {}
}
window.ResizeObserver = ResizeObserverMock
// jsdom has no Element.scrollTo; Streamdown pins streaming code blocks to the bottom with it.
if (typeof Element.prototype.scrollTo !== 'function') {
Element.prototype.scrollTo = (() => {}) as typeof Element.prototype.scrollTo
}
class IntersectionObserverMock {
observe() {}
unobserve() {}
disconnect() {}
takeRecords() {
return []
}
}
window.IntersectionObserver = IntersectionObserverMock as unknown as typeof IntersectionObserver
vi.mock('@tauri-apps/api/core', () => ({
invoke: vi.fn()
}))
// Desktop-context suites script the ACP carrier through the `invoke` mock above:
// swap the real `/ws`-over-Channel `DesktopAcpTransport` for the invoke-backed
// double. Suites that test the real class call `vi.unmock` on this module.
vi.mock('@/lib/acp-transport/desktop-transport', async () => {
// Non-literal specifier: this setup file belongs to the node tsconfig project,
// which must not pull renderer sources into its file list.
const double = './src/renderer/lib/test-utils/invoke-acp-transport'
const { createInvokeAcpTransport } = await import(/* @vite-ignore */ double)
return {
DESKTOP_CHANNEL_URL: 'channel://desktop',
// A plain function: `new` yields the returned transport object.
DesktopAcpTransport: function DesktopAcpTransport() {
return createInvokeAcpTransport()
}
}
})
vi.mock('@tauri-apps/api/event', () => ({
listen: vi.fn(() => Promise.resolve(() => {}))
}))
vi.mock('@tauri-apps/plugin-fs', () => ({
readDir: vi.fn(),
readFile: vi.fn(),
readTextFile: vi.fn(),
writeFile: vi.fn(),
writeTextFile: vi.fn(),
mkdir: vi.fn(),
remove: vi.fn(),
rename: vi.fn(),
stat: vi.fn(),
watchImmediate: vi.fn()
}))
vi.mock('@tauri-apps/plugin-dialog', () => ({
open: vi.fn(),
save: vi.fn(),
message: vi.fn(),
confirm: vi.fn()
}))
vi.mock('@tauri-apps/plugin-clipboard-manager', () => ({
readText: vi.fn(),
writeText: vi.fn(),
readImage: vi.fn(),
writeImage: vi.fn()
}))
vi.mock('@tauri-apps/plugin-store', () => ({
createStore: vi.fn()
}))
vi.mock('@tauri-apps/plugin-os', () => ({
platform: vi.fn(),
version: vi.fn(),
type: vi.fn(),
arch: vi.fn(),
tempdir: vi.fn(),
homedir: vi.fn()
}))
vi.mock('@tauri-apps/plugin-shell', () => ({
Command: vi.fn(),
open: vi.fn()
}))
vi.mock('@tauri-apps/plugin-opener', () => ({
openPath: vi.fn(),
openUrl: vi.fn(),
revealItemInDir: vi.fn()
}))
vi.mock('react-virtuoso', () => {
const VirtuosoComponent = React.forwardRef(
(
{
data,
itemContent
}: {
data: unknown[]
itemContent: (index: number, item: unknown) => React.JSX.Element
},
_ref: React.Ref<unknown>
) => {
return React.createElement(
'div',
{ 'data-testid': 'virtuoso-scroller', 'data-virtuoso-scroller': 'true' },
React.createElement(
'div',
{ 'data-testid': 'virtuoso-item-list' },
data.map((item, index) =>
React.createElement('div', { key: index }, itemContent(index, item))
)
)
)
}
)
VirtuosoComponent.displayName = 'Virtuoso'
return { Virtuoso: VirtuosoComponent }
})