Skip to content

Commit 4d5afa5

Browse files
committed
fix: use utc dates, handle division by zero, + add tanstack fixture
1 parent 499668f commit 4d5afa5

7 files changed

Lines changed: 1809 additions & 5 deletions

File tree

app/composables/useCharts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export function smoothPath(pts: { x: number; y: number }[]): string {
162162
for (let i = 0; i < n; i++) {
163163
dx[i] = pts[i + 1]!.x - pts[i]!.x
164164
dy[i] = pts[i + 1]!.y - pts[i]!.y
165-
m[i] = dy[i]! / dx[i]!
165+
m[i] = dx[i] === 0 ? 0 : dy[i]! / dx[i]!
166166
}
167167

168168
t[0] = m[0]!

modules/runtime/server/cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ function getMockForUrl(url: string): MockResult | null {
263263
const downloads: { day: string; downloads: number }[] = []
264264
const start = new Date(startDate!)
265265
const end = new Date(endDate!)
266-
for (let d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
266+
for (let d = new Date(start); d <= end; d.setUTCDate(d.getUTCDate() + 1)) {
267267
const day = d.toISOString().slice(0, 10)
268268
const i = downloads.length
269269
const trend = 1 + trendSlope * i
270270
const wave = Math.sin((i * 2 * Math.PI) / wavePeriod) * waveAmp
271271
const noise = Math.sin(i * 7 + s) * 0.05
272-
const dow = d.getDay()
272+
const dow = d.getUTCDay()
273273
const weekend = dow === 0 || dow === 6 ? 1 - weekendDip : 1
274274
downloads.push({
275275
day,

scripts/generate-fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const REQUIRED_PACKAGES = [
4040
'next', // create-command test
4141
'@nuxt/kit', // scoped package tests, version test (3.20.0)
4242
'@types/node', // scoped package tests
43+
'@tanstack/react-query', // OG image test (scoped with long name)
4344
// Docs page tests
4445
'ufo', // docs test with version 1.6.3
4546
'is-odd', // docs test (3.0.1), install copy test, "no create" test, hyphen-in-name test

test/e2e/og-image.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ for (const { path, label } of testCases) {
5656

5757
const imageBuffer = await response.body()
5858
expect(imageBuffer).toMatchSnapshot({
59-
name: `og-image-${path.replace(/\//g, '-').replace(/^-/, '')}.png`,
59+
name: `og-image-${path.replace(/\//g, '-').replace(/^-/, '') || 'home'}.png`,
6060
maxDiffPixelRatio: 0.02,
6161
})
6262
})

test/fixtures/mock-routes.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function matchNpmApi(urlString) {
193193
const downloads = []
194194
const startDate = new Date(start)
195195
const endDate = new Date(end)
196-
for (let d = new Date(startDate); d <= endDate; d.setDate(d.getDate() + 1)) {
196+
for (let d = new Date(startDate); d <= endDate; d.setUTCDate(d.getUTCDate() + 1)) {
197197
const day = d.toISOString().slice(0, 10)
198198
// Sine wave + noise for a realistic-looking sparkline
199199
const dayIndex = downloads.length
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"downloads": 25603146,
3+
"start": "2026-02-20",
4+
"end": "2026-02-26",
5+
"package": "@tanstack/react-query"
6+
}

0 commit comments

Comments
 (0)