use live_server::{listen, Options};
use reqwest::StatusCode;
#[tokio::test]
async fn request() {
const HOST: &str = "127.0.0.1:8000";
let listener = listen(HOST, "./tests/page").await.unwrap();
tokio::spawn(async {
listener.start(Options::default()).await.unwrap();
});
// Test requesting index.html
let response = reqwest::get(format!("http://{HOST}")).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let content_type = response.headers().get("content-type").unwrap();
assert_eq!(content_type, "text/html");
let text = response.text().await.unwrap().replace("\r\n", "\n");
let target_text = format!(
r#"{}"#,
include_str!("./page/index.html"),
include_str!("../src/templates/websocket.js"),
HOST
)
.replace("\r\n", "\n");
assert_eq!(text, target_text);
assert!(text.contains(""#,
include_str!("./page/index.html"),
include_str!("../src/templates/reload.js"),
)
.replace("\r\n", "\n");
assert_eq!(text, target_text);
// Test requesting non-existent html file with reload query does not inject script
let response = reqwest::get(format!("http://{HOST}/404.html?reload"))
.await
.unwrap();
assert_eq!(response.status(), StatusCode::NOT_FOUND);
let content_type = response.headers().get("content-type").unwrap();
assert_eq!(content_type, "text/html");
let text = response.text().await.unwrap();
assert!(!text.contains("