|  | 
|  | 1 | +import { expect, test } from "@playwright/test"; | 
|  | 2 | + | 
|  | 3 | +test("Open-graph image to be in metatags and present", async ({ | 
|  | 4 | +  page, | 
|  | 5 | +  request, | 
|  | 6 | +}) => { | 
|  | 7 | +  await page.goto("/og"); | 
|  | 8 | + | 
|  | 9 | +  // Wait for meta tags to be present | 
|  | 10 | +  const ogImageSrc = await page | 
|  | 11 | +    .locator('meta[property="og:image"]') | 
|  | 12 | +    .getAttribute("content"); | 
|  | 13 | +  const ogImageAlt = await page | 
|  | 14 | +    .locator('meta[property="og:image:alt"]') | 
|  | 15 | +    .getAttribute("content"); | 
|  | 16 | +  const ogImageType = await page | 
|  | 17 | +    .locator('meta[property="og:image:type"]') | 
|  | 18 | +    .getAttribute("content"); | 
|  | 19 | +  const ogImageWidth = await page | 
|  | 20 | +    .locator('meta[property="og:image:width"]') | 
|  | 21 | +    .getAttribute("content"); | 
|  | 22 | +  const ogImageHeight = await page | 
|  | 23 | +    .locator('meta[property="og:image:height"]') | 
|  | 24 | +    .getAttribute("content"); | 
|  | 25 | + | 
|  | 26 | +  // Verify meta tag exists and is the correct values | 
|  | 27 | +  expect(ogImageSrc).not.toBe(null); | 
|  | 28 | +  expect(ogImageAlt).toBe("OpenNext"); | 
|  | 29 | +  expect(ogImageType).toBe("image/png"); | 
|  | 30 | +  expect(ogImageWidth).toBe("1200"); | 
|  | 31 | +  expect(ogImageHeight).toBe("630"); | 
|  | 32 | + | 
|  | 33 | +  // Check if the image source is working | 
|  | 34 | +  const response = await request.get(`/og/${ogImageSrc?.split("/").at(-1)}`); | 
|  | 35 | +  expect(response.status()).toBe(200); | 
|  | 36 | +  expect(response.headers()["content-type"]).toBe("image/png"); | 
|  | 37 | +  expect(response.headers()["cache-control"]).toBe( | 
|  | 38 | +    "public, immutable, no-transform, max-age=31536000", | 
|  | 39 | +  ); | 
|  | 40 | +}); | 
|  | 41 | + | 
|  | 42 | +test("next/og (vercel/og) to work in API route", async ({ request }) => { | 
|  | 43 | +  const response = await request.get("api/og?title=opennext"); | 
|  | 44 | +  expect(response.status()).toBe(200); | 
|  | 45 | +  expect(response.headers()["content-type"]).toBe("image/png"); | 
|  | 46 | +  expect(response.headers()["cache-control"]).toBe( | 
|  | 47 | +    "public, immutable, no-transform, max-age=31536000", | 
|  | 48 | +  ); | 
|  | 49 | +}); | 
0 commit comments