Skip to content
Myr

markdown-resolve.test.ts

This file

Path

apps/web/test/markdown-resolve.test.ts

73 lines · 2.9 KiB · TypeScript

Last changed by

Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248

History of this file

Take it

Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a

lines 1–13why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { CommitSha, ProjectName } from "@repo/protocol/ids";34import { resolveRepoUrl } from "../src/features/markdown/resolve.ts";56const sha = CommitSha.make("0123456789abcdef0123456789abcdef01234567");78/** A `javascript:` URL, joined at run time so lint reads no script URL in the source. */9const scriptUrl = ["javascript", "alert(1)"].join(":");1011const at = (dir: string, kind: "link" | "media") => ({12 dir,13 kind,

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 14why, one step back
14 project: ProjectName.make("oscabriel/p"),

Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a

lines 15–30why, one step back
15 sha,
16});1718describe("a link in a Markdown file", () => {19 it.each([20 ["#usage", "#usage"],21 ["https://e.org/x", "https://e.org/x"],22 ["mailto:a@e.org", "mailto:a@e.org"],23 [scriptUrl, scriptUrl],24 ["//cdn.e.org/x.png", "//cdn.e.org/x.png"],25 ["", ""],26 ])("leaves %j as written", (url, expected) => {27 expect(resolveRepoUrl(url, at("docs", "link"))).toBe(expected);28 });2930 it.each([

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 31–41why, one step back
31 ["./guide.md", "docs", `/oscabriel/p/blob/${sha}/docs/guide.md`],
32 ["guide.md", "docs/api", `/oscabriel/p/blob/${sha}/docs/api/guide.md`],33 ["../../x", "docs", `/oscabriel/p/blob/${sha}/x`],34 ["../../../../x", "docs/api", `/oscabriel/p/blob/${sha}/x`],35 ["/LICENSE", "docs/api", `/oscabriel/p/blob/${sha}/LICENSE`],36 ["/../LICENSE", "docs", `/oscabriel/p/blob/${sha}/LICENSE`],37 ["src/a.ts?raw=1#L3", "", `/oscabriel/p/blob/${sha}/src/a.ts?raw=1#L3`],38 ["CONTRIBUTING.md", "", `/oscabriel/p/blob/${sha}/CONTRIBUTING.md`],39 ["./a.md#usage", "docs", `/oscabriel/p/blob/${sha}/docs/a.md#usage`],40 ["my file.md", "", `/oscabriel/p/blob/${sha}/my%20file.md`],41 ["my%20file.md", "", `/oscabriel/p/blob/${sha}/my%20file.md`],

Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a

lines 42–46why, one step back
42 ])("resolves %j in %j", (url, dir, expected) => {
43 expect(resolveRepoUrl(url, at(dir, "link"))).toBe(expected);44 });4546 it.each([

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 47–50why, one step back
47 ["docs/", "", `/oscabriel/p/tree/${sha}/docs`],
48 ["..", "docs/api", `/oscabriel/p/tree/${sha}/docs`],49 ["/", "docs", `/oscabriel/p/tree/${sha}`],50 ["./", "", `/oscabriel/p/tree/${sha}`],

Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a

lines 51–55why, one step back
51 ])("opens %j in %j as a folder", (url, dir, expected) => {
52 expect(resolveRepoUrl(url, at(dir, "link"))).toBe(expected);53 });5455 it.each([

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 56–57why, one step back
56 ["/\\evil.example/x", `/oscabriel/p/blob/${sha}/x`],
57 ["\\\\evil.example/x", `/oscabriel/p/blob/${sha}/x`],

Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a

lines 58–64why, one step back
58 ])("keeps %j inside the project", (url, expected) => {
59 expect(resolveRepoUrl(url, at("", "link"))).toBe(expected);60 });61});6263describe("an image or a video in a Markdown file", () => {64 it.each([

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 65–68why, one step back
65 ["./img/logo.png", "docs", `/oscabriel/p/raw/${sha}/docs/img/logo.png`],
66 ["media/logo.svg", "", `/oscabriel/p/raw/${sha}/media/logo.svg`],67 ["/media/logo.svg", "docs", `/oscabriel/p/raw/${sha}/media/logo.svg`],68 ["../demo.mp4", "docs", `/oscabriel/p/raw/${sha}/demo.mp4`],

Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a

lines 69–73why, one step back
69 ["https://e.org/logo.png", "docs", "https://e.org/logo.png"],
70 ])("resolves %j in %j", (url, dir, expected) => {71 expect(resolveRepoUrl(url, at(dir, "media"))).toBe(expected);72 });73});