|
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,77 @@ describe("Cloudflare Docs", () => { |
300 | 301 | expect(await response.text()).toContain("Page not found."); |
301 | 302 | }); |
302 | 303 | }); |
| 304 | + |
| 305 | + describe("head tags", async () => { |
| 306 | + describe("/workers/", async () => { |
| 307 | + const request = new Request("http://fakehost/workers/"); |
| 308 | + const response = await SELF.fetch(request); |
| 309 | + expect(response.status).toBe(200); |
| 310 | + |
| 311 | + const html = await response.text(); |
| 312 | + const dom = parse(html); |
| 313 | + |
| 314 | + it("product meta tags", () => { |
| 315 | + const product = dom.querySelector("meta[name='pcx_product']") |
| 316 | + ?.attributes.content; |
| 317 | + |
| 318 | + const group = dom.querySelector("meta[name='pcx_content_group']") |
| 319 | + ?.attributes.content; |
| 320 | + |
| 321 | + expect(product).toBe("Workers"); |
| 322 | + expect(group).toBe("Developer platform"); |
| 323 | + }); |
| 324 | + |
| 325 | + it("index.md rel='alternate' tag", () => { |
| 326 | + const markdown = dom.querySelector( |
| 327 | + "link[rel='alternate'][type='text/markdown']", |
| 328 | + )?.attributes.href; |
| 329 | + |
| 330 | + expect(markdown).toBe("/workers/index.md"); |
| 331 | + }); |
| 332 | + |
| 333 | + it("og:image tag", () => { |
| 334 | + const image = dom.querySelector("meta[property='og:image']")?.attributes |
| 335 | + .content; |
| 336 | + |
| 337 | + expect(image).toBe( |
| 338 | + "https://developers.cloudflare.com/dev-products-preview.png", |
| 339 | + ); |
| 340 | + }); |
| 341 | + }); |
| 342 | + |
| 343 | + describe("/style-guide/fixtures/markdown/", async () => { |
| 344 | + const request = new Request( |
| 345 | + "http://fakehost/style-guide/fixtures/markdown/", |
| 346 | + ); |
| 347 | + const response = await SELF.fetch(request); |
| 348 | + expect(response.status).toBe(200); |
| 349 | + |
| 350 | + const html = await response.text(); |
| 351 | + const dom = parse(html); |
| 352 | + |
| 353 | + it("title", () => { |
| 354 | + const title = dom.querySelector("title")?.textContent; |
| 355 | + |
| 356 | + expect(title).toMatchInlineSnapshot( |
| 357 | + `"Markdown · Cloudflare Style Guide"`, |
| 358 | + ); |
| 359 | + }); |
| 360 | + |
| 361 | + it("description", () => { |
| 362 | + const desc = dom.querySelector("meta[name='description']")?.attributes |
| 363 | + .content; |
| 364 | + |
| 365 | + const og = dom.querySelector("meta[property='og:description']") |
| 366 | + ?.attributes.content; |
| 367 | + |
| 368 | + expect(desc).toMatchInlineSnapshot( |
| 369 | + `"The HTML generated by this file is used as a test fixture for our Markdown generation."`, |
| 370 | + ); |
| 371 | + expect(og).toMatchInlineSnapshot( |
| 372 | + `"The HTML generated by this file is used as a test fixture for our Markdown generation."`, |
| 373 | + ); |
| 374 | + }); |
| 375 | + }); |
| 376 | + }); |
303 | 377 | }); |
0 commit comments