Unverified Commit ac84542f authored by JJ Kasper's avatar JJ Kasper Committed by GitHub
parent 257872e4
......@@ -28,7 +28,7 @@ createNextDescribe(
const duration = endTime - startTime
// Each part takes 5 seconds so it should be below 10 seconds
// Using 7 seconds to ensure external factors causing slight slowness don't fail the tests
expect(duration < 7000).toBe(true)
expect(duration).toBeLessThan(10_000)
expect($('#slow-layout-message').text()).toBe('hello from slow layout')
expect($('#slow-page-message').text()).toBe('hello from slow page')
})
......
......@@ -24,23 +24,18 @@ describe('useReportWebVitals hook', () => {
// Analytics events are only sent in production
it('should send web-vitals to vercel-insights', async () => {
let countEvents = false
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) => {
if (countEvents) {
eventsCount += 1
}
eventsCount += 1
route.fulfill()
})
},
})
// Start counting analytics events
countEvents = true
// Refresh will trigger CLS and LCP. When page loads FCP and TTFB will trigger:
await browser.refresh()
......@@ -48,6 +43,9 @@ describe('useReportWebVitals hook', () => {
await browser.elementById('btn').click()
// Make sure all registered events in performance-relayer has fired
await check(() => eventsCount, /6/)
await check(async () => {
expect(eventsCount).toBeGreaterThanOrEqual(6)
return 'success'
}, 'success')
})
})
/* eslint-env jest */
import {
check,
findPort,
killApp,
launchApp,
......@@ -58,12 +59,15 @@ describe('Image Component Trailing Slash Tests', () => {
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
await check(async () => {
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
return 'success'
}, 'success')
} finally {
if (browser) {
await browser.close()
......
/* eslint-env jest */
import {
check,
findPort,
killApp,
launchApp,
......@@ -58,12 +59,15 @@ describe('Image Component Trailing Slash Tests', () => {
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
await check(async () => {
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
return 'success'
}, 'success')
} finally {
if (browser) {
await browser.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment