Skip to content

Commit c4e9bf8

Browse files
authored
test: add snapshot testing of html output (#573)
1 parent fc6c8f3 commit c4e9bf8

File tree

41 files changed

+2906
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2906
-12
lines changed

Cargo.lock

Lines changed: 128 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ criterion = { version = "0.4.0", features = ["async_futures", "html_reports"] }
7070
file_test_runner = "0.2.0"
7171
tokio = { version = "1.25.0", features = ["full"] }
7272
pretty_assertions = "1.0.0"
73+
insta = "1.38.0"
7374

7475
[features]
7576
default = ["html", "rust", "ammonia"]

tests/html_test.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,24 @@ async fn html_doc_files() {
167167
"styles.css",
168168
]
169169
);
170+
171+
#[cfg(all(not(feature = "syntect"), not(feature = "tree-sitter")))]
172+
{
173+
insta::assert_snapshot!(files.get("./all_symbols.html").unwrap());
174+
insta::assert_snapshot!(files.get("./index.html").unwrap());
175+
insta::assert_snapshot!(files.get("./~/Bar.html").unwrap());
176+
insta::assert_snapshot!(files.get("./~/Bar.prototype.html").unwrap());
177+
insta::assert_snapshot!(files.get("./~/Foo.html").unwrap());
178+
insta::assert_snapshot!(files.get("./~/Foo.prototype.html").unwrap());
179+
insta::assert_snapshot!(files.get("./~/Foobar.html").unwrap());
180+
insta::assert_snapshot!(files.get("./~/Foobar.prototype.html").unwrap());
181+
insta::assert_snapshot!(files.get("fuse.js").unwrap());
182+
insta::assert_snapshot!(files.get("page.css").unwrap());
183+
insta::assert_snapshot!(files.get("script.js").unwrap());
184+
insta::assert_snapshot!(files.get("search.js").unwrap());
185+
insta::assert_snapshot!(files.get("search_index.js").unwrap());
186+
insta::assert_snapshot!(files.get("styles.css").unwrap());
187+
}
170188
}
171189

172190
#[tokio::test]
@@ -231,6 +249,36 @@ async fn html_doc_files_rewrite() {
231249
"styles.css"
232250
]
233251
);
252+
253+
#[cfg(all(not(feature = "syntect"), not(feature = "tree-sitter")))]
254+
{
255+
insta::assert_snapshot!(files.get("./all_symbols.html").unwrap());
256+
insta::assert_snapshot!(files.get("./index.html").unwrap());
257+
insta::assert_snapshot!(files.get("./~/Bar.html").unwrap());
258+
insta::assert_snapshot!(files.get("./~/Bar.prototype.html").unwrap());
259+
insta::assert_snapshot!(files.get("./~/Baz.html").unwrap());
260+
insta::assert_snapshot!(files.get("./~/Baz.foo.html").unwrap());
261+
insta::assert_snapshot!(files.get("./~/Foo.html").unwrap());
262+
insta::assert_snapshot!(files.get("./~/Foo.bar.html").unwrap());
263+
insta::assert_snapshot!(files
264+
.get("./~/Foo.prototype.\"><img src=x onerror=alert(1)>.html")
265+
.unwrap());
266+
insta::assert_snapshot!(files.get("./~/Foo.prototype.foo.html").unwrap());
267+
insta::assert_snapshot!(files.get("./~/Foo.prototype.html").unwrap());
268+
insta::assert_snapshot!(files.get("./~/Foobar.html").unwrap());
269+
insta::assert_snapshot!(files.get("./~/Foobar.prototype.html").unwrap());
270+
insta::assert_snapshot!(files.get("./~/Hello.html").unwrap());
271+
insta::assert_snapshot!(files.get("./~/Hello.world.html").unwrap());
272+
insta::assert_snapshot!(files.get("./~/index.html").unwrap());
273+
insta::assert_snapshot!(files.get("foo/~/index.html").unwrap());
274+
insta::assert_snapshot!(files.get("foo/~/x.html").unwrap());
275+
insta::assert_snapshot!(files.get("fuse.js").unwrap());
276+
insta::assert_snapshot!(files.get("page.css").unwrap());
277+
insta::assert_snapshot!(files.get("script.js").unwrap());
278+
insta::assert_snapshot!(files.get("search.js").unwrap());
279+
insta::assert_snapshot!(files.get("search_index.js").unwrap());
280+
insta::assert_snapshot!(files.get("styles.css").unwrap());
281+
}
234282
}
235283

236284
#[tokio::test]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: tests/html_test.rs
3+
expression: "files.get(\"page.css\").unwrap()"
4+
---
5+
*,:before,:after{box-sizing:border-box;border:0 solid #e5e7eb}:before,:after{--tw-content:""}html,:host{-webkit-text-size-adjust:100%;tab-size:4;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;line-height:1.5}body{line-height:inherit;margin:0}hr{color:inherit;border-top-width:1px;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-feature-settings:normal;font-variation-settings:normal;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-feature-settings:inherit;font-variation-settings:inherit;font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:#0000;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{margin:0;padding:0;list-style:none}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder{opacity:1;color:#9ca3af}textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}[hidden]{display:none}*,:before,:after,::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }.mb-6{margin-bottom:1.5rem}.block{display:block}.flex{display:flex}.flex-1{flex:1}.items-center{align-items:center}.justify-between{justify-content:space-between}.gap-2{gap:.5rem}.gap-2\.5{gap:.625rem}.gap-4{gap:1rem}.overflow-hidden{overflow:hidden}.text-ellipsis{text-overflow:ellipsis}.whitespace-nowrap{white-space:nowrap}.rounded{border-radius:.25rem}.rounded-lg{border-radius:.5rem}.border{border-width:1px}.border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity))}.bg-transparent{background-color:#0000}.px-2{padding-left:.5rem;padding-right:.5rem}.px-2\.5{padding-left:.625rem;padding-right:.625rem}.px-3{padding-left:.75rem;padding-right:.75rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xs{font-size:.75rem;line-height:1rem}.italic{font-style:italic}.leading-none{line-height:1}.text-stone-400{--tw-text-opacity:1;color:rgb(168 162 158/var(--tw-text-opacity))}.blur{--tw-blur:blur(8px);filter:var(--tw-blur)var(--tw-brightness)var(--tw-contrast)var(--tw-grayscale)var(--tw-hue-rotate)var(--tw-invert)var(--tw-saturate)var(--tw-sepia)var(--tw-drop-shadow)}body{width:100%;max-width:1280px;margin-left:auto;margin-right:auto;padding:1.75rem;overflow-x:hidden}#content{gap:1.5rem;display:flex;position:relative}#content>main{flex:1}.toc{box-sizing:border-box;flex:none;width:16rem;max-height:100vh;position:sticky;top:0}@media not all and (min-width:1024px){.toc{display:none}}.toc>div{max-height:100%;overflow-y:scroll}.toc>div>:last-child{padding-bottom:1rem}#searchResults{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity));display:none;position:absolute;inset:0}.hover\:bg-stone-100:hover{--tw-bg-opacity:1;background-color:rgb(245 245 244/var(--tw-bg-opacity))}@media not all and (min-width:1024px){.max-lg\:flex-col-reverse{flex-direction:column-reverse}}@media (min-width:1024px){.lg\:max-w-80{max-width:20rem}.lg\:items-center{align-items:center}}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
source: tests/html_test.rs
3+
expression: "files.get(\"script.js\").unwrap()"
4+
---
5+
function findParent(el, find) {
6+
do {
7+
if (find(el)) {
8+
return el;
9+
}
10+
} while (el = el.parentElement);
11+
}
12+
13+
document.addEventListener("click", (e) => {
14+
const target = findParent(
15+
e.target,
16+
(el) => el instanceof HTMLButtonElement && el.dataset["copy"],
17+
);
18+
if (target) {
19+
navigator?.clipboard?.writeText(target.dataset["copy"]);
20+
}
21+
});
22+
23+
window.addEventListener("load", () => {
24+
const usageSelector = document.getElementById("usageSelector");
25+
26+
document.addEventListener("mouseup", (e) => {
27+
if (
28+
findParent(
29+
e.target,
30+
(el) =>
31+
el.parentElement === usageSelector && el instanceof HTMLDivElement,
32+
)
33+
) {
34+
usageSelector.open = false;
35+
}
36+
});
37+
});

0 commit comments

Comments
 (0)