use assert_cmd::Command;
use predicates::str::contains;
use tempfile::tempdir;
#[test]
fn graph_without_an_entry_says_what_is_missing() {
let d = tempdir().unwrap();
std::fs::write(d.path().join("package.json"), "{}").unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.arg("graph")
.assert()
.failure()
.stderr(contains("--entry"))
.stderr(contains("export const app = createApp"));
}
#[test]
fn explain_rejects_an_entry_that_does_not_exist() {
let d = tempdir().unwrap();
std::fs::write(d.path().join("package.json"), "{}").unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["explain", "/users", "--entry", "src/nope.ts"])
.assert()
.failure()
.stderr(contains("no such entry"));
}
#[test]
fn graph_without_a_runtime_says_so() {
let d = tempdir().unwrap();
std::fs::create_dir_all(d.path().join("src")).unwrap();
std::fs::write(d.path().join("src/app.ts"), "export const app = {};\n").unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.arg("graph")
.assert()
.failure()
.stderr(contains("no runtime detected"));
}
#[test]
fn graph_rejects_an_unknown_format() {
let d = tempdir().unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["graph", "--format", "svg"])
.assert()
.failure();
}
#[test]
fn openapi_without_an_entry_says_what_is_missing() {
let d = tempdir().unwrap();
std::fs::write(d.path().join("package.json"), "{}").unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.arg("openapi")
.assert()
.failure()
.stderr(contains("--entry"));
}