use anycms_spa::spa;
use rust_embed::RustEmbed;
#[cfg(feature = "axum")]
spa!(ExcludedSpa, "tests/fixtures/site", exclude: ["*.gz", "*.br"]);
#[cfg(feature = "actix")]
spa!(ExcludedSpa, "tests/fixtures/site", exclude: ["*.gz", "*.br"]);
#[cfg(feature = "salvo")]
spa!(ExcludedSpa, "tests/fixtures/site", exclude: ["*.gz", "*.br"]);
#[cfg(feature = "axum")]
spa!(PlainSpa, "tests/fixtures/site");
#[cfg(feature = "actix")]
spa!(PlainSpa, "tests/fixtures/site", { });
#[cfg(feature = "salvo")]
spa!(PlainSpa, "tests/fixtures/site", "/", ["index.html"], { });
fn embedded_paths<E: RustEmbed>() -> Vec<String> {
E::iter().map(|p| p.to_string()).collect()
}
mod nested {
use anycms_spa::spa;
#[cfg(feature = "axum")]
spa!(NestedSpa, "tests/fixtures/site", exclude: ["*.gz", "*.br"]);
#[cfg(feature = "actix")]
spa!(NestedSpa, "tests/fixtures/site", exclude: ["*.gz", "*.br"]);
#[cfg(feature = "salvo")]
spa!(NestedSpa, "tests/fixtures/site", exclude: ["*.gz", "*.br"]);
#[cfg(any(feature = "axum", feature = "actix", feature = "salvo"))]
pub(super) fn embedded_paths() -> Vec<String> {
use rust_embed::RustEmbed;
NestedSpa::iter().map(|p| p.to_string()).collect()
}
}
#[test]
fn exclude_globs_are_not_embedded() {
let paths = embedded_paths::<ExcludedSpa>();
assert!(paths.contains(&"index.html".to_string()));
assert!(paths.contains(&"app.js".to_string()));
assert!(paths.contains(&"data.json".to_string()));
assert!(
!paths.iter().any(|p| p.ends_with(".gz") || p.ends_with(".br")),
"compressed companions leaked into the embed: {paths:?}"
);
}
#[test]
fn legacy_shapes_still_embed_everything() {
let paths = embedded_paths::<PlainSpa>();
assert!(paths.contains(&"app.js.gz".to_string()));
assert!(paths.contains(&"app.js.br".to_string()));
}
#[test]
fn macro_works_inside_nested_module() {
let paths = nested::embedded_paths();
assert!(paths.contains(&"index.html".to_string()));
assert!(
!paths.iter().any(|p| p.ends_with(".gz") || p.ends_with(".br")),
"nested-module invocation leaked companions: {paths:?}"
);
}