Skip to content

Commit 5a709ad

Browse files
committed
test(language_server): add test for init_nested_configs (#10728)
Added tests for the bug in #10698
1 parent d5f66fb commit 5a709ad

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

crates/oxc_language_server/src/linter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ pub mod isolated_lint_handler;
44
pub mod server_linter;
55

66
#[cfg(test)]
7-
mod tester;
7+
pub mod tester;

crates/oxc_language_server/src/worker.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ fn range_overlaps(a: Range, b: Range) -> bool {
459459

460460
#[cfg(test)]
461461
mod tests {
462+
use crate::linter::tester::get_file_uri;
463+
462464
use super::*;
463465

464466
#[test]
@@ -487,4 +489,34 @@ mod tests {
487489
.is_responsible_for_uri(&Uri::from_str("file:///path/to/other/file.js").unwrap())
488490
);
489491
}
492+
493+
#[test]
494+
fn test_init_nested_configs_with_disabled_nested_configs() {
495+
let mut flags = FxHashMap::default();
496+
flags.insert("disable_nested_configs".to_string(), "true".to_string());
497+
498+
let configs = WorkspaceWorker::init_nested_configs(
499+
&Uri::from_str("file:///root/").unwrap(),
500+
&Options { flags, ..Options::default() },
501+
);
502+
503+
assert!(configs.is_empty());
504+
}
505+
506+
#[test]
507+
fn test_init_nested_configs() {
508+
let configs = WorkspaceWorker::init_nested_configs(
509+
&get_file_uri("fixtures/linter/init_nested_configs"),
510+
&Options::default(),
511+
);
512+
let configs = configs.pin();
513+
let mut configs_dirs = configs.keys().collect::<Vec<&PathBuf>>();
514+
// sorting the key because for consistent tests results
515+
configs_dirs.sort();
516+
517+
assert!(configs_dirs.len() == 3);
518+
assert!(configs_dirs[2].ends_with("deep2"));
519+
assert!(configs_dirs[1].ends_with("deep1"));
520+
assert!(configs_dirs[0].ends_with("init_nested_configs"));
521+
}
490522
}

0 commit comments

Comments
 (0)