Skip to content

Commit 20e2040

Browse files
committed
Add integration test that checks styled-components renders successfully and no incorrect unicode characters are present in the style tag
1 parent 538f73b commit 20e2040

4 files changed

Lines changed: 68 additions & 1 deletion

File tree

integration/scripts/browser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ async function main() {
118118
"/forbid-in-is-correct.js",
119119
"/code-simplification-neql-define.js",
120120
"/spread_with_key.tsx",
121+
"/styledcomponents-output.js",
121122
];
122123
tests.reverse();
123124

integration/snippets/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"dependencies": {
77
"lodash": "^4.17.21",
88
"react": "^17.0.2",
9-
"redux": "^4.1.1"
9+
"react-dom": "^17.0.2",
10+
"redux": "^4.1.1",
11+
"styled-components": "^5.3.1"
1012
}
1113
}

integration/snippets/public/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
</head>
88
<body>
99
<script type="module">
10+
globalThis.console.assert = (condition, ...content) => {
11+
if (!condition) {
12+
throw new Error(content.join(" "));
13+
14+
}
15+
};
1016
globalThis.getModuleScriptSrc = async (name) => {
1117
const response = await fetch(name, {
1218
cache: "force-cache",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import styled from "styled-components";
2+
import React from "react";
3+
import ReactDOM from "react-dom";
4+
5+
const ErrorScreenRoot = styled.div`
6+
font-family: "Muli", -apple-system, BlinkMacSystemFont, Helvetica, Arial,
7+
sans-serif;
8+
position: fixed;
9+
top: 0;
10+
left: 0;
11+
width: 100vw;
12+
height: 100vh;
13+
display: flex;
14+
flex-direction: column;
15+
justify-content: center;
16+
align-items: center;
17+
background: #fff;
18+
text-align: center;
19+
background-color: #0b2988;
20+
color: #fff;
21+
font-family: "Muli", -apple-system, BlinkMacSystemFont, Helvetica, Arial,
22+
sans-serif;
23+
line-height: 1.5em;
24+
25+
& > p {
26+
margin-top: 10px;
27+
}
28+
29+
& a {
30+
color: inherit;
31+
}
32+
`;
33+
34+
export function test() {
35+
const reactEl = document.createElement("div");
36+
document.body.appendChild(reactEl);
37+
ReactDOM.render(
38+
<ErrorScreenRoot id="error-el">
39+
This is an error! Look for the string
40+
</ErrorScreenRoot>,
41+
reactEl
42+
);
43+
44+
const style = document.querySelector("style[data-styled]");
45+
console.assert(style, "style tag should exist");
46+
console.assert(
47+
style.textContent.split("").every((a) => a.codePointAt(0) < 128),
48+
"style tag should not contain invalid unicode codepoints"
49+
);
50+
console.assert(
51+
document.querySelector("#error-el").textContent ===
52+
"This is an error! Look for the string"
53+
);
54+
55+
ReactDOM.unmountComponentAtNode(reactEl);
56+
reactEl.remove();
57+
testDone(import.meta.url);
58+
}

0 commit comments

Comments
 (0)