0.0.1-alpha.5.fix.1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/knowledge-web-lib/src/assets.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Vite development and production asset resolution.
|
||||
|
||||
@@ -193,3 +193,7 @@ fn local_static_mount_path(base: &str) -> Option<String> {
|
||||
}
|
||||
return Some(format!("{}/assets", normalized.trim_end_matches('/')));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../unit_tests/assets.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/knowledge-web-lib/src/lib.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Shared Actix Web and Maud composition for the three Knowledge server launchers.
|
||||
//!
|
||||
@@ -22,6 +22,3 @@ pub(crate) use self::assets::ViteAssets;
|
||||
pub(crate) use self::assets::load_assets_from_environment;
|
||||
/// Internal Maud renderer for the public foundation page.
|
||||
pub(crate) use self::page::render_index_page;
|
||||
|
||||
#[cfg(test)]
|
||||
mod unit_tests;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/knowledge-web-lib/src/page.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Maud rendering adapted from the static template-lab contract.
|
||||
|
||||
@@ -50,3 +50,7 @@ fn family_slug(family: knowledge_domain_lib::ContentFamily) -> &'static str {
|
||||
knowledge_domain_lib::ContentFamily::ProjectLocal => return "project-local",
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../unit_tests/page.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
// file: crates/knowledge-web-lib/src/unit_tests.rs
|
||||
// version: 1
|
||||
|
||||
//! Unit tests for shared Web composition primitives.
|
||||
|
||||
#[test]
|
||||
fn development_assets_include_vite_client_before_main_entry() {
|
||||
let assets = match crate::ViteAssets::development("http://127.0.0.1:5173/") {
|
||||
Ok(value) => value,
|
||||
Err(error) => {
|
||||
assert!(error.is_empty(), "unexpected development asset error: {error}");
|
||||
return;
|
||||
},
|
||||
};
|
||||
assert_eq!(assets.scripts().len(), 2);
|
||||
assert_eq!(assets.scripts()[0], "http://127.0.0.1:5173/@vite/client");
|
||||
assert_eq!(assets.scripts()[1], "http://127.0.0.1:5173/src/main.ts");
|
||||
assert!(assets.stylesheets().is_empty());
|
||||
assert!(assets.static_assets_directory().is_none());
|
||||
assert!(assets.static_mount_path().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn production_manifest_resolves_hashes_and_asset_base() {
|
||||
let manifest = r#"{
|
||||
"src/main.ts": {
|
||||
"file": "assets/main-abc.js",
|
||||
"css": ["assets/main-def.css"],
|
||||
"isEntry": true
|
||||
}
|
||||
}"#;
|
||||
let assets = match crate::ViteAssets::from_manifest_text(manifest, "/", std::path::PathBuf::from("/tmp/knowledge-assets")) {
|
||||
Ok(value) => value,
|
||||
Err(error) => {
|
||||
assert!(error.is_empty(), "unexpected manifest error: {error}");
|
||||
return;
|
||||
},
|
||||
};
|
||||
assert_eq!(assets.scripts().len(), 1);
|
||||
assert_eq!(assets.scripts()[0], "/assets/main-abc.js");
|
||||
assert_eq!(assets.stylesheets().len(), 1);
|
||||
assert_eq!(assets.stylesheets()[0], "/assets/main-def.css");
|
||||
assert_eq!(assets.static_assets_directory(), Some(std::path::Path::new("/tmp/knowledge-assets")));
|
||||
assert_eq!(assets.static_mount_path(), Some("/assets"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manifest_requires_the_stable_main_entry() {
|
||||
let manifest = r#"{"index.html": {"file": "assets/index.js", "isEntry": true}}"#;
|
||||
let result = crate::ViteAssets::from_manifest_text(manifest, "/", std::path::PathBuf::from("/tmp/knowledge-assets"));
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn maud_page_uses_resolved_assets_and_site_identity() {
|
||||
let assets = match crate::ViteAssets::from_manifest_text(
|
||||
r#"{"src/main.ts": {"file": "assets/main.js", "css": ["assets/main.css"], "isEntry": true}}"#,
|
||||
"/",
|
||||
std::path::PathBuf::from("/tmp/knowledge-assets"),
|
||||
) {
|
||||
Ok(value) => value,
|
||||
Err(error) => {
|
||||
assert!(error.is_empty(), "unexpected manifest error: {error}");
|
||||
return;
|
||||
},
|
||||
};
|
||||
let rendered = crate::render_index_page(crate::ServerSite::Pgr, &assets).into_string();
|
||||
assert!(rendered.contains("SaseDev Knowledge — PGR"));
|
||||
assert!(rendered.contains("/assets/main.js"));
|
||||
assert!(rendered.contains("/assets/main.css"));
|
||||
assert!(rendered.contains("data-content-family=\"pgr\""));
|
||||
}
|
||||
Reference in New Issue
Block a user