Skip to content

Commit 6b01882

Browse files
authored
chore: increase test coverage (#87)
1 parent b8c429c commit 6b01882

File tree

3 files changed

+110
-4
lines changed

3 files changed

+110
-4
lines changed

deno.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"tasks": {
33
"build": "deno run --allow-read --allow-write --allow-net --allow-run --allow-env ./style/patch.ts && deno fmt",
4+
"check:types": "deno check **/*.ts",
5+
"coverage": "deno test --allow-read --coverage=cov_profile",
46
"dev": "deno run -A --unstable --watch --no-check ./example/main.ts",
5-
"test": "deno test --allow-read",
6-
"coverage": "deno test --allow-read --coverage=cov_profile"
7+
"ok": "deno fmt --check && deno lint && deno task check:types && deno task test",
8+
"report": "deno coverage cov_profile --html",
9+
"test": "deno test --allow-read"
710
},
811
"fmt": {
912
"exclude": ["./test/fixtures/alerts.md"]

test/fixtures/codeMath.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>y</mi><mo>=</mo><mi>m</mi><mi>x</mi><mo>+</mo><mi>b</mi></mrow><annotation encoding="application/x-tex">y = mx + b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.1944em"></span><span class="mathnormal" style="margin-right:0.03588em">y</span><span class="mspace" style="margin-right:0.2778em"></span><span>=</span><span class="mspace" style="margin-right:0.2778em"></span></span><span class="base"><span class="strut" style="height:0.6667em;vertical-align:-0.0833em"></span><span class="mathnormal">m</span><span class="mathnormal">x</span><span class="mspace" style="margin-right:0.2222em"></span><span>+</span><span class="mspace" style="margin-right:0.2222em"></span></span><span class="base"><span class="strut" style="height:0.6944em"></span><span class="mathnormal">b</span></span></span></span></span>

test/test.ts

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts";
2-
import { DOMParser } from "https://deno.land/x/[email protected].35-alpha/deno-dom-wasm.ts";
1+
import { assertEquals } from "https://deno.land/std@0.211.0/assert/assert_equals.ts";
2+
import { DOMParser } from "https://deno.land/x/[email protected].43/deno-dom-wasm.ts";
33
import { render, Renderer } from "../mod.ts";
44

55
Deno.test("Basic markdown", async () => {
@@ -106,3 +106,105 @@ Deno.test(
106106
assertEquals(html, expected);
107107
},
108108
);
109+
110+
Deno.test("Iframe rendering", () => {
111+
const markdown =
112+
'Here is an iframe:\n\n<iframe src="https://example.com" width="300" height="200"></iframe>';
113+
const expected =
114+
`<p>Here is an iframe:</p>\n<iframe src="https://example.com" width="300" height="200"></iframe>`;
115+
116+
const html = render(markdown, { allowIframes: true });
117+
assertEquals(html, expected);
118+
});
119+
120+
Deno.test("Iframe rendering disabled", () => {
121+
const markdown =
122+
'Here is an iframe:\n\n<iframe src="https://example.com" width="300" height="200"></iframe>';
123+
const expectedWithoutIframe = `<p>Here is an iframe:</p>\n`;
124+
125+
const html = render(markdown);
126+
assertEquals(html, expectedWithoutIframe);
127+
});
128+
129+
Deno.test("Media URL transformation", () => {
130+
const markdown = "![Image](image.jpg)\n\n![Video](video.mp4)";
131+
const mediaBaseUrl = "https://cdn.example.com/";
132+
const expected =
133+
`<p><img src="https://cdn.example.com/image.jpg" alt="Image" /></p>\n<p><img src="https://cdn.example.com/video.mp4" alt="Video" /></p>\n`;
134+
135+
const html = render(markdown, { mediaBaseUrl: mediaBaseUrl });
136+
assertEquals(html, expected);
137+
});
138+
139+
Deno.test("Media URL transformation without base URL", () => {
140+
const markdown = "![Image](image.jpg)\n\n![Video](video.mp4)";
141+
const expectedWithoutTransformation =
142+
`<p><img src="image.jpg" alt="Image" /></p>\n<p><img src="video.mp4" alt="Video" /></p>\n`;
143+
144+
const html = render(markdown);
145+
assertEquals(html, expectedWithoutTransformation);
146+
});
147+
148+
Deno.test("Media URL transformation with invalid URL", () => {
149+
const markdown = "![Image](invalid-url)";
150+
const mediaBaseUrl = "this is an invalid url";
151+
const expected = `<p><img alt="Image" /></p>\n`;
152+
153+
const html = render(markdown, { mediaBaseUrl: mediaBaseUrl });
154+
assertEquals(html, expected);
155+
});
156+
157+
Deno.test("Inline rendering", () => {
158+
const markdown = "My [Deno](https://deno.land) Blog";
159+
const expected =
160+
`My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog`;
161+
162+
const html = render(markdown, { inline: true });
163+
assertEquals(html, expected);
164+
});
165+
166+
Deno.test("Inline rendering false", () => {
167+
const markdown = "My [Deno](https://deno.land) Blog";
168+
const expected =
169+
`<p>My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog</p>\n`;
170+
171+
const html = render(markdown, { inline: false });
172+
assertEquals(html, expected);
173+
});
174+
175+
Deno.test("Link URL resolution with base URL", () => {
176+
const markdown = "[Test Link](/path/to/resource)";
177+
const baseUrl = "https://example.com/";
178+
const expected =
179+
`<p><a href="https://example.com/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`;
180+
181+
const html = render(markdown, { baseUrl: baseUrl });
182+
assertEquals(html, expected);
183+
});
184+
185+
Deno.test("Link URL resolution without base URL", () => {
186+
const markdown = "[Test Link](/path/to/resource)";
187+
const expected =
188+
`<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`;
189+
190+
const html = render(markdown);
191+
assertEquals(html, expected);
192+
});
193+
194+
Deno.test("Link URL resolution with invalid URL and base URL", () => {
195+
const markdown = "[Test Link](/path/to/resource)";
196+
const baseUrl = "this is an invalid url";
197+
const expected =
198+
`<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`;
199+
200+
const html = render(markdown, { baseUrl: baseUrl });
201+
assertEquals(html, expected);
202+
});
203+
204+
Deno.test("Math rendering in code block", () => {
205+
const markdown = "```math\ny = mx + b\n```";
206+
const expected = Deno.readTextFileSync("./test/fixtures/codeMath.html");
207+
208+
const html = render(markdown, { allowMath: true });
209+
assertEquals(html, expected);
210+
});

0 commit comments

Comments
 (0)