Skip to content

Commit dca0114

Browse files
🏷️ Add types for test configs (#26)
* Add types for test configs to enable auto-completion and detect API changes in future Markdoc versions This might be especially useful to find and fix potential future breaking changes since @markdoc/markdoc still has not yet reached semver `1.0.0`. * 🏷️ Add additional typing --------- Co-authored-by: Samuel Plumppu <[email protected]>
1 parent eb6c1bb commit dca0114

File tree

28 files changed

+77
-46
lines changed

28 files changed

+77
-46
lines changed

test/heading.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("Headings", () => {
1414
it("adds IDs and exports headings even when a custom heading is included", async () => {
1515
const result = (await markdocPreprocess({
1616
headingIds: true,
17-
nodes: { heading: basicHeadingNode.heading },
17+
nodes: { heading: basicHeadingNode },
1818
} as Options).markup!({
1919
content: markdocWithHeadings,
2020
filename: "test.md",
@@ -26,7 +26,7 @@ describe("Headings", () => {
2626
it("adds IDs and exports headings even when the custom heading is a custom component", async () => {
2727
const result = (await markdocPreprocess({
2828
headingIds: true,
29-
nodes: { heading: customComponentNode.heading },
29+
nodes: { heading: customComponentNode },
3030
} as Options).markup!({
3131
content: markdocWithHeadings,
3232
filename: "test.md",
@@ -49,7 +49,7 @@ describe("Headings", () => {
4949
it("adds IDs when passed a custom slugifying function even for custom headings", async () => {
5050
const result = (await markdocPreprocess({
5151
headingIds: customSlugger,
52-
nodes: { heading: basicHeadingNode.heading },
52+
nodes: { heading: basicHeadingNode },
5353
} as Options).markup!({
5454
content: markdocWithHeadings,
5555
filename: "test.md",
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default {};
1+
import type { Config } from "@markdoc/markdoc";
2+
3+
export default {} satisfies Config["nodes"];

test/markdoc/empty-schemas/tags.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default {};
1+
import type { Config } from "@markdoc/markdoc";
2+
3+
export default {} satisfies Config["tags"];

test/markdoc/file-preference/tags.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @type {import('@markdoc/markdoc').Config['tags']} */
12
export default {
23
preferenceTag: {
34
render: "JavaScriptTag",
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { Config } from "@markdoc/markdoc";
2+
13
export default {
24
preferenceTag: {
35
render: "TypeScriptTag",
46
attributes: {},
57
children: ["text"],
68
},
7-
};
9+
} satisfies Config["tags"];
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { Config } from "@markdoc/markdoc";
2+
13
export default {
24
priorityTag: {
35
render: "FileTag",
46
attributes: {},
57
children: ["text"],
68
},
7-
};
9+
} satisfies Config["tags"];
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { Config } from "@markdoc/markdoc";
2+
13
export default {
24
priorityTag: {
35
render: "DirectoryTag",
46
attributes: {},
57
children: ["text"],
68
},
7-
};
9+
} satisfies Config["tags"];
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
import type { Schema } from "@markdoc/markdoc";
12
import { headingNode } from "../../../src/index.ts";
23

34
export default {
4-
heading: {
5-
render: "h1",
6-
attributes: {
7-
class: { type: String, default: "custom-heading" },
8-
...headingNode.attributes,
9-
},
10-
children: headingNode.children,
11-
transform: headingNode.transform,
5+
render: "h1",
6+
attributes: {
7+
class: { type: String, default: "custom-heading" },
8+
...headingNode.attributes,
129
},
13-
};
10+
children: headingNode.children,
11+
transform: headingNode.transform,
12+
} satisfies Schema;
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import type { Schema } from "@markdoc/markdoc";
12
import { headingNode } from "../../../src/index.ts";
23

34
export default {
4-
heading: {
5-
render: "HeadingComponent",
6-
attributes: {
7-
...headingNode.attributes,
8-
},
9-
children: headingNode.children,
10-
transform: headingNode.transform,
5+
render: "HeadingComponent",
6+
attributes: {
7+
...headingNode.attributes,
118
},
12-
};
9+
children: headingNode.children,
10+
transform: headingNode.transform,
11+
} satisfies Schema;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { Config } from "@markdoc/markdoc";
12
import functions from "../../shared-schema/functions.ts";
23

34
export default {
45
testFunction: functions.testFunction,
5-
};
6+
} satisfies Config["functions"];

0 commit comments

Comments
 (0)