diff options
| author | Roj <ez@roj.im> | 2022-07-18 22:12:19 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-18 15:12:19 -0400 |
| commit | 70d1ecaeaa7843b37e8ea5161b24988813b2f543 (patch) | |
| tree | 011330b532ccd44320bf90c55c95b088467255bd /cli/args | |
| parent | 1f04cea160071a296fc97a6bd50a2690521d70f6 (diff) | |
feat(cli): support configuring the test tool in the config file (#15079)
Diffstat (limited to 'cli/args')
| -rw-r--r-- | cli/args/config_file.rs | 33 | ||||
| -rw-r--r-- | cli/args/flags.rs | 25 | ||||
| -rw-r--r-- | cli/args/mod.rs | 9 |
3 files changed, 54 insertions, 13 deletions
diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs index a0a5837fb..48f77d009 100644 --- a/cli/args/config_file.rs +++ b/cli/args/config_file.rs @@ -397,6 +397,28 @@ pub struct FmtConfig { pub files: FilesConfig, } +#[derive(Clone, Debug, Default, Deserialize)] +#[serde(default, deny_unknown_fields)] +struct SerializedTestConfig { + pub files: SerializedFilesConfig, +} + +impl SerializedTestConfig { + pub fn into_resolved( + self, + config_file_specifier: &ModuleSpecifier, + ) -> Result<TestConfig, AnyError> { + Ok(TestConfig { + files: self.files.into_resolved(config_file_specifier)?, + }) + } +} + +#[derive(Clone, Debug, Default)] +pub struct TestConfig { + pub files: FilesConfig, +} + #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ConfigFileJson { @@ -405,6 +427,7 @@ pub struct ConfigFileJson { pub lint: Option<Value>, pub fmt: Option<Value>, pub tasks: Option<Value>, + pub test: Option<Value>, } #[derive(Clone, Debug)] @@ -583,6 +606,16 @@ impl ConfigFile { } } + pub fn to_test_config(&self) -> Result<Option<TestConfig>, AnyError> { + if let Some(config) = self.json.test.clone() { + let lint_config: SerializedTestConfig = serde_json::from_value(config) + .context("Failed to parse \"test\" configuration")?; + Ok(Some(lint_config.into_resolved(&self.specifier)?)) + } else { + Ok(None) + } + } + /// Return any tasks that are defined in the configuration file as a sequence /// of JSON objects providing the name of the task and the arguments of the /// task in a detail field. diff --git a/cli/args/flags.rs b/cli/args/flags.rs index c6fbb320b..9bab9db3b 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -175,7 +175,7 @@ pub struct TestFlags { pub no_run: bool, pub fail_fast: Option<NonZeroUsize>, pub allow_none: bool, - pub include: Option<Vec<String>>, + pub include: Vec<String>, pub filter: Option<String>, pub shuffle: Option<u64>, pub concurrent_jobs: NonZeroUsize, @@ -2682,15 +2682,14 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) { NonZeroUsize::new(1).unwrap() }; - let include = if matches.is_present("files") { - let files: Vec<String> = matches + let include: Vec<String> = if matches.is_present("files") { + matches .values_of("files") .unwrap() .map(String::from) - .collect(); - Some(files) + .collect::<Vec<_>>() } else { - None + Vec::new() }; flags.coverage_dir = matches.value_of("coverage").map(String::from); @@ -4995,7 +4994,7 @@ mod tests { fail_fast: None, filter: Some("- foo".to_string()), allow_none: true, - include: Some(svec!["dir1/", "dir2/"]), + include: svec!["dir1/", "dir2/"], ignore: vec![], shuffle: None, concurrent_jobs: NonZeroUsize::new(1).unwrap(), @@ -5067,7 +5066,7 @@ mod tests { filter: None, allow_none: false, shuffle: None, - include: None, + include: vec![], ignore: vec![], concurrent_jobs: NonZeroUsize::new(4).unwrap(), trace_ops: false, @@ -5095,7 +5094,7 @@ mod tests { filter: None, allow_none: false, shuffle: None, - include: None, + include: vec![], ignore: vec![], concurrent_jobs: NonZeroUsize::new(1).unwrap(), trace_ops: false, @@ -5127,7 +5126,7 @@ mod tests { filter: None, allow_none: false, shuffle: None, - include: None, + include: vec![], ignore: vec![], concurrent_jobs: NonZeroUsize::new(1).unwrap(), trace_ops: false, @@ -5153,7 +5152,7 @@ mod tests { filter: None, allow_none: false, shuffle: Some(1), - include: None, + include: vec![], ignore: vec![], concurrent_jobs: NonZeroUsize::new(1).unwrap(), trace_ops: false, @@ -5179,7 +5178,7 @@ mod tests { filter: None, allow_none: false, shuffle: None, - include: None, + include: vec![], ignore: vec![], concurrent_jobs: NonZeroUsize::new(1).unwrap(), trace_ops: false, @@ -5206,7 +5205,7 @@ mod tests { filter: None, allow_none: false, shuffle: None, - include: None, + include: vec![], ignore: vec![], concurrent_jobs: NonZeroUsize::new(1).unwrap(), trace_ops: false, diff --git a/cli/args/mod.rs b/cli/args/mod.rs index accdeae7f..badfdc39d 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -14,6 +14,7 @@ pub use config_file::LintConfig; pub use config_file::LintRulesConfig; pub use config_file::MaybeImportsResult; pub use config_file::ProseWrap; +pub use config_file::TestConfig; pub use config_file::TsConfig; pub use flags::*; @@ -244,6 +245,14 @@ impl CliOptions { } } + pub fn to_test_config(&self) -> Result<Option<TestConfig>, AnyError> { + if let Some(config_file) = &self.maybe_config_file { + config_file.to_test_config() + } else { + Ok(None) + } + } + pub fn to_fmt_config(&self) -> Result<Option<FmtConfig>, AnyError> { if let Some(config) = &self.maybe_config_file { config.to_fmt_config() |
