#[inline]
pub fn setup_deno_run_command(package_name: &str, executable_name: &str) -> std::process::Command {
    let mut cmd = std::process::Command::new("deno");

    cmd.arg("run");
    cmd.arg("-A");

    if package_name == executable_name {
        cmd.arg(format!("npm:{package_name}"));
    } else {
        cmd.arg(format!("npm:{package_name}/{executable_name}"));
    }

    cmd
}

#[cfg(test)]
mod test_deno {
    #[test_with::executable(deno)]
    #[test]
    fn it_can_execute_an_npm_package_script() -> Result<(), Box<dyn core::error::Error>> {
        let input = "[1,2,3,4,5,6]";
        let output = "[1, 2, 3, 4, 5, 6]\n";

        let file_ext = crate::filetype::get_file_extension("json");

        let snippet = crate::execution::setup_snippet(input, &file_ext)?;

        let result = crate::execution::run_tools(
            &[crate::runners::CommandType::Deno("prettier", "prettier")],
            snippet.path(),
            crate::tools::prettier::set_args,
            crate::testing::DEFAULT_TEST_FORMATTER_TIMEOUT,
            crate::tools::prettier::IS_STDIN,
            crate::testing::DEFAULT_TEST_DEBUG_ENABLED,
            &crate::config::MdsfConfigRunners {
                deno: true,
                ..Default::default()
            },
        )?;

        assert!(!result.0);
        assert_eq!(result.1, Some(output.to_string()));

        Ok(())
    }

    #[test_with::executable(deno)]
    #[test]
    #[ignore]
    fn it_works_with_executable_name() -> Result<(), Box<dyn core::error::Error>> {
        let input = r#"model Pet {  name: string;  age: int32;kind: "dog" | "cat" | "fish";}
"#;

        let output = r#"model Pet {
  name: string;
  age: int32;
  kind: "dog" | "cat" | "fish";
}
"#;

        let file_ext = crate::filetype::get_file_extension("typespec");

        let snippet = crate::execution::setup_snippet(input, &file_ext)?;

        let result = crate::execution::run_tools(
            &[crate::runners::CommandType::Deno(
                "@typespec/compiler",
                "tsp",
            )],
            snippet.path(),
            crate::tools::tsp_format::set_args,
            crate::testing::DEFAULT_TEST_FORMATTER_TIMEOUT,
            crate::tools::tsp_format::IS_STDIN,
            crate::testing::DEFAULT_TEST_DEBUG_ENABLED,
            &crate::config::MdsfConfigRunners {
                deno: true,
                ..Default::default()
            },
        )?;

        assert!(!result.0);
        assert_eq!(result.1, Some(output.to_string()));

        Ok(())
    }
}
