Skip to content

Commit 377b125

Browse files
committed
fix: green CI on main
- drop never-read `capturedUpstreamContentType` to satisfy unused-vars lint - assert pan-on-open guard via `panBy` (not rAF spy); the Nuxt/happy-dom test env schedules a stray rAF during mount, making the count flaky
1 parent 7028777 commit 377b125

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

test/nuxt-runtime/google-maps-overlay-view.nuxt.test.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,44 +354,52 @@ describe('scriptGoogleMapsOverlayView', () => {
354354
// resolved a position. That caused unexpected map panning on initial mount
355355
// and remount. The fix gates the rAF scheduling on `open !== false` and
356356
// re-checks `open` + `overlayPosition` inside the callback before panning.
357+
//
358+
// We mock `requestAnimationFrame` to fire its callback synchronously so the
359+
// panMapToFitOverlay → panBy path is exercised within the test, then assert
360+
// on `panBy` (the actual user-visible side effect). Spying on rAF directly
361+
// is unreliable in the Nuxt/happy-dom environment, which itself schedules
362+
// background rAF calls during mount.
357363

358364
let rafSpy: ReturnType<typeof vi.spyOn>
359365

360366
beforeEach(() => {
361-
rafSpy = vi.spyOn(globalThis, 'requestAnimationFrame')
367+
rafSpy = vi.spyOn(globalThis, 'requestAnimationFrame').mockImplementation(((cb: FrameRequestCallback) => {
368+
cb(0)
369+
return 0
370+
}) as typeof globalThis.requestAnimationFrame)
362371
})
363372

364373
afterEach(() => {
365374
rafSpy.mockRestore()
366375
})
367376

368-
it('does not schedule pan-on-open when overlay starts closed (defaultOpen=false)', async () => {
377+
it('does not pan when overlay starts closed (defaultOpen=false)', async () => {
369378
const mocks = createOverlayMocks()
370379
await mountOverlay(
371380
{ position: { lat: 10, lng: 20 }, defaultOpen: false },
372381
mocks,
373382
)
374383

375-
expect(rafSpy).not.toHaveBeenCalled()
376384
expect(mocks.mockMap.panBy).not.toHaveBeenCalled()
377385
})
378386

379-
it('does not schedule pan-on-open when controlled :open is false on mount', async () => {
387+
it('does not pan when controlled :open is false on mount', async () => {
380388
const mocks = createOverlayMocks()
381389
await mountOverlay(
382390
{ position: { lat: 10, lng: 20 }, open: false },
383391
mocks,
384392
)
385393

386-
expect(rafSpy).not.toHaveBeenCalled()
387394
expect(mocks.mockMap.panBy).not.toHaveBeenCalled()
388395
})
389396

390397
it('schedules pan-on-open when overlay starts open with a position', async () => {
391398
const mocks = createOverlayMocks()
392399
await mountOverlay({ position: { lat: 10, lng: 20 } }, mocks)
393400

394-
// The guard allows the rAF to be scheduled when the happy path applies
401+
// Happy path: rAF callback fires synchronously via the mock, then
402+
// panMapToFitOverlay runs panBy off the (mock) bounding rects.
395403
expect(rafSpy).toHaveBeenCalled()
396404
})
397405

@@ -402,7 +410,6 @@ describe('scriptGoogleMapsOverlayView', () => {
402410
mocks,
403411
)
404412

405-
expect(rafSpy).not.toHaveBeenCalled()
406413
expect(mocks.mockMap.panBy).not.toHaveBeenCalled()
407414
})
408415
})

test/unit/proxy-handler-binary.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Server } from 'node:http'
22
import { createServer } from 'node:http'
33
import { gzipSync } from 'node:zlib'
4-
import { createApp, defineEventHandler, getHeader, getHeaders, readBody, readRawBody, toNodeListener } from 'h3'
4+
import { createApp, defineEventHandler, getHeaders, readBody, readRawBody, toNodeListener } from 'h3'
55
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
66

77
/**
@@ -19,15 +19,12 @@ describe('proxy handler - compressed binary payloads (#618)', () => {
1919
let proxyPort: number
2020
let capturedUpstreamBody: Buffer | null = null
2121

22-
let capturedUpstreamContentType: string | undefined
23-
2422
beforeAll(async () => {
2523
// Mock upstream: captures raw request bytes exactly as received
2624
const upstreamApp = createApp()
2725
upstreamApp.use('/', defineEventHandler(async (event) => {
2826
const raw = await readRawBody(event, false)
2927
capturedUpstreamBody = raw ? Buffer.from(raw) : Buffer.alloc(0)
30-
capturedUpstreamContentType = getHeader(event, 'content-type')
3128
return { status: 1 }
3229
}))
3330

@@ -86,7 +83,6 @@ describe('proxy handler - compressed binary payloads (#618)', () => {
8683

8784
beforeEach(() => {
8885
capturedUpstreamBody = null
89-
capturedUpstreamContentType = undefined
9086
})
9187

9288
afterAll(() => {

0 commit comments

Comments
 (0)