-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathdev.rs
More file actions
72 lines (66 loc) · 2.43 KB
/
dev.rs
File metadata and controls
72 lines (66 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use assert_cmd::cargo::cargo_bin_cmd;
use predicates::prelude::*;
#[test]
fn cli_dev_help_shows_template_option() {
let mut cmd = cargo_bin_cmd!("spacetimedb-cli");
cmd.args(["dev", "--help"])
.assert()
.success()
.stdout(predicate::str::contains("--template"))
.stdout(predicate::str::contains("-t"));
}
#[test]
fn cli_dev_accepts_template_flag() {
// This test verifies that the CLI correctly parses the --template flag.
// We use --help after the flag to avoid actually running dev mode,
// but this still validates that the flag is recognized.
let mut cmd = cargo_bin_cmd!("spacetimedb-cli");
// Running with an invalid server should fail, but not because of the template flag
cmd.args(["dev", "--template", "react", "--server", "nonexistent-server-12345"])
.assert()
.failure()
// The error should be about the server, not about an unrecognized --template flag
.stderr(
predicate::str::contains("template")
.not()
.or(predicate::str::contains("unrecognized").not()),
);
}
#[test]
fn cli_dev_accepts_short_template_flag() {
let mut cmd = cargo_bin_cmd!("spacetimedb-cli");
cmd.args(["dev", "-t", "typescript", "--server", "nonexistent-server-12345"])
.assert()
.failure()
// The error should be about the server, not about an unrecognized -t flag
.stderr(
predicate::str::contains("-t")
.not()
.or(predicate::str::contains("unrecognized").not()),
);
}
#[test]
fn cli_init_with_template_creates_project() {
// Test that `spacetime init --template` successfully creates a project
// We use init directly since dev forwards to it for template handling
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
let mut cmd = cargo_bin_cmd!("spacetimedb-cli");
cmd.current_dir(temp_dir.path())
.args([
"init",
"--template",
"basic-rs",
"--local",
"--non-interactive",
"test-project",
])
.assert()
.success();
// Verify expected files were created
let project_dir = temp_dir.path().join("test-project");
assert!(
project_dir.join("spacetimedb").exists(),
"spacetimedb directory should exist"
);
assert!(project_dir.join("src").exists(), "src directory should exist");
}