Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ futures = "0.3.30"
tokio = { version = "1.39.2", features = ["full"] }
pretty_assertions = "1.4.0"
insta = { version = "1.39.0", features = ["json"] }
html5ever = "0.27.0"
markup5ever_rcdom = "0.3.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
url = "2.4.1"
Expand Down
12 changes: 11 additions & 1 deletion src/html/templates/pages/redirect.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
<meta http-equiv="refresh" content="0; url={{path}}">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0; url={{path}}" />
<title>Redirecting…</title>
</head>
<body>
<a href="{{path}}">Click here if you are not redirected.</a>
</body>
</html>
88 changes: 87 additions & 1 deletion tests/html_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ async fn html_doc_files_single() {
id_prefix: None,
diff_only: false,
},
get_files("single").await,
get_files(std::env::var("PROBE_DS").as_deref().unwrap_or("single")).await,
None,
)
.unwrap();
Expand Down Expand Up @@ -947,3 +947,89 @@ export function hello(): string {
ul_depth
);
}

// Parse every generated HTML file with a real HTML5 parser and assert it has
// no parse errors (missing closing tags, mismatched/invalid markup, etc.).
// See issue #634.
fn assert_generated_html_is_valid(
files: &std::collections::HashMap<String, String>,
) {
use html5ever::parse_document;
use html5ever::tendril::TendrilSink;
use markup5ever_rcdom::RcDom;

let mut names: Vec<_> = files.keys().collect();
names.sort();

for name in names {
if !name.ends_with(".html") {
continue;
}
let content = &files[name];
let dom = parse_document(RcDom::default(), Default::default())
.from_utf8()
.read_from(&mut content.as_bytes())
.unwrap();
assert!(
dom.errors.is_empty(),
"generated HTML for {name} is not valid: {:?}",
dom.errors
);
}
}

#[tokio::test]
async fn html_output_is_valid() {
// Validate the "multiple" fixture: it exercises the widest range of output
// (classes, interfaces, enums, type aliases, namespaces, drilldown member
// pages, redirects, and the all-symbols/index pages).
let multiple_dir = std::env::current_dir()
.unwrap()
.join("tests")
.join("testdata")
.join("multiple");
let mut rewrite_map = IndexMap::new();
rewrite_map.insert(
ModuleSpecifier::from_file_path(multiple_dir.join("a.ts")).unwrap(),
".".to_string(),
);
rewrite_map.insert(
ModuleSpecifier::from_file_path(multiple_dir.join("b.ts")).unwrap(),
"foo".to_string(),
);
rewrite_map.insert(
ModuleSpecifier::from_file_path(multiple_dir.join("c.ts")).unwrap(),
"c".to_string(),
);
rewrite_map.insert(
ModuleSpecifier::from_file_path(multiple_dir.join("_d.ts")).unwrap(),
"d".to_string(),
);

let ctx = GenerateCtx::create_basic(
GenerateOptions {
package_name: None,
main_entrypoint: Some(
ModuleSpecifier::from_file_path(multiple_dir.join("a.ts")).unwrap(),
),
href_resolver: Arc::new(EmptyResolver),
usage_composer: Some(Arc::new(EmptyResolver)),
rewrite_map: Some(rewrite_map),
category_docs: None,
disable_search: false,
symbol_redirect_map: None,
default_symbol_map: None,
markdown_renderer: comrak::create_renderer(None, None, None),
markdown_stripper: Arc::new(comrak::strip),
head_inject: None,
id_prefix: None,
diff_only: false,
},
get_files("multiple").await,
None,
)
.unwrap();
let files = generate(ctx).unwrap();

assert_generated_html_is_valid(&files);
}
12 changes: 11 additions & 1 deletion tests/snapshots/html_test__html_doc_files_multiple-11.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@
source: tests/html_test.rs
expression: files.get(file_name).unwrap()
---
<meta http-equiv="refresh" content="0; url=..&#x2F;.&#x2F;.&#x2F;~&#x2F;B.html">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0; url=..&#x2F;.&#x2F;.&#x2F;~&#x2F;B.html" />
<title>Redirecting…</title>
</head>
<body>
<a href="..&#x2F;.&#x2F;.&#x2F;~&#x2F;B.html">Click here if you are not redirected.</a>
</body>
</html>
12 changes: 11 additions & 1 deletion tests/snapshots/html_test__html_doc_files_multiple-13.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@
source: tests/html_test.rs
expression: files.get(file_name).unwrap()
---
<meta http-equiv="refresh" content="0; url=..&#x2F;.&#x2F;.&#x2F;~&#x2F;Bar.html">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0; url=..&#x2F;.&#x2F;.&#x2F;~&#x2F;Bar.html" />
<title>Redirecting…</title>
</head>
<body>
<a href="..&#x2F;.&#x2F;.&#x2F;~&#x2F;Bar.html">Click here if you are not redirected.</a>
</body>
</html>
12 changes: 11 additions & 1 deletion tests/snapshots/html_test__html_doc_files_multiple-29.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@
source: tests/html_test.rs
expression: files.get(file_name).unwrap()
---
<meta http-equiv="refresh" content="0; url=..&#x2F;.&#x2F;.&#x2F;~&#x2F;Foo.html">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0; url=..&#x2F;.&#x2F;.&#x2F;~&#x2F;Foo.html" />
<title>Redirecting…</title>
</head>
<body>
<a href="..&#x2F;.&#x2F;.&#x2F;~&#x2F;Foo.html">Click here if you are not redirected.</a>
</body>
</html>
12 changes: 11 additions & 1 deletion tests/snapshots/html_test__html_doc_files_multiple-38.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@
source: tests/html_test.rs
expression: files.get(file_name).unwrap()
---
<meta http-equiv="refresh" content="0; url=..&#x2F;.&#x2F;.&#x2F;~&#x2F;Foobar.html">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0; url=..&#x2F;.&#x2F;.&#x2F;~&#x2F;Foobar.html" />
<title>Redirecting…</title>
</head>
<body>
<a href="..&#x2F;.&#x2F;.&#x2F;~&#x2F;Foobar.html">Click here if you are not redirected.</a>
</body>
</html>
Loading
Loading