Skip to content

Commit 6b8a368

Browse files
committed
✅ Add test for heading opt-in
1 parent 3e4cfe9 commit 6b8a368

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

test/__snapshots__/options.test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ exports[`File extensions > works when passed the default extension 1`] = `
4949
<article><h1>This is some basic Markdoc</h1><p>With a paragraph.</p><p>Some text <strong>in bold</strong> and <em>in italic</em>.</p><p>And a <a href="https://example.com">link</a>.</p><h2>More fancy stuff</h2><p>Some <code>&lt;p&gt;</code> inline code.</p><p>And a code block:</p><pre data-language="javascript"><code>&lcub;&lcub;% test %&rcub;&rcub;</code></pre><p>And even a table with a nested list:</p><table><thead><tr><th>Table header 1</th><th>Table header 2</th></tr></thead><tbody><tr><td><ul><li>Row 1 Cell 1 Item 1</li><li>Row 1 Cell 1 Item 2</li></ul></td><td>Row 1 Cell 2</td></tr><tr><td>Row 2 Cell 1</td><td>Row 2 cell 2</td></tr></tbody></table></article>"
5050
`;
5151

52+
exports[`Headings > adds IDs and exports headings when passed as an option 1`] = `
53+
"<script module>
54+
export const slug = "test";
55+
export const headings = [{"level":1,"title":"This is some basic Markdoc","id":"this-is-some-basic-markdoc"},{"level":2,"title":"More fancy stuff","id":"more-fancy-stuff"}];
56+
</script>
57+
<article><h1 id="this-is-some-basic-markdoc">This is some basic Markdoc</h1><p>With a paragraph.</p><p>Some text <strong>in bold</strong> and <em>in italic</em>.</p><p>And a <a href="https://example.com">link</a>.</p><h2 id="more-fancy-stuff">More fancy stuff</h2><p>Some <code>&lt;p&gt;</code> inline code.</p><p>And a code block:</p><pre data-language="javascript"><code>&lcub;&lcub;% test %&rcub;&rcub;</code></pre><p>And even a table with a nested list:</p><table><thead><tr><th>Table header 1</th><th>Table header 2</th></tr></thead><tbody><tr><td><ul><li>Row 1 Cell 1 Item 1</li><li>Row 1 Cell 1 Item 2</li></ul></td><td>Row 1 Cell 2</td></tr><tr><td>Row 2 Cell 1</td><td>Row 2 cell 2</td></tr></tbody></table></article>"
58+
`;
59+
60+
exports[`Headings > doesn't add IDs or export headings by default 1`] = `
61+
"<script module>
62+
export const slug = "test";
63+
</script>
64+
<article><h1>This is some basic Markdoc</h1><p>With a paragraph.</p><p>Some text <strong>in bold</strong> and <em>in italic</em>.</p><p>And a <a href="https://example.com">link</a>.</p><h2>More fancy stuff</h2><p>Some <code>&lt;p&gt;</code> inline code.</p><p>And a code block:</p><pre data-language="javascript"><code>&lcub;&lcub;% test %&rcub;&rcub;</code></pre><p>And even a table with a nested list:</p><table><thead><tr><th>Table header 1</th><th>Table header 2</th></tr></thead><tbody><tr><td><ul><li>Row 1 Cell 1 Item 1</li><li>Row 1 Cell 1 Item 2</li></ul></td><td>Row 1 Cell 2</td></tr><tr><td>Row 2 Cell 1</td><td>Row 2 cell 2</td></tr></tbody></table></article>"
65+
`;
66+
67+
exports[`Headings > doesn't add IDs or export headings when passed false 1`] = `
68+
"<script module>
69+
export const slug = "test";
70+
</script>
71+
<article><h1>This is some basic Markdoc</h1><p>With a paragraph.</p><p>Some text <strong>in bold</strong> and <em>in italic</em>.</p><p>And a <a href="https://example.com">link</a>.</p><h2>More fancy stuff</h2><p>Some <code>&lt;p&gt;</code> inline code.</p><p>And a code block:</p><pre data-language="javascript"><code>&lcub;&lcub;% test %&rcub;&rcub;</code></pre><p>And even a table with a nested list:</p><table><thead><tr><th>Table header 1</th><th>Table header 2</th></tr></thead><tbody><tr><td><ul><li>Row 1 Cell 1 Item 1</li><li>Row 1 Cell 1 Item 2</li></ul></td><td>Row 1 Cell 2</td></tr><tr><td>Row 2 Cell 1</td><td>Row 2 cell 2</td></tr></tbody></table></article>"
72+
`;
73+
5274
exports[`Layout > properly puts the parsed file in a layout when passed as an option 1`] = `
5375
"<script module>
5476
export const slug = "test";

test/options.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,45 @@ describe("File extensions", () => {
119119
});
120120
});
121121

122+
123+
124+
125+
describe("Headings", () => {
126+
it("doesn't add IDs or export headings by default", async () => {
127+
const result = (await markdocPreprocess().markup!({
128+
content: basicMarkdoc,
129+
filename: "test.md",
130+
})) as Processed;
131+
132+
expect(result.code).toMatchSnapshot();
133+
});
134+
135+
it("adds IDs and exports headings when passed as an option", async () => {
136+
const result = (await markdocPreprocess({
137+
headingIds: true,
138+
} as Options).markup!({
139+
content: basicMarkdoc,
140+
filename: "test.md",
141+
})) as Processed;
142+
143+
expect(result.code).toMatchSnapshot();
144+
});
145+
146+
it("doesn't add IDs or export headings when passed false", async () => {
147+
const result = (await markdocPreprocess({
148+
headingIds: false,
149+
} as Options).markup!({
150+
content: basicMarkdoc,
151+
filename: "test.md",
152+
})) as Processed;
153+
154+
expect(result.code).toMatchSnapshot();
155+
});
156+
});
157+
158+
159+
160+
122161
describe("Layout", () => {
123162
it("properly puts the parsed file in a layout when passed as an option", async () => {
124163
const layoutOptions = {

0 commit comments

Comments
 (0)