Files
sausage/host/tests/it/plan_todos.rs
T

78 lines
2.4 KiB
Rust

//! The plan and todos ports run through real world extension snapshots and survive restart.
use sausage::world::World;
use std::path::Path;
const BUNDLE: &str = include_str!("../../js/plan-todos-test-bundle.js");
#[tokio::test(flavor = "current_thread")]
async fn plan_todos_and_restart() -> anyhow::Result<()> {
let target = crate::common::build_git();
let dir = tempfile::tempdir()?;
let disk = dir.path().join("world");
let _world = World::open(dir.path())?;
std::fs::create_dir_all(disk.join("bin"))?;
for binary in ["git", "tar"] {
std::fs::copy(
target.join(format!("wasm32-wasip2/release/{binary}.wasm")),
disk.join(format!("bin/{binary}.wasm")),
)?;
}
let repo = disk.join("src/sausage");
std::fs::create_dir_all(&repo)?;
assert!(
std::process::Command::new("git")
.args(["init", "-b", "main"])
.arg(&repo)
.status()?
.success()
);
for name in ["plan", "todos"] {
let destination = repo.join("extensions").join(name);
std::fs::create_dir_all(&destination)?;
std::fs::copy(
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../extensions")
.join(name)
.join("server.ts"),
destination.join("server.ts"),
)?;
}
assert!(
std::process::Command::new("git")
.args(["add", "."])
.current_dir(&repo)
.status()?
.success()
);
assert!(
std::process::Command::new("git")
.args([
"-c",
"user.name=Test",
"-c",
"user.email=test@example.com",
"commit",
"--no-gpg-sign",
"-m",
"plan and todos"
])
.current_dir(&repo)
.status()?
.success()
);
for restart in [false, true] {
let world = World::open(dir.path())?;
let exec = sausage::process::exec(World {
root: world.root.clone(),
host_dir: world.host_dir.clone(),
processes: world.processes.clone(),
})?;
sausage::harness::run_module(
world,
exec,
&format!("globalThis.planTodosRestart={restart};\n{BUNDLE}"),
)
.await?;
}
Ok(())
}