mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
fix(init): suppress info logs when using quiet mode (#15741)
This commit is contained in:
parent
b162a57ab5
commit
8de6411b79
3 changed files with 77 additions and 17 deletions
|
@ -6006,5 +6006,15 @@ mod tests {
|
|||
..Flags::default()
|
||||
}
|
||||
);
|
||||
|
||||
let r = flags_from_vec(svec!["deno", "init", "--quiet"]);
|
||||
assert_eq!(
|
||||
r.unwrap(),
|
||||
Flags {
|
||||
subcommand: DenoSubcommand::Init(InitFlags { dir: None }),
|
||||
log_level: Some(Level::Error),
|
||||
..Flags::default()
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,17 +15,17 @@ fn init_subcommand_without_dir() {
|
|||
let output = deno_cmd
|
||||
.current_dir(cwd)
|
||||
.arg("init")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
assert_contains!(stdout, "Project initialized");
|
||||
assert!(!stdout.contains("cd"));
|
||||
assert_contains!(stdout, "deno run main.ts");
|
||||
assert_contains!(stdout, "deno test");
|
||||
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||
assert_contains!(stderr, "Project initialized");
|
||||
assert!(!stderr.contains("cd"));
|
||||
assert_contains!(stderr, "deno run main.ts");
|
||||
assert_contains!(stderr, "deno test");
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
|
@ -67,17 +67,17 @@ fn init_subcommand_with_dir_arg() {
|
|||
.current_dir(cwd)
|
||||
.arg("init")
|
||||
.arg("my_dir")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
assert_contains!(stdout, "Project initialized");
|
||||
assert_contains!(stdout, "cd my_dir");
|
||||
assert_contains!(stdout, "deno run main.ts");
|
||||
assert_contains!(stdout, "deno test");
|
||||
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||
assert_contains!(stderr, "Project initialized");
|
||||
assert_contains!(stderr, "cd my_dir");
|
||||
assert_contains!(stderr, "deno run main.ts");
|
||||
assert_contains!(stderr, "deno test");
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
|
@ -108,3 +108,52 @@ fn init_subcommand_with_dir_arg() {
|
|||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
assert_contains!(stdout, "1 passed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn init_subcommand_with_quiet_arg() {
|
||||
let temp_dir = TempDir::new();
|
||||
let cwd = temp_dir.path();
|
||||
let deno_dir = util::new_deno_dir();
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(cwd)
|
||||
.arg("init")
|
||||
.arg("--quiet")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
assert_eq!(stdout, "");
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(cwd)
|
||||
.env("NO_COLOR", "1")
|
||||
.arg("run")
|
||||
.arg("main.ts")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
assert_eq!(output.stdout, b"Add 2 + 3 = 5\n");
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(cwd)
|
||||
.env("NO_COLOR", "1")
|
||||
.arg("test")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
assert_contains!(stdout, "1 passed");
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use crate::args::InitFlags;
|
|||
use crate::deno_std;
|
||||
use deno_core::anyhow::Context;
|
||||
use deno_core::error::AnyError;
|
||||
use log::info;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
|
@ -39,12 +40,12 @@ pub async fn init_project(init_flags: InitFlags) -> Result<(), AnyError> {
|
|||
.replace("{CURRENT_STD_URL}", deno_std::CURRENT_STD_URL.as_str());
|
||||
create_file(&dir, "main_test.ts", &main_test_ts)?;
|
||||
|
||||
println!("✅ Project initialized");
|
||||
println!("Run these commands to get started");
|
||||
info!("✅ Project initialized");
|
||||
info!("Run these commands to get started");
|
||||
if let Some(dir) = init_flags.dir {
|
||||
println!(" cd {}", dir);
|
||||
info!(" cd {}", dir);
|
||||
}
|
||||
println!(" deno run main.ts");
|
||||
println!(" deno test");
|
||||
info!(" deno run main.ts");
|
||||
info!(" deno test");
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue