1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

feat(cli): add --ignore flag to test command (#11712)

This commit is contained in:
Casper Beyer 2021-08-24 23:23:29 +08:00 committed by GitHub
parent 7ae30bcc89
commit a7240c5091
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 2 deletions

View file

@ -99,6 +99,7 @@ pub enum DenoSubcommand {
script: String, script: String,
}, },
Test { Test {
ignore: Vec<PathBuf>,
doc: bool, doc: bool,
no_run: bool, no_run: bool,
fail_fast: Option<NonZeroUsize>, 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> { fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
runtime_args(SubCommand::with_name("test"), true, true) runtime_args(SubCommand::with_name("test"), true, true)
.setting(AppSettings::TrailingVarArg) .setting(AppSettings::TrailingVarArg)
.arg(
Arg::with_name("ignore")
.long("ignore")
.takes_value(true)
.use_delimiter(true)
.require_equals(true)
.help("Ignore files"),
)
.arg( .arg(
Arg::with_name("no-run") Arg::with_name("no-run")
.long("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) { fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
runtime_args_parse(flags, matches, true, true); 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 no_run = matches.is_present("no-run");
let doc = matches.is_present("doc"); let doc = matches.is_present("doc");
let allow_none = matches.is_present("allow-none"); let allow_none = matches.is_present("allow-none");
@ -1836,6 +1850,7 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
doc, doc,
fail_fast, fail_fast,
include, include,
ignore,
filter, filter,
shuffle, shuffle,
allow_none, allow_none,
@ -3564,6 +3579,7 @@ mod tests {
filter: Some("- foo".to_string()), filter: Some("- foo".to_string()),
allow_none: true, allow_none: true,
include: Some(svec!["dir1/", "dir2/"]), include: Some(svec!["dir1/", "dir2/"]),
ignore: vec![],
shuffle: None, shuffle: None,
concurrent_jobs: NonZeroUsize::new(1).unwrap(), concurrent_jobs: NonZeroUsize::new(1).unwrap(),
}, },
@ -3632,6 +3648,7 @@ mod tests {
allow_none: false, allow_none: false,
shuffle: None, shuffle: None,
include: None, include: None,
ignore: vec![],
concurrent_jobs: NonZeroUsize::new(4).unwrap(), concurrent_jobs: NonZeroUsize::new(4).unwrap(),
}, },
..Flags::default() ..Flags::default()
@ -3656,6 +3673,7 @@ mod tests {
allow_none: false, allow_none: false,
shuffle: None, shuffle: None,
include: None, include: None,
ignore: vec![],
concurrent_jobs: NonZeroUsize::new(1).unwrap(), concurrent_jobs: NonZeroUsize::new(1).unwrap(),
}, },
..Flags::default() ..Flags::default()
@ -3684,6 +3702,7 @@ mod tests {
allow_none: false, allow_none: false,
shuffle: None, shuffle: None,
include: None, include: None,
ignore: vec![],
concurrent_jobs: NonZeroUsize::new(1).unwrap(), concurrent_jobs: NonZeroUsize::new(1).unwrap(),
}, },
enable_testing_features: true, enable_testing_features: true,
@ -3706,6 +3725,7 @@ mod tests {
allow_none: false, allow_none: false,
shuffle: Some(1), shuffle: Some(1),
include: None, include: None,
ignore: vec![],
concurrent_jobs: NonZeroUsize::new(1).unwrap(), concurrent_jobs: NonZeroUsize::new(1).unwrap(),
}, },
watch: false, watch: false,
@ -3728,6 +3748,7 @@ mod tests {
allow_none: false, allow_none: false,
shuffle: None, shuffle: None,
include: None, include: None,
ignore: vec![],
concurrent_jobs: NonZeroUsize::new(1).unwrap(), concurrent_jobs: NonZeroUsize::new(1).unwrap(),
}, },
watch: true, watch: true,

View file

@ -202,6 +202,7 @@ where
/// Specifiers that start with http and https are left intact. /// Specifiers that start with http and https are left intact.
pub fn collect_specifiers<P>( pub fn collect_specifiers<P>(
include: Vec<String>, include: Vec<String>,
ignore: &[PathBuf],
predicate: P, predicate: P,
) -> Result<Vec<ModuleSpecifier>, AnyError> ) -> Result<Vec<ModuleSpecifier>, AnyError>
where where
@ -222,7 +223,7 @@ where
let p = normalize_path(&root_path.join(path)); let p = normalize_path(&root_path.join(path));
if p.is_dir() { 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 let mut test_files_as_urls = test_files
.iter() .iter()
.map(|f| ModuleSpecifier::from_file_path(f).unwrap()) .map(|f| ModuleSpecifier::from_file_path(f).unwrap())
@ -491,6 +492,7 @@ mod tests {
root_dir_path.to_str().unwrap().to_string(), root_dir_path.to_str().unwrap().to_string(),
"https://localhost:8080".to_string(), "https://localhost:8080".to_string(),
], ],
&[ignore_dir_path],
|path| { |path| {
// exclude dotfiles // exclude dotfiles
path path
@ -515,7 +517,6 @@ mod tests {
&format!("{}/child/e.mjs", root_dir_url), &format!("{}/child/e.mjs", root_dir_url),
&format!("{}/child/f.mjsx", root_dir_url), &format!("{}/child/f.mjsx", root_dir_url),
&format!("{}/d.jsx", root_dir_url), &format!("{}/d.jsx", root_dir_url),
&format!("{}/ignore/g.d.ts", root_dir_url),
"https://localhost:8080", "https://localhost:8080",
] ]
.iter() .iter()

View file

@ -1002,6 +1002,7 @@ async fn coverage_command(
async fn test_command( async fn test_command(
flags: Flags, flags: Flags,
include: Option<Vec<String>>, include: Option<Vec<String>>,
ignore: Vec<PathBuf>,
no_run: bool, no_run: bool,
doc: bool, doc: bool,
fail_fast: Option<NonZeroUsize>, fail_fast: Option<NonZeroUsize>,
@ -1045,11 +1046,13 @@ async fn test_command(
let test_modules_result = if doc { let test_modules_result = if doc {
fs_util::collect_specifiers( fs_util::collect_specifiers(
include.clone(), include.clone(),
&ignore,
fs_util::is_supported_test_ext, fs_util::is_supported_test_ext,
) )
} else { } else {
fs_util::collect_specifiers( fs_util::collect_specifiers(
include.clone(), include.clone(),
&ignore,
fs_util::is_supported_test_path, fs_util::is_supported_test_path,
) )
}; };
@ -1176,6 +1179,7 @@ async fn test_command(
let operation = |modules_to_reload: Vec<ModuleSpecifier>| { let operation = |modules_to_reload: Vec<ModuleSpecifier>| {
let filter = filter.clone(); let filter = filter.clone();
let include = include.clone(); let include = include.clone();
let ignore = ignore.clone();
let lib = lib.clone(); let lib = lib.clone();
let permissions = permissions.clone(); let permissions = permissions.clone();
let program_state = program_state.clone(); let program_state = program_state.clone();
@ -1184,6 +1188,7 @@ async fn test_command(
let doc_modules = if doc { let doc_modules = if doc {
fs_util::collect_specifiers( fs_util::collect_specifiers(
include.clone(), include.clone(),
&ignore,
fs_util::is_supported_test_ext, fs_util::is_supported_test_ext,
)? )?
} else { } else {
@ -1198,6 +1203,7 @@ async fn test_command(
let test_modules = fs_util::collect_specifiers( let test_modules = fs_util::collect_specifiers(
include.clone(), include.clone(),
&ignore,
fs_util::is_supported_test_path, fs_util::is_supported_test_path,
)?; )?;
@ -1231,6 +1237,7 @@ async fn test_command(
let doc_modules = if doc { let doc_modules = if doc {
fs_util::collect_specifiers( fs_util::collect_specifiers(
include.clone(), include.clone(),
&ignore,
fs_util::is_supported_test_ext, fs_util::is_supported_test_ext,
)? )?
} else { } else {
@ -1239,6 +1246,7 @@ async fn test_command(
let test_modules = fs_util::collect_specifiers( let test_modules = fs_util::collect_specifiers(
include.clone(), include.clone(),
&ignore,
fs_util::is_supported_test_path, fs_util::is_supported_test_path,
)?; )?;
@ -1352,6 +1360,7 @@ fn get_subcommand(
no_run, no_run,
doc, doc,
fail_fast, fail_fast,
ignore,
include, include,
allow_none, allow_none,
filter, filter,
@ -1360,6 +1369,7 @@ fn get_subcommand(
} => test_command( } => test_command(
flags, flags,
include, include,
ignore,
no_run, no_run,
doc, doc,
fail_fast, fail_fast,

View file

@ -49,6 +49,12 @@ itest!(fail {
output: "test/fail.out", output: "test/fail.out",
}); });
itest!(collect {
args: "test --ignore=test/collect/ignore test/collect",
exit_code: 0,
output: "test/collect.out",
});
itest!(load_unload { itest!(load_unload {
args: "test test/load_unload.ts", args: "test test/load_unload.ts",
exit_code: 0, exit_code: 0,

5
cli/tests/testdata/test/collect.out vendored Normal file
View 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])

View file

@ -0,0 +1 @@
throw new Error("this module should be ignored");

View file