This repository was archived by the owner on May 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathquilt.browser.test.ts
More file actions
372 lines (320 loc) · 10.5 KB
/
Copy pathquilt.browser.test.ts
File metadata and controls
372 lines (320 loc) · 10.5 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import { describe, test, expect, vi, beforeEach } from 'vitest'
import {
getQuiltGames,
getQuiltLoaders,
getQuiltLoaderVersionsByMinecraft,
QuiltLoaderArtifact,
GetQuiltOptions,
DEFAULT_META_URL_QUILT,
} from './quilt.browser'
import { FabricArtifactVersion } from './fabric.browser'
describe('quilt.browser', () => {
beforeEach(() => {
vi.clearAllMocks()
})
describe('getQuiltGames', () => {
test('should fetch quilt game versions', async () => {
const mockGames = [{ version: '1.20.1' }, { version: '1.19.4' }, { version: '23w31a' }]
const mockFetch = vi.fn().mockResolvedValue({
json: async () => mockGames,
})
const result = await getQuiltGames({ fetch: mockFetch })
expect(mockFetch).toHaveBeenCalledWith('https://meta.quiltmc.org/v3/game', expect.any(Object))
expect(result).toEqual(['1.20.1', '1.19.4', '23w31a'])
expect(result).toHaveLength(3)
})
test('should use custom signal', async () => {
const controller = new AbortController()
const mockFetch = vi.fn().mockResolvedValue({
json: async () => [],
})
await getQuiltGames({
fetch: mockFetch,
signal: controller.signal,
})
expect(mockFetch).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({ signal: controller.signal }),
)
})
test('should work without options', async () => {
const mockFetch = vi.spyOn(global, 'fetch').mockResolvedValue({
json: async () => [],
} as any)
const result = await getQuiltGames()
expect(result).toEqual([])
mockFetch.mockRestore()
})
test('should handle empty game list', async () => {
const mockFetch = vi.fn().mockResolvedValue({
json: async () => [],
})
const result = await getQuiltGames({ fetch: mockFetch })
expect(result).toEqual([])
})
test('should extract version strings from response', async () => {
const mockGames = [{ version: '1.20.1' }, { version: '1.19.4' }, { version: '1.18.2' }]
const mockFetch = vi.fn().mockResolvedValue({
json: async () => mockGames,
})
const result = await getQuiltGames({ fetch: mockFetch })
expect(result).toEqual(['1.20.1', '1.19.4', '1.18.2'])
})
})
describe('getQuiltLoaders', () => {
test('should fetch quilt loader versions', async () => {
const mockLoaders: FabricArtifactVersion[] = [
{ version: '0.19.2', maven: 'org.quiltmc:quilt-loader:0.19.2', stable: true },
{ version: '0.19.1', maven: 'org.quiltmc:quilt-loader:0.19.1', stable: true },
{
version: '0.19.0-beta.1',
maven: 'org.quiltmc:quilt-loader:0.19.0-beta.1',
stable: false,
},
]
const mockFetch = vi.fn().mockResolvedValue({
json: async () => mockLoaders,
})
const result = await getQuiltLoaders({ fetch: mockFetch })
expect(mockFetch).toHaveBeenCalledWith(
'https://meta.quiltmc.org/v3/versions/loader',
expect.any(Object),
)
expect(result).toEqual(mockLoaders)
expect(result).toHaveLength(3)
})
test('should use custom signal', async () => {
const controller = new AbortController()
const mockFetch = vi.fn().mockResolvedValue({
json: async () => [],
})
await getQuiltLoaders({
fetch: mockFetch,
signal: controller.signal,
})
expect(mockFetch).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({ signal: controller.signal }),
)
})
test('should work without options', async () => {
const mockFetch = vi.spyOn(global, 'fetch').mockResolvedValue({
json: async () => [],
} as any)
const result = await getQuiltLoaders()
expect(result).toEqual([])
mockFetch.mockRestore()
})
test('should handle empty loader list', async () => {
const mockFetch = vi.fn().mockResolvedValue({
json: async () => [],
})
const result = await getQuiltLoaders({ fetch: mockFetch })
expect(result).toEqual([])
})
test('should differentiate stable and beta versions', async () => {
const mockLoaders: FabricArtifactVersion[] = [
{ version: '0.19.2', maven: 'org.quiltmc:quilt-loader:0.19.2', stable: true },
{
version: '0.19.0-beta.1',
maven: 'org.quiltmc:quilt-loader:0.19.0-beta.1',
stable: false,
},
]
const mockFetch = vi.fn().mockResolvedValue({
json: async () => mockLoaders,
})
const result = await getQuiltLoaders({ fetch: mockFetch })
expect(result.filter((l) => l.stable)).toHaveLength(1)
expect(result.filter((l) => !l.stable)).toHaveLength(1)
})
})
describe('getQuiltLoaderVersionsByMinecraft', () => {
test('should fetch quilt loader versions for specific minecraft version', async () => {
const mockVersions: QuiltLoaderArtifact[] = [
{
loader: {
separator: '.',
build: 2,
maven: 'org.quiltmc:quilt-loader:0.19.2',
version: '0.19.2',
stable: true,
},
intermediary: {
maven: 'org.quiltmc:intermediary:1.20.1',
version: '1.20.1',
stable: true,
},
launcherMeta: {
version: 1,
libraries: {
client: [],
common: [],
server: [],
},
mainClass: {
client: 'net.fabricmc.loader.launch.knot.KnotClient',
server: 'net.fabricmc.loader.launch.knot.KnotServer',
},
},
hashed: {
maven: 'org.quiltmc:hashed:1.20.1',
version: '1.20.1',
stable: true,
},
},
]
const mockFetch = vi.fn().mockResolvedValue({
json: async () => mockVersions,
})
const result = await getQuiltLoaderVersionsByMinecraft({
fetch: mockFetch,
minecraftVersion: '1.20.1',
})
expect(mockFetch).toHaveBeenCalledWith(
'https://meta.quiltmc.org/v3/versions/loader/1.20.1',
expect.any(Object),
)
expect(result).toEqual(mockVersions)
expect(result).toHaveLength(1)
})
test('should use custom signal', async () => {
const controller = new AbortController()
const mockFetch = vi.fn().mockResolvedValue({
json: async () => [],
})
await getQuiltLoaderVersionsByMinecraft({
fetch: mockFetch,
signal: controller.signal,
minecraftVersion: '1.20.1',
})
expect(mockFetch).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({ signal: controller.signal }),
)
})
test('should handle different minecraft versions', async () => {
const versions = ['1.20.1', '1.19.4', '1.18.2', '1.16.5']
const mockFetch = vi.fn().mockResolvedValue({
json: async () => [],
})
for (const version of versions) {
await getQuiltLoaderVersionsByMinecraft({
fetch: mockFetch,
minecraftVersion: version,
})
expect(mockFetch).toHaveBeenCalledWith(
`https://meta.quiltmc.org/v3/versions/loader/${version}`,
expect.any(Object),
)
}
})
test('should handle empty loader list for minecraft version', async () => {
const mockFetch = vi.fn().mockResolvedValue({
json: async () => [],
})
const result = await getQuiltLoaderVersionsByMinecraft({
fetch: mockFetch,
minecraftVersion: '1.20.1',
})
expect(result).toEqual([])
})
test('should handle snapshot versions', async () => {
const mockFetch = vi.fn().mockResolvedValue({
json: async () => [],
})
await getQuiltLoaderVersionsByMinecraft({
fetch: mockFetch,
minecraftVersion: '23w31a',
})
expect(mockFetch).toHaveBeenCalledWith(
'https://meta.quiltmc.org/v3/versions/loader/23w31a',
expect.any(Object),
)
})
test('should parse artifact versions correctly', async () => {
const mockVersions: QuiltLoaderArtifact[] = [
{
loader: {
separator: '.',
build: 2,
maven: 'org.quiltmc:quilt-loader:0.19.2',
version: '0.19.2',
stable: true,
},
intermediary: {
maven: 'org.quiltmc:intermediary:1.20.1',
version: '1.20.1',
stable: true,
},
launcherMeta: {
version: 1,
libraries: {
client: [],
common: [],
server: [],
},
mainClass: {
client: 'net.fabricmc.loader.launch.knot.KnotClient',
server: 'net.fabricmc.loader.launch.knot.KnotServer',
},
},
hashed: {
maven: 'org.quiltmc:hashed:1.20.1',
version: '1.20.1',
stable: true,
},
},
]
const mockFetch = vi.fn().mockResolvedValue({
json: async () => mockVersions,
})
const result = await getQuiltLoaderVersionsByMinecraft({
fetch: mockFetch,
minecraftVersion: '1.20.1',
})
expect(result[0].loader.version).toBe('0.19.2')
expect(result[0].hashed).toBeDefined()
})
})
describe('DEFAULT_META_URL_QUILT', () => {
test('should have correct default URL', () => {
expect(DEFAULT_META_URL_QUILT).toBe('https://meta.quiltmc.org')
})
})
describe('QuiltLoaderArtifact interface', () => {
test('should have hashed property', () => {
const artifact: QuiltLoaderArtifact = {
loader: {
maven: 'org.quiltmc:quilt-loader:0.19.2',
version: '0.19.2',
stable: true,
},
intermediary: {
maven: 'org.quiltmc:intermediary:1.20.1',
version: '1.20.1',
stable: true,
},
launcherMeta: {
version: 1,
libraries: {
client: [],
common: [],
server: [],
},
mainClass: {
client: 'net.fabricmc.loader.launch.knot.KnotClient',
server: 'net.fabricmc.loader.launch.knot.KnotServer',
},
},
hashed: {
maven: 'org.quiltmc:hashed:1.20.1',
version: '1.20.1',
stable: true,
},
}
expect(artifact.hashed).toBeDefined()
expect(artifact.hashed.maven).toBe('org.quiltmc:hashed:1.20.1')
})
})
})