forked from
npmx.dev/npmx.dev
[READ-ONLY]
a fast, modern browser for the npm registry
1import { expect, test } from './test-utils'
2
3// TODO(serhalp): The nuxt@3.20.2 fixture has no stars. Update fixture to have stars coverage here.
4const paths = ['/', '/package/nuxt/v/3.20.2']
5
6for (const path of paths) {
7 test.describe(path, () => {
8 test(`og image for ${path}`, async ({ page, goto, baseURL }) => {
9 await goto(path, { waitUntil: 'domcontentloaded' })
10
11 const ogImageUrl = await page.locator('meta[property="og:image"]').getAttribute('content')
12 expect(ogImageUrl).toBeTruthy()
13
14 const ogImagePath = new URL(ogImageUrl!).pathname
15 const localUrl = baseURL?.endsWith('/')
16 ? `${baseURL}${ogImagePath.slice(1)}`
17 : `${baseURL}${ogImagePath}`
18 const response = await page.request.get(localUrl)
19
20 expect(response.status()).toBe(200)
21 expect(response.headers()['content-type']).toContain('image/png')
22
23 const imageBuffer = await response.body()
24 expect(imageBuffer).toMatchSnapshot({
25 name: `og-image-for-${path.replace(/\//g, '-')}.png`,
26 })
27 })
28 })
29}