Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
+21
-15
@@ -9,6 +9,7 @@ use std::{
|
||||
net::{TcpListener, TcpStream},
|
||||
path::{Path, PathBuf},
|
||||
process::{Child, Command, Stdio},
|
||||
sync::Arc,
|
||||
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
@@ -39,10 +40,18 @@ impl Response {
|
||||
struct TestServer {
|
||||
child: Child,
|
||||
port: u16,
|
||||
root: PathBuf,
|
||||
fixture: Arc<ServerFixture>,
|
||||
marker: String,
|
||||
}
|
||||
|
||||
struct ServerFixture(PathBuf);
|
||||
|
||||
impl Drop for ServerFixture {
|
||||
fn drop(&mut self) {
|
||||
let _ = fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl TestServer {
|
||||
fn start(label: &str) -> Self {
|
||||
Self::start_with_env(label, &[])
|
||||
@@ -53,10 +62,11 @@ impl TestServer {
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.expect("clock")
|
||||
.as_nanos();
|
||||
let root = std::env::temp_dir().join(format!(
|
||||
let fixture = Arc::new(ServerFixture(std::env::temp_dir().join(format!(
|
||||
"texrra-test-{label}-{}-{stamp}",
|
||||
std::process::id()
|
||||
));
|
||||
))));
|
||||
let root = &fixture.0;
|
||||
let web = root.join("web");
|
||||
fs::create_dir_all(&web).expect("create web dir");
|
||||
let marker = format!("marker-{stamp}");
|
||||
@@ -81,7 +91,7 @@ impl TestServer {
|
||||
.arg("serve")
|
||||
.arg(root.join("hello.tex"))
|
||||
.arg(port.to_string())
|
||||
.current_dir(&root)
|
||||
.current_dir(root)
|
||||
.env("TEXRRA_WEB_DIR", &web)
|
||||
.env("TEXRRA_PROJECTS_DIR", root.join("projects"))
|
||||
.stdout(Stdio::null())
|
||||
@@ -93,15 +103,12 @@ impl TestServer {
|
||||
let mut server = Self {
|
||||
child,
|
||||
port,
|
||||
root: root.clone(),
|
||||
fixture: Arc::clone(&fixture),
|
||||
marker: marker.clone(),
|
||||
};
|
||||
match server.wait_ready() {
|
||||
Ok(()) => return server,
|
||||
Err(message) if message.contains("Address already in use") => {
|
||||
let _ = server.child.kill();
|
||||
let _ = server.child.wait();
|
||||
}
|
||||
Err(message) if message.contains("Address already in use") => {}
|
||||
Err(message) => panic!("{message}"),
|
||||
}
|
||||
}
|
||||
@@ -142,7 +149,7 @@ impl TestServer {
|
||||
}
|
||||
|
||||
fn log(&self) -> String {
|
||||
fs::read_to_string(self.root.join("server.log")).unwrap_or_default()
|
||||
fs::read_to_string(self.fixture.0.join("server.log")).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn request(&self, method: &str, path: &str, body: &[u8], content_type: &str) -> Response {
|
||||
@@ -175,7 +182,6 @@ impl Drop for TestServer {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.child.kill();
|
||||
let _ = self.child.wait();
|
||||
let _ = fs::remove_dir_all(&self.root);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +474,7 @@ fn project_preview_uses_the_engine_default() {
|
||||
value["durationMs"]
|
||||
);
|
||||
let svg = value["pages"][0]["svg"].as_str().unwrap();
|
||||
assert!(svg.contains("font-style=\"italic\""), "{svg}");
|
||||
assert!(svg.contains("data-font=\"CMMI10\""), "{svg}");
|
||||
assert!(!svg.contains('$'), "{svg}");
|
||||
|
||||
let forced = server.request(
|
||||
@@ -530,7 +536,7 @@ fn engine_parameter_overrides_the_environment_default() {
|
||||
);
|
||||
let value: Value = serde_json::from_slice(&default_preview.body).expect("preview JSON");
|
||||
let svg = value["pages"][0]["svg"].as_str().unwrap();
|
||||
assert!(svg.contains("font-style=\"italic\""), "{svg}");
|
||||
assert!(svg.contains("data-font=\"CMMI10\""), "{svg}");
|
||||
|
||||
let v1_preview = route_d.request(
|
||||
"POST",
|
||||
@@ -583,7 +589,7 @@ fn engine_parameter_overrides_the_environment_default() {
|
||||
);
|
||||
let value: Value = serde_json::from_slice(&forced.body).expect("preview JSON");
|
||||
let svg = value["pages"][0]["svg"].as_str().unwrap();
|
||||
assert!(svg.contains("font-style=\"italic\""), "{svg}");
|
||||
assert!(svg.contains("data-font=\"CMMI10\""), "{svg}");
|
||||
let forced_pdf = v1.request(
|
||||
"POST",
|
||||
"/api/projects/hello/pdf?engine=route-d",
|
||||
@@ -2507,7 +2513,7 @@ fn project_preview_defaults_to_route_d_without_env() {
|
||||
assert_eq!(preview.status, 200, "{}", preview.text());
|
||||
let value: Value = serde_json::from_slice(&preview.body).expect("preview JSON");
|
||||
let svg = value["pages"][0]["svg"].as_str().unwrap();
|
||||
assert!(svg.contains("font-style=\"italic\""), "{svg}");
|
||||
assert!(svg.contains("data-font=\"CMMI10\""), "{svg}");
|
||||
assert!(!svg.contains('$'), "{svg}");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user