Files
matcha/tests/new.rs
T
chrnx 757b729986 fix(add): merge imports into existing brace + capability idempotency; fmt
- wire::add_import now merges a new symbol into an already-present
  `import { ... } from '<from>';` brace instead of appending a second,
  colliding import line for the same module (a duplicate ESM binding
  is a hard SyntaxError/TS2300, not a harmless dupe as previously
  assumed). Falls back to appending a new line when the module isn't
  imported yet, or if the brace-merge edit fails the parses_clean
  guard.
- cmd_add::run gains a capability-level idempotency guard, keyed on
  each capability's unique route-path literal, so `matcha add <cap>`
  run twice no longer appends a duplicate handler + route.
- cargo fmt --all across the crate; drop the stale #[allow(dead_code)]
  on wire::parses_clean now that it's demonstrably live.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-07-11 13:52:21 -05:00

72 lines
1.8 KiB
Rust

use assert_cmd::Command;
use std::process::Command as Proc;
use tempfile::tempdir;
#[test]
fn new_scaffolds_into_named_dir() {
let d = tempdir().unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["new", "my-api"])
.assert()
.success();
let root = d.path().join("my-api");
assert!(root.join("src/app.module.ts").exists());
assert!(root.join("public/index.html").exists());
}
#[test]
fn new_refuses_existing_dir() {
let d = tempdir().unwrap();
std::fs::create_dir(d.path().join("taken")).unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["new", "taken"])
.assert()
.failure();
}
#[test]
fn new_clones_local_template() {
let d = tempdir().unwrap();
// build a bare-ish source repo to clone
let src = d.path().join("src-tmpl");
std::fs::create_dir_all(src.join("public")).unwrap();
std::fs::write(src.join("public/marker.txt"), "hi").unwrap();
Proc::new("git")
.args(["init", "-q"])
.current_dir(&src)
.status()
.unwrap();
Proc::new("git")
.args(["add", "."])
.current_dir(&src)
.status()
.unwrap();
Proc::new("git")
.args([
"-c",
"user.email=t@t",
"-c",
"user.name=t",
"commit",
"-qm",
"init",
])
.current_dir(&src)
.status()
.unwrap();
let url = format!("file://{}", src.display());
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["new", "cloned", "--template-url", &url])
.assert()
.success();
assert!(d.path().join("cloned/public/marker.txt").exists());
assert!(!d.path().join("cloned/.git").exists()); // .git stripped
}