diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-08-24 23:23:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-24 17:23:29 +0200 |
commit | a7240c5091e757da1285c2f655796d4e62e54bb3 (patch) | |
tree | 403e6c36dcf8816f207b51f51a80667f1b2e3acb /cli | |
parent | 7ae30bcc89829a8e4d101deeb3a977f488ef7a12 (diff) |
feat(cli): add --ignore flag to test command (#11712)
Diffstat (limited to 'cli')
-rw-r--r-- | cli/flags.rs | 21 | ||||
-rw-r--r-- | cli/fs_util.rs | 5 | ||||
-rw-r--r-- | cli/main.rs | 10 | ||||
-rw-r--r-- | cli/tests/integration/test_tests.rs | 6 | ||||
-rw-r--r-- | cli/tests/testdata/test/collect.out | 5 | ||||
-rw-r--r-- | cli/tests/testdata/test/collect/ignore/test.ts | 1 | ||||
-rw-r--r-- | cli/tests/testdata/test/collect/test.ts | 0 |
7 files changed, 46 insertions, 2 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index 53177465d..63182753a 100644 --- a/cli/flags.rs +++ b/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>, @@ -1025,6 +1026,14 @@ 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") .help("Cache test modules, but don't run tests") @@ -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, diff --git a/cli/fs_util.rs b/cli/fs_util.rs index cab2d5dad..446c16f27 100644 --- a/cli/fs_util.rs +++ b/cli/fs_util.rs @@ -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() diff --git a/cli/main.rs b/cli/main.rs index ad1e15643..9749496c6 100644 --- a/cli/main.rs +++ b/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, diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs index 355a3c261..971e756a9 100644 --- a/cli/tests/integration/test_tests.rs +++ b/cli/tests/integration/test_tests.rs @@ -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, diff --git a/cli/tests/testdata/test/collect.out b/cli/tests/testdata/test/collect.out new file mode 100644 index 000000000..3bdada829 --- /dev/null +++ b/cli/tests/testdata/test/collect.out @@ -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]) + diff --git a/cli/tests/testdata/test/collect/ignore/test.ts b/cli/tests/testdata/test/collect/ignore/test.ts new file mode 100644 index 000000000..16fb63ba7 --- /dev/null +++ b/cli/tests/testdata/test/collect/ignore/test.ts @@ -0,0 +1 @@ +throw new Error("this module should be ignored"); diff --git a/cli/tests/testdata/test/collect/test.ts b/cli/tests/testdata/test/collect/test.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/tests/testdata/test/collect/test.ts |