forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdx-test.ts
121 lines (101 loc) · 3.09 KB
/
mdx-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
import { test, expect } from "@playwright/test";
import {
createAppFixture,
createFixture,
js,
mdx,
} from "./helpers/create-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { PlaywrightFixture } from "./helpers/playwright-fixture";
test.describe("mdx", () => {
let fixture: Fixture;
let appFixture: AppFixture;
test.beforeAll(async () => {
fixture = await createFixture({
files: {
"app/root.jsx": js`
import { json } from "@remix-run/node";
import { Links, Meta, Outlet, Scripts } from "@remix-run/react";
export default function Root() {
return (
<html lang="en">
<head>
<Meta />
<Links />
</head>
<body>
<Outlet />
<Scripts />
</body>
</html>
);
}
`,
"app/routes/blog.jsx": js`
import { json } from "@remix-run/node";
import { useMatches, Outlet } from "@remix-run/react";
export default function Index() {
const matches = useMatches();
const mdxMatch = matches[matches.length - 1];
return (
<div>
<p id="additionalData">{mdxMatch.data.additionalData === 10 && 'Additional Data: 10'}</p>
<p id="handle">{mdxMatch.handle.someData}</p>
<Outlet />
</div>
);
}
`,
"app/routes/blog/post.mdx": mdx`---
meta:
title: My First Post
description: Isn't this awesome?
headers:
Cache-Control: no-cache
---
export const links = () => [
{ rel: "stylesheet", href: "app.css" }
]
export const handle = {
someData: "abc"
}
import { useLoaderData } from '@remix-run/react';
export const loader = async () => {
return { mamboNumber: 5 };
};
export function ComponentUsingData() {
const { mamboNumber } = useLoaderData();
return <div id="loader">Mambo Number: {mamboNumber}</div>;
}
# This is some markdown!
<ComponentUsingData />
`.trim(),
"app/routes/basic.mdx": mdx`
# This is some basic markdown!
`.trim(),
},
});
appFixture = await createAppFixture(fixture);
});
test.afterAll(async () => {
await appFixture.close();
});
test("can render basic markdown", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/basic");
expect(await app.getHtml()).toMatch("This is some basic markdown!");
});
test("supports links, meta, headers, handle, and loader", async ({
page,
}) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/blog/post");
expect(await app.getHtml('meta[name="description"]')).toMatch(
"Isn't this awesome?"
);
expect(await app.getHtml("title")).toMatch("My First Post");
expect(await app.getHtml("#loader")).toMatch(/Mambo Number:.+5/s);
expect(await app.getHtml("#handle")).toMatch("abc");
expect(await app.getHtml('link[rel="stylesheet"]')).toMatch("app.css");
});
});