-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_test.ts
148 lines (138 loc) · 3.95 KB
/
mod_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { Aleph, ensureTextFile, expect, join, test } from "./dev_deps.ts";
import { mdxLoader, mdxResolver } from "./mod.ts";
test("mdxResolver", () => {
expect(mdxResolver("/pages/index.mdx")).toEqual({
asPage: {
path: "/",
isIndex: true,
},
});
expect(mdxResolver("/pages/docs/index.mdx")).toEqual({
asPage: {
path: "/docs",
isIndex: true,
},
});
expect(mdxResolver("/pages/docs/get-started.mdx")).toEqual({
asPage: { path: "/docs/get-started", isIndex: false },
});
expect(
mdxResolver("/pages/get_started.mdx", {
rewritePagePath: (path) => path.replaceAll("_", "-"),
}),
).toEqual({
asPage: { path: "/get-started", isIndex: false },
});
});
test("mdxLoader", async () => {
Deno.env.set("DENO_TESTING", "true");
const dir = await Deno.makeTempDir({ prefix: "aleph_plugin_testing" });
const aleph = new Aleph(dir);
await ensureTextFile(
join(dir, "/pages/docs/index.mdx"),
[
"# aleph-plugin-mdx",
"Aleph plugin for mdx v2",
].join("\n"),
);
await expect(
mdxLoader(
{ specifier: "/pages/docs/index.mdx" },
aleph,
),
).resolves.toEqual({
code: `/*@jsxRuntime automatic @jsxImportSource react*/
import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
function MDXContent(props = {}) {
const {wrapper: MDXLayout} = props.components || ({});
return MDXLayout ? _jsx(MDXLayout, Object.assign({}, props, {
children: _jsx(_createMdxContent, {})
})) : _createMdxContent();
function _createMdxContent() {
const _components = Object.assign({
h1: "h1",
p: "p"
}, props.components);
return _jsxs(_Fragment, {
children: [_jsx(_components.h1, {
children: "aleph-plugin-mdx"
}), "\\n", _jsx(_components.p, {
children: "Aleph plugin for mdx v2"
})]
});
}
}
export default MDXContent;
`,
});
await expect(
mdxLoader(
{ specifier: "/pages/docs/index.mdx" },
aleph,
{ pageProps: { meta: { title: "hello" }, nav: [{ path: "/" }] } },
),
).resolves.toEqual({
code: `/*@jsxRuntime automatic @jsxImportSource react*/
import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
function MDXContent(props = {}) {
const {wrapper: MDXLayout} = props.components || ({});
return MDXLayout ? _jsx(MDXLayout, Object.assign({}, props, {
children: _jsx(_createMdxContent, {})
})) : _createMdxContent();
function _createMdxContent() {
const _components = Object.assign({
h1: "h1",
p: "p"
}, props.components);
return _jsxs(_Fragment, {
children: [_jsx(_components.h1, {
children: "aleph-plugin-mdx"
}), "\\n", _jsx(_components.p, {
children: "Aleph plugin for mdx v2"
})]
});
}
}
export default MDXContent;
MDXContent.meta = {"title":"hello"};
MDXContent.nav = [{"path":"/"}];`,
});
await ensureTextFile(
join(dir, "/components/hello.mdx"),
[
"# aleph-plugin-mdx",
"Aleph plugin for mdx v2",
].join("\n"),
);
await expect(
mdxLoader(
{ specifier: "/components/hello.mdx" },
aleph,
{ pageProps: { meta: { title: "hello" }, nav: [{ path: "/" }] } },
),
).resolves.toEqual({
code: `/*@jsxRuntime automatic @jsxImportSource react*/
import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
function MDXContent(props = {}) {
const {wrapper: MDXLayout} = props.components || ({});
return MDXLayout ? _jsx(MDXLayout, Object.assign({}, props, {
children: _jsx(_createMdxContent, {})
})) : _createMdxContent();
function _createMdxContent() {
const _components = Object.assign({
h1: "h1",
p: "p"
}, props.components);
return _jsxs(_Fragment, {
children: [_jsx(_components.h1, {
children: "aleph-plugin-mdx"
}), "\\n", _jsx(_components.p, {
children: "Aleph plugin for mdx v2"
})]
});
}
}
export default MDXContent;
`,
});
});