Skip to content

Commit dc5162a

Browse files
committed
fix(og-image): update test to derive downloads from weeklyValues
1 parent 662ba9b commit dc5162a

File tree

2 files changed

+272
-13
lines changed

2 files changed

+272
-13
lines changed

test/fixtures/jsdelivr/vue.json

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
{
2+
"type": "npm",
3+
"name": "vue",
4+
"version": "3.5.27",
5+
"default": "/dist/vue.global.min.js",
6+
"files": [
7+
{
8+
"type": "directory",
9+
"name": "dist",
10+
"files": [
11+
{
12+
"type": "file",
13+
"name": "vue.cjs.js",
14+
"hash": "Spb3UJa120lbcHS96PMrde0P1IwyXLjWIV3Ou1RijWY=",
15+
"size": 2296
16+
},
17+
{
18+
"type": "file",
19+
"name": "vue.cjs.prod.js",
20+
"hash": "+63JmG7ZUFnGqvj6r5+AphQ2mJfWqOSJPmHRSdlwKpc=",
21+
"size": 1774
22+
},
23+
{
24+
"type": "file",
25+
"name": "vue.d.mts",
26+
"hash": "wBkVkr6Ot5BvmaxLh5jYClhblAAeoaX1DWzlsNE6XGI=",
27+
"size": 299
28+
},
29+
{
30+
"type": "file",
31+
"name": "vue.d.ts",
32+
"hash": "wBkVkr6Ot5BvmaxLh5jYClhblAAeoaX1DWzlsNE6XGI=",
33+
"size": 299
34+
},
35+
{
36+
"type": "file",
37+
"name": "vue.esm-browser.js",
38+
"hash": "8hAZOTL8EqgiaDuLB7G4RPapWRHfkYPBQQeEPWfGTuI=",
39+
"size": 543513
40+
},
41+
{
42+
"type": "file",
43+
"name": "vue.esm-browser.prod.js",
44+
"hash": "RQ8A1DP4bYzXrhfxY4DnpN5QHOndxhgoDXHR1rUUOlU=",
45+
"size": 166276
46+
},
47+
{
48+
"type": "file",
49+
"name": "vue.esm-bundler.js",
50+
"hash": "xFA3s1njCve19oecNYzzqkI5MGl87i75V7mcjtisyhs=",
51+
"size": 2188
52+
},
53+
{
54+
"type": "file",
55+
"name": "vue.global.js",
56+
"hash": "4QwcGRJ20HdK8/H+RTHD8KMMX0SYAOtv+DMT6QPeL+Y=",
57+
"size": 575157
58+
},
59+
{
60+
"type": "file",
61+
"name": "vue.global.prod.js",
62+
"hash": "R3ktt9Hy9tlnYoqSse8eL/0xwPyBjWeKj9VIWHnoWG0=",
63+
"size": 161438
64+
},
65+
{
66+
"type": "file",
67+
"name": "vue.runtime.esm-browser.js",
68+
"hash": "OOwiBm63wFE2esMurNo067bCbaxh6Ev//i2GUWzaWS8=",
69+
"size": 374576
70+
},
71+
{
72+
"type": "file",
73+
"name": "vue.runtime.esm-browser.prod.js",
74+
"hash": "L56SqCzuokJ0DDSxRmUu7uok4edKN+Zy4D47EXIVvbM=",
75+
"size": 105236
76+
},
77+
{
78+
"type": "file",
79+
"name": "vue.runtime.esm-bundler.js",
80+
"hash": "Xfw8TQ9z9YQwIToZYUMuzkpfbuxnMLvCPFqS+i9Rofk=",
81+
"size": 580
82+
},
83+
{
84+
"type": "file",
85+
"name": "vue.runtime.global.js",
86+
"hash": "mjxFvDW2yvOXxAkN4CqTMJcouEPsw8MOUU5CUctm/E4=",
87+
"size": 400132
88+
},
89+
{
90+
"type": "file",
91+
"name": "vue.runtime.global.prod.js",
92+
"hash": "6oYT2FGASdAuo9D0lOWJxEvPUUp1Pp4+vLaxgc9HIRQ=",
93+
"size": 103180
94+
}
95+
]
96+
},
97+
{
98+
"type": "directory",
99+
"name": "compiler-sfc",
100+
"files": [
101+
{
102+
"type": "file",
103+
"name": "index.browser.js",
104+
"hash": "vKxYudqTucILq0Z1HcNs4ez24gmyZhaB621OFnUMnGw=",
105+
"size": 46
106+
},
107+
{
108+
"type": "file",
109+
"name": "index.browser.mjs",
110+
"hash": "P+7CEsCuuR5abmLKr58SiVRZAhD4wwKRDqN3wIj2tho=",
111+
"size": 34
112+
},
113+
{
114+
"type": "file",
115+
"name": "index.d.mts",
116+
"hash": "P+7CEsCuuR5abmLKr58SiVRZAhD4wwKRDqN3wIj2tho=",
117+
"size": 34
118+
},
119+
{
120+
"type": "file",
121+
"name": "index.d.ts",
122+
"hash": "P+7CEsCuuR5abmLKr58SiVRZAhD4wwKRDqN3wIj2tho=",
123+
"size": 34
124+
},
125+
{
126+
"type": "file",
127+
"name": "index.js",
128+
"hash": "oiJsPu24J86Q+r0YQTyLbUAIqZJp9AP4bxYLczxUaXA=",
129+
"size": 75
130+
},
131+
{
132+
"type": "file",
133+
"name": "index.mjs",
134+
"hash": "zEcxISpVQrCZcvX1uAByr6A4eUEkK9JdXTpG2LuSDjg=",
135+
"size": 61
136+
},
137+
{
138+
"type": "file",
139+
"name": "package.json",
140+
"hash": "qDsWZ8wfqnNKzp1I1o9e5GZuigkWDfwmq0ue3GCoDA8=",
141+
"size": 50
142+
},
143+
{
144+
"type": "file",
145+
"name": "register-ts.js",
146+
"hash": "QkRyfJQu+K/vopaeqeQXnYhf+1PZH5YoEvyxikBabsk=",
147+
"size": 111
148+
}
149+
]
150+
},
151+
{
152+
"type": "directory",
153+
"name": "jsx-runtime",
154+
"files": [
155+
{
156+
"type": "file",
157+
"name": "index.d.ts",
158+
"hash": "MY0ZEYv2v40IhEHJSJkPU8r8ee1YG3jz1BoPej9fFFw=",
159+
"size": 848
160+
},
161+
{
162+
"type": "file",
163+
"name": "index.js",
164+
"hash": "7PyafRHlPLlB9VPK4NsP/r/Yf5eKxqdkocPbtCGouI8=",
165+
"size": 303
166+
},
167+
{
168+
"type": "file",
169+
"name": "index.mjs",
170+
"hash": "gVyN3tATf8FbqLWNzm1xLRbtPXNwHNHiomtW5IMvGaY=",
171+
"size": 265
172+
},
173+
{
174+
"type": "file",
175+
"name": "package.json",
176+
"hash": "h7UgBMQCDJWur6qiP24hdlIZVHgo4snzqUzZUw3UthQ=",
177+
"size": 75
178+
}
179+
]
180+
},
181+
{
182+
"type": "directory",
183+
"name": "server-renderer",
184+
"files": [
185+
{
186+
"type": "file",
187+
"name": "index.d.mts",
188+
"hash": "3fT8EanRVfHVgISDitDrZA04trdyT6wUoeeC76qilmw=",
189+
"size": 37
190+
},
191+
{
192+
"type": "file",
193+
"name": "index.d.ts",
194+
"hash": "3fT8EanRVfHVgISDitDrZA04trdyT6wUoeeC76qilmw=",
195+
"size": 37
196+
},
197+
{
198+
"type": "file",
199+
"name": "index.js",
200+
"hash": "Dnc1vk5lOZ0g2eplhAoM0O73+TX9GyJObEW1dr4SrBM=",
201+
"size": 49
202+
},
203+
{
204+
"type": "file",
205+
"name": "index.mjs",
206+
"hash": "3fT8EanRVfHVgISDitDrZA04trdyT6wUoeeC76qilmw=",
207+
"size": 37
208+
},
209+
{
210+
"type": "file",
211+
"name": "package.json",
212+
"hash": "qDsWZ8wfqnNKzp1I1o9e5GZuigkWDfwmq0ue3GCoDA8=",
213+
"size": 50
214+
}
215+
]
216+
},
217+
{
218+
"type": "file",
219+
"name": "index.js",
220+
"hash": "pSh/YFa8XCxWnTGAY+4EP1Wg0yP6cmL2RFbVj9V0+Sg=",
221+
"size": 171
222+
},
223+
{
224+
"type": "file",
225+
"name": "index.mjs",
226+
"hash": "vi81WQvuReaYUNDY1I8LjI9cDvDs+KcmWrEvt63WWE0=",
227+
"size": 27
228+
},
229+
{
230+
"type": "file",
231+
"name": "jsx.d.ts",
232+
"hash": "ijXsGcbGmcmP0W/ICuaWTYATnFqOYuxKXGCQLB2jKFw=",
233+
"size": 741
234+
},
235+
{
236+
"type": "file",
237+
"name": "LICENSE",
238+
"hash": "G7hcybE7ge9ByBxRhmFy/DReBQPIZyamdVt5ZZC3AXU=",
239+
"size": 1091
240+
},
241+
{
242+
"type": "file",
243+
"name": "package.json",
244+
"hash": "UItPIU1CLPZPLUsCtc0/g9PTJcWxeyWORD9aoNYJ3iA=",
245+
"size": 2810
246+
},
247+
{
248+
"type": "file",
249+
"name": "README.md",
250+
"hash": "wSxqjXHTxJpu8n1LvXDja6Ki0ntKLJuhnqHA5cj2C68=",
251+
"size": 3758
252+
}
253+
],
254+
"links": {
255+
"stats": "https://data.jsdelivr.com/v1/stats/packages/npm/vue@3.5.27",
256+
"entrypoints": "https://data.jsdelivr.com/v1/packages/npm/vue@3.5.27/entrypoints"
257+
}
258+
}

test/nuxt/components/OgImagePackage.spec.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { mockNuxtImport, mountSuspended, registerEndpoint } from '@nuxt/test-utils/runtime'
22
import { describe, expect, it, vi, beforeEach } from 'vitest'
33

4-
const { mockUseResolvedVersion, mockUsePackage, mockUseRepoMeta } = vi.hoisted(() => ({
4+
const {
5+
mockUseResolvedVersion,
6+
mockUsePackage,
7+
mockUseRepoMeta,
8+
mockFetchPackageDownloadEvolution,
9+
} = vi.hoisted(() => ({
510
mockUseResolvedVersion: vi.fn(),
611
mockUsePackage: vi.fn(),
712
mockUseRepoMeta: vi.fn(),
13+
mockFetchPackageDownloadEvolution: vi.fn().mockResolvedValue([]),
814
}))
915

1016
mockNuxtImport('useResolvedVersion', () => mockUseResolvedVersion)
@@ -18,7 +24,7 @@ vi.mock('~/utils/npm/api', () => ({
1824
}))
1925
vi.mock('~/composables/useCharts', () => ({
2026
useCharts: vi.fn().mockReturnValue({
21-
fetchPackageDownloadEvolution: vi.fn().mockResolvedValue([]),
27+
fetchPackageDownloadEvolution: mockFetchPackageDownloadEvolution,
2228
}),
2329
smoothPath: vi.fn().mockReturnValue(''),
2430
}))
@@ -47,21 +53,16 @@ describe('OgImagePackage', () => {
4753
downloads = 12500,
4854
} = overrides
4955

50-
// Mock $fetch for downloads endpoint
51-
vi.spyOn(globalThis, '$fetch').mockImplementation((url: string) => {
52-
if (typeof url === 'string' && url.includes('api.npmjs.org/downloads/point')) {
53-
return Promise.resolve({
54-
downloads,
55-
start: '2026-04-03',
56-
end: '2026-04-09',
57-
package: packageName,
58-
})
59-
}
56+
// Mock weekly evolution to provide download counts
57+
mockFetchPackageDownloadEvolution.mockResolvedValue(downloads > 0 ? [{ value: downloads }] : [])
58+
59+
// Mock $fetch for likes endpoint
60+
vi.spyOn(globalThis, '$fetch').mockImplementation(((url: string) => {
6061
if (typeof url === 'string' && url.includes('/api/social/likes/')) {
6162
return Promise.resolve({ totalLikes: 0, userHasLiked: false })
6263
}
6364
return Promise.resolve(null)
64-
})
65+
}) as typeof $fetch)
6566

6667
mockUseResolvedVersion.mockReturnValue({
6768
data: ref('1.0.0'),

0 commit comments

Comments
 (0)