mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
feat(cli): add --ignore flag to test command (#11712)
This commit is contained in:
parent
7ae30bcc89
commit
a7240c5091
7 changed files with 46 additions and 2 deletions
21
cli/flags.rs
21
cli/flags.rs
|
@ -99,6 +99,7 @@ pub enum DenoSubcommand {
|
|||
script: String,
|
||||
},
|
||||
Test {
|
||||
ignore: Vec<PathBuf>,
|
||||
doc: bool,
|
||||
no_run: bool,
|
||||
fail_fast: Option<NonZeroUsize>,
|
||||
|
@ -1024,6 +1025,14 @@ Deno allows specifying the filename '-' to read the file from stdin.
|
|||
fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
|
||||
runtime_args(SubCommand::with_name("test"), true, true)
|
||||
.setting(AppSettings::TrailingVarArg)
|
||||
.arg(
|
||||
Arg::with_name("ignore")
|
||||
.long("ignore")
|
||||
.takes_value(true)
|
||||
.use_delimiter(true)
|
||||
.require_equals(true)
|
||||
.help("Ignore files"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("no-run")
|
||||
.long("no-run")
|
||||
|
@ -1768,6 +1777,11 @@ fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|||
fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||
runtime_args_parse(flags, matches, true, true);
|
||||
|
||||
let ignore = match matches.values_of("ignore") {
|
||||
Some(f) => f.map(PathBuf::from).collect(),
|
||||
None => vec![],
|
||||
};
|
||||
|
||||
let no_run = matches.is_present("no-run");
|
||||
let doc = matches.is_present("doc");
|
||||
let allow_none = matches.is_present("allow-none");
|
||||
|
@ -1836,6 +1850,7 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|||
doc,
|
||||
fail_fast,
|
||||
include,
|
||||
ignore,
|
||||
filter,
|
||||
shuffle,
|
||||
allow_none,
|
||||
|
@ -3564,6 +3579,7 @@ mod tests {
|
|||
filter: Some("- foo".to_string()),
|
||||
allow_none: true,
|
||||
include: Some(svec!["dir1/", "dir2/"]),
|
||||
ignore: vec![],
|
||||
shuffle: None,
|
||||
concurrent_jobs: NonZeroUsize::new(1).unwrap(),
|
||||
},
|
||||
|
@ -3632,6 +3648,7 @@ mod tests {
|
|||
allow_none: false,
|
||||
shuffle: None,
|
||||
include: None,
|
||||
ignore: vec![],
|
||||
concurrent_jobs: NonZeroUsize::new(4).unwrap(),
|
||||
},
|
||||
..Flags::default()
|
||||
|
@ -3656,6 +3673,7 @@ mod tests {
|
|||
allow_none: false,
|
||||
shuffle: None,
|
||||
include: None,
|
||||
ignore: vec![],
|
||||
concurrent_jobs: NonZeroUsize::new(1).unwrap(),
|
||||
},
|
||||
..Flags::default()
|
||||
|
@ -3684,6 +3702,7 @@ mod tests {
|
|||
allow_none: false,
|
||||
shuffle: None,
|
||||
include: None,
|
||||
ignore: vec![],
|
||||
concurrent_jobs: NonZeroUsize::new(1).unwrap(),
|
||||
},
|
||||
enable_testing_features: true,
|
||||
|
@ -3706,6 +3725,7 @@ mod tests {
|
|||
allow_none: false,
|
||||
shuffle: Some(1),
|
||||
include: None,
|
||||
ignore: vec![],
|
||||
concurrent_jobs: NonZeroUsize::new(1).unwrap(),
|
||||
},
|
||||
watch: false,
|
||||
|
@ -3728,6 +3748,7 @@ mod tests {
|
|||
allow_none: false,
|
||||
shuffle: None,
|
||||
include: None,
|
||||
ignore: vec![],
|
||||
concurrent_jobs: NonZeroUsize::new(1).unwrap(),
|
||||
},
|
||||
watch: true,
|
||||
|
|
|
@ -202,6 +202,7 @@ where
|
|||
/// Specifiers that start with http and https are left intact.
|
||||
pub fn collect_specifiers<P>(
|
||||
include: Vec<String>,
|
||||
ignore: &[PathBuf],
|
||||
predicate: P,
|
||||
) -> Result<Vec<ModuleSpecifier>, AnyError>
|
||||
where
|
||||
|
@ -222,7 +223,7 @@ where
|
|||
|
||||
let p = normalize_path(&root_path.join(path));
|
||||
if p.is_dir() {
|
||||
let test_files = collect_files(&[p], &[], &predicate).unwrap();
|
||||
let test_files = collect_files(&[p], ignore, &predicate).unwrap();
|
||||
let mut test_files_as_urls = test_files
|
||||
.iter()
|
||||
.map(|f| ModuleSpecifier::from_file_path(f).unwrap())
|
||||
|
@ -491,6 +492,7 @@ mod tests {
|
|||
root_dir_path.to_str().unwrap().to_string(),
|
||||
"https://localhost:8080".to_string(),
|
||||
],
|
||||
&[ignore_dir_path],
|
||||
|path| {
|
||||
// exclude dotfiles
|
||||
path
|
||||
|
@ -515,7 +517,6 @@ mod tests {
|
|||
&format!("{}/child/e.mjs", root_dir_url),
|
||||
&format!("{}/child/f.mjsx", root_dir_url),
|
||||
&format!("{}/d.jsx", root_dir_url),
|
||||
&format!("{}/ignore/g.d.ts", root_dir_url),
|
||||
"https://localhost:8080",
|
||||
]
|
||||
.iter()
|
||||
|
|
10
cli/main.rs
10
cli/main.rs
|
@ -1002,6 +1002,7 @@ async fn coverage_command(
|
|||
async fn test_command(
|
||||
flags: Flags,
|
||||
include: Option<Vec<String>>,
|
||||
ignore: Vec<PathBuf>,
|
||||
no_run: bool,
|
||||
doc: bool,
|
||||
fail_fast: Option<NonZeroUsize>,
|
||||
|
@ -1045,11 +1046,13 @@ async fn test_command(
|
|||
let test_modules_result = if doc {
|
||||
fs_util::collect_specifiers(
|
||||
include.clone(),
|
||||
&ignore,
|
||||
fs_util::is_supported_test_ext,
|
||||
)
|
||||
} else {
|
||||
fs_util::collect_specifiers(
|
||||
include.clone(),
|
||||
&ignore,
|
||||
fs_util::is_supported_test_path,
|
||||
)
|
||||
};
|
||||
|
@ -1176,6 +1179,7 @@ async fn test_command(
|
|||
let operation = |modules_to_reload: Vec<ModuleSpecifier>| {
|
||||
let filter = filter.clone();
|
||||
let include = include.clone();
|
||||
let ignore = ignore.clone();
|
||||
let lib = lib.clone();
|
||||
let permissions = permissions.clone();
|
||||
let program_state = program_state.clone();
|
||||
|
@ -1184,6 +1188,7 @@ async fn test_command(
|
|||
let doc_modules = if doc {
|
||||
fs_util::collect_specifiers(
|
||||
include.clone(),
|
||||
&ignore,
|
||||
fs_util::is_supported_test_ext,
|
||||
)?
|
||||
} else {
|
||||
|
@ -1198,6 +1203,7 @@ async fn test_command(
|
|||
|
||||
let test_modules = fs_util::collect_specifiers(
|
||||
include.clone(),
|
||||
&ignore,
|
||||
fs_util::is_supported_test_path,
|
||||
)?;
|
||||
|
||||
|
@ -1231,6 +1237,7 @@ async fn test_command(
|
|||
let doc_modules = if doc {
|
||||
fs_util::collect_specifiers(
|
||||
include.clone(),
|
||||
&ignore,
|
||||
fs_util::is_supported_test_ext,
|
||||
)?
|
||||
} else {
|
||||
|
@ -1239,6 +1246,7 @@ async fn test_command(
|
|||
|
||||
let test_modules = fs_util::collect_specifiers(
|
||||
include.clone(),
|
||||
&ignore,
|
||||
fs_util::is_supported_test_path,
|
||||
)?;
|
||||
|
||||
|
@ -1352,6 +1360,7 @@ fn get_subcommand(
|
|||
no_run,
|
||||
doc,
|
||||
fail_fast,
|
||||
ignore,
|
||||
include,
|
||||
allow_none,
|
||||
filter,
|
||||
|
@ -1360,6 +1369,7 @@ fn get_subcommand(
|
|||
} => test_command(
|
||||
flags,
|
||||
include,
|
||||
ignore,
|
||||
no_run,
|
||||
doc,
|
||||
fail_fast,
|
||||
|
|
|
@ -49,6 +49,12 @@ itest!(fail {
|
|||
output: "test/fail.out",
|
||||
});
|
||||
|
||||
itest!(collect {
|
||||
args: "test --ignore=test/collect/ignore test/collect",
|
||||
exit_code: 0,
|
||||
output: "test/collect.out",
|
||||
});
|
||||
|
||||
itest!(load_unload {
|
||||
args: "test test/load_unload.ts",
|
||||
exit_code: 0,
|
||||
|
|
5
cli/tests/testdata/test/collect.out
vendored
Normal file
5
cli/tests/testdata/test/collect.out
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
Check [WILDCARD]/test/collect/test.ts
|
||||
running 0 tests from [WILDCARD]/test/collect/test.ts
|
||||
|
||||
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD])
|
||||
|
1
cli/tests/testdata/test/collect/ignore/test.ts
vendored
Normal file
1
cli/tests/testdata/test/collect/ignore/test.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
throw new Error("this module should be ignored");
|
0
cli/tests/testdata/test/collect/test.ts
vendored
Normal file
0
cli/tests/testdata/test/collect/test.ts
vendored
Normal file
Loading…
Reference in a new issue