AkurAI Build
Menu

Public repository / master

AkurAI-Framework / crates/assets/tests/pipeline.rs

Latest change 9df51040bf1687e4dc8a91557f02df52e8d5cf3a - feat(assets): content-hash fingerprinting + conservative minifiers by Ólafur Búi Ólafsson

//! End-to-end: fingerprint a minified asset and build its cache-busted name.

use akurai_assets::{fingerprint, hashed_name, minify_css, minify_js};

#[test]
fn fingerprint_round_trip_is_deterministic() {
    let css = minify_css("/* x */ .a {\n  color: red;\n}");
    assert_eq!(css, ".a{color:red}");

    let h1 = fingerprint(css.as_bytes());
    let h2 = fingerprint(css.as_bytes());
    assert_eq!(h1, h2, "same bytes must hash the same");

    let name = hashed_name("app.css", css.as_bytes());
    assert_eq!(name, format!("app.{h1}.css"));
}

#[test]
fn different_minified_output_yields_different_name() {
    let a = minify_css(".a{color:red}");
    let b = minify_css(".a{color:blue}");
    assert_ne!(
        hashed_name("app.css", a.as_bytes()),
        hashed_name("app.css", b.as_bytes())
    );
}

#[test]
fn js_pipeline_preserves_string_and_strips_comment() {
    let js = minify_js("const u = \"http://x\"; // comment\n");
    assert_eq!(js, "const u = \"http://x\";");
    let name = hashed_name("bundle.js", js.as_bytes());
    assert!(name.starts_with("bundle.") && name.ends_with(".js"));
}