mirror of
https://github.com/denoland/deno.git
synced 2024-12-01 16:51:13 -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()
|
..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
|
let output = deno_cmd
|
||||||
.current_dir(cwd)
|
.current_dir(cwd)
|
||||||
.arg("init")
|
.arg("init")
|
||||||
.stdout(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.wait_with_output()
|
.wait_with_output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(output.status.success());
|
assert!(output.status.success());
|
||||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||||
assert_contains!(stdout, "Project initialized");
|
assert_contains!(stderr, "Project initialized");
|
||||||
assert!(!stdout.contains("cd"));
|
assert!(!stderr.contains("cd"));
|
||||||
assert_contains!(stdout, "deno run main.ts");
|
assert_contains!(stderr, "deno run main.ts");
|
||||||
assert_contains!(stdout, "deno test");
|
assert_contains!(stderr, "deno test");
|
||||||
|
|
||||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||||
let output = deno_cmd
|
let output = deno_cmd
|
||||||
|
@ -67,17 +67,17 @@ fn init_subcommand_with_dir_arg() {
|
||||||
.current_dir(cwd)
|
.current_dir(cwd)
|
||||||
.arg("init")
|
.arg("init")
|
||||||
.arg("my_dir")
|
.arg("my_dir")
|
||||||
.stdout(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.wait_with_output()
|
.wait_with_output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(output.status.success());
|
assert!(output.status.success());
|
||||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||||
assert_contains!(stdout, "Project initialized");
|
assert_contains!(stderr, "Project initialized");
|
||||||
assert_contains!(stdout, "cd my_dir");
|
assert_contains!(stderr, "cd my_dir");
|
||||||
assert_contains!(stdout, "deno run main.ts");
|
assert_contains!(stderr, "deno run main.ts");
|
||||||
assert_contains!(stdout, "deno test");
|
assert_contains!(stderr, "deno test");
|
||||||
|
|
||||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||||
let output = deno_cmd
|
let output = deno_cmd
|
||||||
|
@ -108,3 +108,52 @@ fn init_subcommand_with_dir_arg() {
|
||||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||||
assert_contains!(stdout, "1 passed");
|
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 crate::deno_std;
|
||||||
use deno_core::anyhow::Context;
|
use deno_core::anyhow::Context;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
|
use log::info;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
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());
|
.replace("{CURRENT_STD_URL}", deno_std::CURRENT_STD_URL.as_str());
|
||||||
create_file(&dir, "main_test.ts", &main_test_ts)?;
|
create_file(&dir, "main_test.ts", &main_test_ts)?;
|
||||||
|
|
||||||
println!("✅ Project initialized");
|
info!("✅ Project initialized");
|
||||||
println!("Run these commands to get started");
|
info!("Run these commands to get started");
|
||||||
if let Some(dir) = init_flags.dir {
|
if let Some(dir) = init_flags.dir {
|
||||||
println!(" cd {}", dir);
|
info!(" cd {}", dir);
|
||||||
}
|
}
|
||||||
println!(" deno run main.ts");
|
info!(" deno run main.ts");
|
||||||
println!(" deno test");
|
info!(" deno test");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue