mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
Adjust the tests
This commit is contained in:
parent
8be07eddcc
commit
ce40d5e0c5
1 changed files with 71 additions and 12 deletions
|
@ -529,9 +529,9 @@ mod tests {
|
||||||
Path::new("/root/work/project/node_modules/expect/build/print.js")
|
Path::new("/root/work/project/node_modules/expect/build/print.js")
|
||||||
)
|
)
|
||||||
.await,
|
.await,
|
||||||
Ok(ControlFlow::Continue(None))
|
Ok(ControlFlow::Break(()))
|
||||||
),
|
),
|
||||||
"Even though it has package.json with prettier in it and no prettier on node_modules along the path, nothing should fail since declared inside node_modules"
|
"Should not format files inside node_modules/"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,8 +595,8 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
ControlFlow::Continue(Some(PathBuf::from("/root/web_blog"))),
|
ControlFlow::Break(()),
|
||||||
"Should find a preinstalled prettier in the project root even for node_modules files"
|
"Should not allow formatting node_modules/ contents"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,6 +608,18 @@ mod tests {
|
||||||
json!({
|
json!({
|
||||||
"work": {
|
"work": {
|
||||||
"web_blog": {
|
"web_blog": {
|
||||||
|
"node_modules": {
|
||||||
|
"expect": {
|
||||||
|
"build": {
|
||||||
|
"print.js": "// print.js file contents",
|
||||||
|
},
|
||||||
|
"package.json": r#"{
|
||||||
|
"devDependencies": {
|
||||||
|
"prettier": "2.5.1"
|
||||||
|
}
|
||||||
|
}"#,
|
||||||
|
},
|
||||||
|
},
|
||||||
"pages": {
|
"pages": {
|
||||||
"[slug].tsx": "// [slug].tsx file contents",
|
"[slug].tsx": "// [slug].tsx file contents",
|
||||||
},
|
},
|
||||||
|
@ -628,33 +640,55 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let path = "/root/work/web_blog/node_modules/pages/[slug].tsx";
|
|
||||||
match Prettier::locate_prettier_installation(
|
match Prettier::locate_prettier_installation(
|
||||||
fs.as_ref(),
|
fs.as_ref(),
|
||||||
&HashSet::default(),
|
&HashSet::default(),
|
||||||
Path::new(path)
|
Path::new("/root/work/web_blog/pages/[slug].tsx")
|
||||||
)
|
)
|
||||||
.await {
|
.await {
|
||||||
Ok(path) => panic!("Expected to fail for prettier in package.json but not in node_modules found, but got path {path:?}"),
|
Ok(path) => panic!("Expected to fail for prettier in package.json but not in node_modules found, but got path {path:?}"),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let message = e.to_string();
|
let message = e.to_string();
|
||||||
assert!(message.contains(path), "Error message should mention which start file was used for location");
|
assert!(message.contains("/root/work/web_blog"), "Error message should mention which project had prettier defined");
|
||||||
assert!(message.contains("/root/work/web_blog"), "Error message should mention potential candidates without prettier node_modules contents");
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Prettier::locate_prettier_installation(
|
Prettier::locate_prettier_installation(
|
||||||
fs.as_ref(),
|
fs.as_ref(),
|
||||||
&HashSet::from_iter(
|
&HashSet::from_iter(
|
||||||
[PathBuf::from("/root"), PathBuf::from("/root/work")].into_iter()
|
[PathBuf::from("/root"), PathBuf::from("/root/work")].into_iter()
|
||||||
),
|
),
|
||||||
Path::new("/root/work/web_blog/node_modules/pages/[slug].tsx")
|
Path::new("/root/work/web_blog/pages/[slug].tsx")
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
ControlFlow::Continue(Some(PathBuf::from("/root/work"))),
|
ControlFlow::Continue(Some(PathBuf::from("/root/work"))),
|
||||||
"Should return first cached value found without path checks"
|
"Should return closest cached value found without path checks"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Prettier::locate_prettier_installation(
|
||||||
|
fs.as_ref(),
|
||||||
|
&HashSet::default(),
|
||||||
|
Path::new("/root/work/web_blog/node_modules/expect/build/print.js")
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
ControlFlow::Break(()),
|
||||||
|
"Should not allow formatting files inside node_modules/"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Prettier::locate_prettier_installation(
|
||||||
|
fs.as_ref(),
|
||||||
|
&HashSet::from_iter(
|
||||||
|
[PathBuf::from("/root"), PathBuf::from("/root/work")].into_iter()
|
||||||
|
),
|
||||||
|
Path::new("/root/work/web_blog/node_modules/expect/build/print.js")
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
ControlFlow::Break(()),
|
||||||
|
"Should ignore cache lookup for files inside node_modules/"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,7 +712,9 @@ mod tests {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"node_modules": {},
|
"node_modules": {
|
||||||
|
"test.js": "// test.js contents",
|
||||||
|
},
|
||||||
"package.json": r#"{
|
"package.json": r#"{
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "^3.0.3"
|
"prettier": "^3.0.3"
|
||||||
|
@ -710,6 +746,29 @@ mod tests {
|
||||||
ControlFlow::Continue(Some(PathBuf::from("/root/work/full-stack-foundations"))),
|
ControlFlow::Continue(Some(PathBuf::from("/root/work/full-stack-foundations"))),
|
||||||
"Should ascend to the multi-workspace root and find the prettier there",
|
"Should ascend to the multi-workspace root and find the prettier there",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Prettier::locate_prettier_installation(
|
||||||
|
fs.as_ref(),
|
||||||
|
&HashSet::default(),
|
||||||
|
Path::new("/root/work/full-stack-foundations/node_modules/prettier/index.js")
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
ControlFlow::Break(()),
|
||||||
|
"Should not allow formatting files inside root node_modules/"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Prettier::locate_prettier_installation(
|
||||||
|
fs.as_ref(),
|
||||||
|
&HashSet::default(),
|
||||||
|
Path::new("/root/work/full-stack-foundations/exercises/03.loading/01.problem.loader/node_modules/test.js")
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
ControlFlow::Break(()),
|
||||||
|
"Should not allow formatting files inside submodule's node_modules/"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
|
Loading…
Reference in a new issue