|
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", () => { |
@@ -291,4 +292,41 @@ describe("Cloudflare Docs", () => { |
291 | 292 | expect(await response.text()).toContain("Page not found."); |
292 | 293 | }); |
293 | 294 | }); |
| 295 | + |
| 296 | + describe("head tags", async () => { |
| 297 | + const request = new Request("http://fakehost/workers/"); |
| 298 | + const response = await SELF.fetch(request); |
| 299 | + expect(response.status).toBe(200); |
| 300 | + |
| 301 | + const html = await response.text(); |
| 302 | + const dom = parse(html); |
| 303 | + |
| 304 | + it("product meta tags", () => { |
| 305 | + const product = dom.querySelector("meta[name='pcx_product']")?.attributes |
| 306 | + .content; |
| 307 | + |
| 308 | + const group = dom.querySelector("meta[name='pcx_content_group']") |
| 309 | + ?.attributes.content; |
| 310 | + |
| 311 | + expect(product).toBe("Workers"); |
| 312 | + expect(group).toBe("Developer platform"); |
| 313 | + }); |
| 314 | + |
| 315 | + it("index.md rel='alternate' tag", () => { |
| 316 | + const markdown = dom.querySelector( |
| 317 | + "link[rel='alternate'][type='text/markdown']", |
| 318 | + )?.attributes.href; |
| 319 | + |
| 320 | + expect(markdown).toBe("/workers/index.md"); |
| 321 | + }); |
| 322 | + |
| 323 | + it("og:image tag", () => { |
| 324 | + const image = dom.querySelector("meta[property='og:image']")?.attributes |
| 325 | + .content; |
| 326 | + |
| 327 | + expect(image).toBe( |
| 328 | + "https://developers.cloudflare.com/dev-products-preview.png", |
| 329 | + ); |
| 330 | + }); |
| 331 | + }); |
294 | 332 | }); |
0 commit comments