|
1 | 1 | import { SELF } from "cloudflare:test"; |
2 | 2 | import { describe, it, expect } from "vitest"; |
3 | 3 | import { XMLParser } from "fast-xml-parser"; |
| 4 | +import { parse } from "node-html-parser"; |
4 | 5 |
|
5 | 6 | describe("Cloudflare Docs", () => { |
6 | 7 | describe("html handling", () => { |
@@ -300,4 +301,41 @@ describe("Cloudflare Docs", () => { |
300 | 301 | expect(await response.text()).toContain("Page not found."); |
301 | 302 | }); |
302 | 303 | }); |
| 304 | + |
| 305 | + describe("head tags", async () => { |
| 306 | + const request = new Request("http://fakehost/workers/"); |
| 307 | + const response = await SELF.fetch(request); |
| 308 | + expect(response.status).toBe(200); |
| 309 | + |
| 310 | + const html = await response.text(); |
| 311 | + const dom = parse(html); |
| 312 | + |
| 313 | + it("product meta tags", () => { |
| 314 | + const product = dom.querySelector("meta[name='pcx_product']")?.attributes |
| 315 | + .content; |
| 316 | + |
| 317 | + const group = dom.querySelector("meta[name='pcx_content_group']") |
| 318 | + ?.attributes.content; |
| 319 | + |
| 320 | + expect(product).toBe("Workers"); |
| 321 | + expect(group).toBe("Developer platform"); |
| 322 | + }); |
| 323 | + |
| 324 | + it("index.md rel='alternate' tag", () => { |
| 325 | + const markdown = dom.querySelector( |
| 326 | + "link[rel='alternate'][type='text/markdown']", |
| 327 | + )?.attributes.href; |
| 328 | + |
| 329 | + expect(markdown).toBe("/workers/index.md"); |
| 330 | + }); |
| 331 | + |
| 332 | + it("og:image tag", () => { |
| 333 | + const image = dom.querySelector("meta[property='og:image']")?.attributes |
| 334 | + .content; |
| 335 | + |
| 336 | + expect(image).toBe( |
| 337 | + "https://developers.cloudflare.com/dev-products-preview.png", |
| 338 | + ); |
| 339 | + }); |
| 340 | + }); |
303 | 341 | }); |
0 commit comments