-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssr.ts
45 lines (34 loc) · 969 Bytes
/
ssr.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
/**
* @jest-environment jsdom
*/
import { render } from "@testing-library/react";
import "mock-match-media/polyfill";
import { setMedia } from "mock-match-media";
import { sizes } from "./sizes.util";
import App from "../App";
const inline = new Set(["</b>", "</span>"]);
const prettify = (input: string) =>
input
.replace(/<[^/>]*>/g, ``) // opening tag
.replace(/<\/[^>]*>/g, (match) =>
inline.has(match) ? ` ` : `\n\n`,
) // closing tag
.replace(/\n\n+/g, "\n\n")
.replace(/ +/g, " ")
.replace(/</g, "<")
.replace(/>/g, ">");
const wait = (ms: number) =>
new Promise((res) => setTimeout(res, ms));
it.each(sizes)("Should render in SSR %p", async () => {
for (const size of sizes) {
setMedia({
width: `${size.width}px`,
height: `${size.height}px`,
});
await wait(20);
expect(
prettify(render(App).baseElement.outerHTML),
).toMatchSnapshot();
await wait(20);
}
});