Skip to content

Commit

Permalink
test: add test for define_command
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Sep 6, 2024
1 parent a39829d commit 5336d16
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .changeset/short-lamps-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
26 changes: 26 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ pub fn define_command(options: Command) -> Command {
options
}

#[cfg(test)]
mod tests {
use crate::command::{define_command, Command};
use crate::types::CommandMeta;

#[test]
fn test_define_command() {
let meta = CommandMeta {
name: Some("test".to_string()),
version: Some("1.0.0".to_string()),
about: Some("test case".to_string()),
styled: Some(false),
};
let cmd = Command {
meta: meta.clone(),
options: Default::default(),
callback: None,
subcommands: None,
};

let defined_cmd = define_command(cmd);

assert_eq!(defined_cmd.meta, meta);
}
}

/// Run command
///
/// **NOTE**: If the given `args` is empty, it will use `process.argv` instead.
Expand Down
4 changes: 2 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Context {

/// Command metadata
#[napi(object)]
#[derive(Clone)]
#[derive(Clone, Debug, PartialEq)]
pub struct CommandMeta {
/// Command name
///
Expand Down Expand Up @@ -183,7 +183,7 @@ pub struct CommandOption {
pub struct Command {
pub meta: CommandMeta,
pub options: HashMap<String, CommandOption>,
#[napi(ts_type = "(ctx: Context) => void")]
#[napi(ts_type = "(ctx: Context) => void ")]
pub callback: Option<JsFunction>,
pub subcommands: Option<HashMap<String, Command>>,
}

0 comments on commit 5336d16

Please sign in to comment.