65 lines
2.3 KiB
Rust
65 lines
2.3 KiB
Rust
use super::*;
|
|
use crate::api::{Server, config};
|
|
|
|
#[test]
|
|
fn component_build_uses_fresh_custom_output_and_stops_on_failure() {
|
|
use std::os::unix::fs::PermissionsExt;
|
|
let root = directory("custom-front");
|
|
let front = root.join("module/demo/front");
|
|
fs::create_dir_all(front.join("src")).unwrap();
|
|
fs::create_dir_all(front.join("dist")).unwrap();
|
|
fs::create_dir_all(root.join("config")).unwrap();
|
|
fs::write(front.join("src/index.html"), "source").unwrap();
|
|
fs::write(front.join("dist/index.html"), "stale").unwrap();
|
|
let desktop = root.join("module/desktop/front");
|
|
fs::create_dir_all(desktop.join("src")).unwrap();
|
|
fs::write(desktop.join("src/desktop.txt"), "desktop artifact").unwrap();
|
|
let script = front.join("build");
|
|
fs::write(&script, "#!/bin/sh\nexit 7\n").unwrap();
|
|
fs::set_permissions(&script, fs::Permissions::from_mode(0o755)).unwrap();
|
|
let (path, port, mut value) = config(&root);
|
|
value["sites"]["front"]["front"] = serde_json::json!({"component":"demo","path":"/"});
|
|
fs::write(&path, value.to_string()).unwrap();
|
|
let binary = root.join("site");
|
|
let args = [
|
|
"build",
|
|
root.to_str().unwrap(),
|
|
"--profile",
|
|
"dev",
|
|
"--output",
|
|
binary.to_str().unwrap(),
|
|
];
|
|
let failed = cli(&args);
|
|
assert!(!failed.status.success());
|
|
assert!(String::from_utf8_lossy(&failed.stderr).contains("exit status: 7"));
|
|
assert!(!binary.exists());
|
|
assert_eq!(
|
|
fs::read_to_string(front.join("dist/index.html")).unwrap(),
|
|
"stale"
|
|
);
|
|
fs::write(
|
|
&script,
|
|
r#"#!/bin/sh
|
|
set -eu
|
|
cat src/index.html > "$1/index.html"
|
|
printf '%s' ' transformed' >> "$1/index.html"
|
|
"#,
|
|
)
|
|
.unwrap();
|
|
success(cli(&args));
|
|
assert_eq!(
|
|
fs::read_to_string(front.join("dist/index.html")).unwrap(),
|
|
"source transformed"
|
|
);
|
|
let server = Server::start(&binary, &path, port);
|
|
let (status, body, _) = server.raw_response("GET", "/", "", "");
|
|
assert_eq!(status, 200);
|
|
assert_eq!(body, "source transformed");
|
|
assert_eq!(
|
|
fs::read_to_string(desktop.join("dist/desktop.txt")).unwrap(),
|
|
"desktop artifact"
|
|
);
|
|
assert_eq!(server.raw_response("GET", "/desktop.txt", "", "").0, 404);
|
|
server.stop();
|
|
}
|