mini-build 0.1.0

Builds the directory a static server serves: CSS/JS bundling and minification via external tools, plus asset mirroring.
Documentation
use super::*;

use std::time::Duration;

#[test]
fn broadcaster_delivers_events_to_subscribers() {
    let broadcaster = Broadcaster::new();
    let rx = broadcaster.subscribe();

    let event = ChangeEvent {
        path: PathBuf::from("style.css"),
        change_type: ChangeType::Css,
    };
    broadcaster.broadcast(event.clone());

    // Bounded rather than a bare `recv()`: a broken broadcaster would hang the suite
    // instead of failing it.
    let received = rx
        .recv_timeout(Duration::from_secs(1))
        .expect("no event arrived within the timeout");
    assert_eq!(received.path, event.path);
    assert_eq!(received.change_type, event.change_type);
}

#[test]
fn broadcaster_tracks_subscriber_count() {
    let broadcaster = Broadcaster::new();
    assert_eq!(broadcaster.subscriber_count(), 0);

    let _rx1 = broadcaster.subscribe();
    assert_eq!(broadcaster.subscriber_count(), 1);

    let _rx2 = broadcaster.subscribe();
    assert_eq!(broadcaster.subscriber_count(), 2);

    drop(_rx1);
    broadcaster.broadcast(ChangeEvent {
        path: PathBuf::from("file.js"),
        change_type: ChangeType::Script,
    });
    assert_eq!(broadcaster.subscriber_count(), 1);
}

/// Classification decides which pipeline owns a file, so it is behavior rather than a
/// convenience: a misclassified `.mjs` would be copied instead of minified.
#[test]
fn change_type_classifies_by_extension() {
    assert_eq!(ChangeType::from_path(Path::new("a.css")), ChangeType::Css);
    assert_eq!(ChangeType::from_path(Path::new("a.js")), ChangeType::Script);
    assert_eq!(
        ChangeType::from_path(Path::new("a.mjs")),
        ChangeType::Script
    );
    assert_eq!(ChangeType::from_path(Path::new("a.html")), ChangeType::Html);
    assert_eq!(ChangeType::from_path(Path::new("a.htm")), ChangeType::Html);
    assert_eq!(ChangeType::from_path(Path::new("a.png")), ChangeType::Other);
    assert_eq!(ChangeType::from_path(Path::new("noext")), ChangeType::Other);
}

#[test]
fn change_type_names_are_stable() {
    assert_eq!(ChangeType::Css.as_str(), "css");
    assert_eq!(ChangeType::Script.as_str(), "script");
    assert_eq!(ChangeType::Html.as_str(), "html");
    assert_eq!(ChangeType::Other.as_str(), "other");
}