diff --git a/worker/index.worker.test.ts b/worker/index.worker.test.ts index 2f09b7906a600d..b1354d03ff4c6e 100644 --- a/worker/index.worker.test.ts +++ b/worker/index.worker.test.ts @@ -1,6 +1,7 @@ import { SELF } from "cloudflare:test"; import { describe, it, expect } from "vitest"; import { XMLParser } from "fast-xml-parser"; +import { parse } from "node-html-parser"; describe("Cloudflare Docs", () => { describe("html handling", () => { @@ -300,4 +301,77 @@ describe("Cloudflare Docs", () => { expect(await response.text()).toContain("Page not found."); }); }); + + describe("head tags", async () => { + describe("/workers/", async () => { + const request = new Request("http://fakehost/workers/"); + const response = await SELF.fetch(request); + expect(response.status).toBe(200); + + const html = await response.text(); + const dom = parse(html); + + it("product meta tags", () => { + const product = dom.querySelector("meta[name='pcx_product']") + ?.attributes.content; + + const group = dom.querySelector("meta[name='pcx_content_group']") + ?.attributes.content; + + expect(product).toBe("Workers"); + expect(group).toBe("Developer platform"); + }); + + it("index.md rel='alternate' tag", () => { + const markdown = dom.querySelector( + "link[rel='alternate'][type='text/markdown']", + )?.attributes.href; + + expect(markdown).toBe("/workers/index.md"); + }); + + it("og:image tag", () => { + const image = dom.querySelector("meta[property='og:image']")?.attributes + .content; + + expect(image).toBe( + "https://developers.cloudflare.com/dev-products-preview.png", + ); + }); + }); + + describe("/style-guide/fixtures/markdown/", async () => { + const request = new Request( + "http://fakehost/style-guide/fixtures/markdown/", + ); + const response = await SELF.fetch(request); + expect(response.status).toBe(200); + + const html = await response.text(); + const dom = parse(html); + + it("title", () => { + const title = dom.querySelector("title")?.textContent; + + expect(title).toMatchInlineSnapshot( + `"Markdown ยท Cloudflare Style Guide"`, + ); + }); + + it("description", () => { + const desc = dom.querySelector("meta[name='description']")?.attributes + .content; + + const og = dom.querySelector("meta[property='og:description']") + ?.attributes.content; + + expect(desc).toMatchInlineSnapshot( + `"The HTML generated by this file is used as a test fixture for our Markdown generation."`, + ); + expect(og).toMatchInlineSnapshot( + `"The HTML generated by this file is used as a test fixture for our Markdown generation."`, + ); + }); + }); + }); });