Files
next.js/test/e2e/app-dir/app/useReportWebVitals.test.ts
4588a73542 Convert tests using createNext -> nextTestSetup (#93767)
## What?

Converts existing `createNext()` usage into `nextTestSetup()`. 

`createNext()` was the setup step we had before `nextTestSetup()` was
added.

This PR focused on the simple conversion cases. There will be a
follow-up to complete the last few.

---------

Co-authored-by: Cursor <[email protected]>
2026-05-12 13:16:31 +02:00

45 lines
1.1 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'
describe('useReportWebVitals hook', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
env: {},
dependencies: {
nanoid: '4.0.1',
},
})
beforeAll(async () => {
await next.start()
})
// Analytics events are only sent in production
it('should send web-vitals', async () => {
await next.fetch('/report-web-vitals')
let eventsCount = 0
const browser = await next.browser('/report-web-vitals', {
beforePageLoad: (page) => {
page.route('https://example.vercel.sh/vitals', (route) => {
eventsCount += 1
route.fulfill()
})
},
})
// Refresh will trigger CLS and LCP. When page loads FCP and TTFB will trigger:
await browser.refresh()
// After interaction LCP and FID will trigger
await browser.elementById('btn').click()
// Make sure all registered events in performance-relayer has fired
await check(async () => {
expect(eventsCount).toBeGreaterThanOrEqual(6)
return 'success'
}, 'success')
})
})