summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorRoj <ez@roj.im>2022-07-18 22:12:19 +0300
committerGitHub <noreply@github.com>2022-07-18 15:12:19 -0400
commit70d1ecaeaa7843b37e8ea5161b24988813b2f543 (patch)
tree011330b532ccd44320bf90c55c95b088467255bd /cli/tools
parent1f04cea160071a296fc97a6bd50a2690521d70f6 (diff)
feat(cli): support configuring the test tool in the config file (#15079)
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/lint.rs2
-rw-r--r--cli/tools/test.rs41
2 files changed, 38 insertions, 5 deletions
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs
index 1c79ff8f6..cfc663387 100644
--- a/cli/tools/lint.rs
+++ b/cli/tools/lint.rs
@@ -70,7 +70,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
} = lint_flags;
// First, prepare final configuration.
// Collect included and ignored files. CLI flags take precendence
- // over config file, ie. if there's `files.ignore` in config file
+ // over config file, i.e. if there's `files.ignore` in config file
// and `--ignore` CLI flag, only the flag value is taken into account.
let mut include_files = args.clone();
let mut exclude_files = ignore.clone();
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index f3d4d6f6c..cbb5d0b53 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -15,6 +15,7 @@ use crate::fmt_errors::format_js_error;
use crate::fs_util::collect_specifiers;
use crate::fs_util::is_supported_test_ext;
use crate::fs_util::is_supported_test_path;
+use crate::fs_util::specifier_to_file_path;
use crate::graph_util::contains_specifier;
use crate::graph_util::graph_valid;
use crate::located_script_name;
@@ -1363,8 +1364,40 @@ async fn fetch_specifiers_with_test_mode(
ignore: Vec<PathBuf>,
include_inline: bool,
) -> Result<Vec<(ModuleSpecifier, TestMode)>, AnyError> {
- let mut specifiers_with_mode =
- collect_specifiers_with_test_mode(include, ignore, include_inline)?;
+ let maybe_test_config = ps.options.to_test_config()?;
+
+ let mut include_files = include.clone();
+ let mut exclude_files = ignore.clone();
+
+ if let Some(test_config) = maybe_test_config.as_ref() {
+ if include_files.is_empty() {
+ include_files = test_config
+ .files
+ .include
+ .iter()
+ .map(|s| s.to_string())
+ .collect::<Vec<_>>();
+ }
+
+ if exclude_files.is_empty() {
+ exclude_files = test_config
+ .files
+ .exclude
+ .iter()
+ .filter_map(|s| specifier_to_file_path(s).ok())
+ .collect::<Vec<_>>();
+ }
+ }
+
+ if include_files.is_empty() {
+ include_files.push(".".to_string());
+ }
+
+ let mut specifiers_with_mode = collect_specifiers_with_test_mode(
+ include_files,
+ exclude_files,
+ include_inline,
+ )?;
for (specifier, mode) in &mut specifiers_with_mode {
let file = ps
.file_fetcher
@@ -1390,7 +1423,7 @@ pub async fn run_tests(
Permissions::from_options(&ps.options.permissions_options());
let specifiers_with_mode = fetch_specifiers_with_test_mode(
&ps,
- test_flags.include.unwrap_or_else(|| vec![".".to_string()]),
+ test_flags.include,
test_flags.ignore.clone(),
test_flags.doc,
)
@@ -1434,7 +1467,7 @@ pub async fn run_tests_with_watch(
let permissions =
Permissions::from_options(&ps.options.permissions_options());
- let include = test_flags.include.unwrap_or_else(|| vec![".".to_string()]);
+ let include = test_flags.include;
let ignore = test_flags.ignore.clone();
let paths_to_watch: Vec<_> = include.iter().map(PathBuf::from).collect();
let no_check = ps.options.type_check_mode() == TypeCheckMode::None;