chore(tests): test_util - Add PathRef (#19450)

This adds a new `PathRef` struct to test_util for making it easier to
work with paths in test code. I'm going to expand on this more in the
future.
This commit is contained in:
David Sherret 2023-06-10 11:09:45 -04:00 committed by GitHub
parent f3326eebd6
commit 7f15126f23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 778 additions and 719 deletions

View file

@ -1258,14 +1258,14 @@ mod tests {
#[test]
fn read_config_file_absolute() {
let path = test_util::testdata_path().join("module_graph/tsconfig.json");
let config_file = ConfigFile::read(&path).unwrap();
let config_file = ConfigFile::read(path.as_path()).unwrap();
assert!(config_file.json.compiler_options.is_some());
}
#[test]
fn include_config_path_on_error() {
let path = test_util::testdata_path().join("404.json");
let error = ConfigFile::read(&path).err().unwrap();
let error = ConfigFile::read(path.as_path()).err().unwrap();
assert!(error.to_string().contains("404.json"));
}
@ -1623,13 +1623,13 @@ mod tests {
fn discover_from_success() {
// testdata/fmt/deno.jsonc exists
let testdata = test_util::testdata_path();
let c_md = testdata.join("fmt/with_config/subdir/c.md");
let c_md = testdata.join("fmt/with_config/subdir/c.md").to_path_buf();
let mut checked = HashSet::new();
let config_file = ConfigFile::discover_from(&c_md, &mut checked)
.unwrap()
.unwrap();
assert!(checked.contains(c_md.parent().unwrap()));
assert!(!checked.contains(&testdata));
assert!(!checked.contains(testdata.as_path()));
let fmt_config = config_file.to_fmt_config().unwrap().unwrap();
let expected_exclude = ModuleSpecifier::from_file_path(
testdata.join("fmt/with_config/subdir/b.ts"),
@ -1640,12 +1640,12 @@ mod tests {
assert_eq!(fmt_config.files.exclude, vec![expected_exclude]);
// Now add all ancestors of testdata to checked.
for a in testdata.ancestors() {
for a in testdata.as_path().ancestors() {
checked.insert(a.to_path_buf());
}
// If we call discover_from again starting at testdata, we ought to get None.
assert!(ConfigFile::discover_from(&testdata, &mut checked)
assert!(ConfigFile::discover_from(testdata.as_path(), &mut checked)
.unwrap()
.is_none());
}
@ -1655,7 +1655,7 @@ mod tests {
let testdata = test_util::testdata_path();
let d = testdata.join("malformed_config/");
let mut checked = HashSet::new();
let err = ConfigFile::discover_from(&d, &mut checked).unwrap_err();
let err = ConfigFile::discover_from(d.as_path(), &mut checked).unwrap_err();
assert!(err.to_string().contains("Unable to parse config file"));
}

View file

@ -1582,9 +1582,10 @@ mod test {
temp_dir.write("pages/[id].ts", "");
let temp_dir_path = temp_dir.path().as_path();
let error = resolve_files(
Some(FilesConfig {
include: vec![temp_dir.path().join("data/**********.ts")],
include: vec![temp_dir_path.join("data/**********.ts")],
exclude: vec![],
}),
None,
@ -1595,12 +1596,12 @@ mod test {
let resolved_files = resolve_files(
Some(FilesConfig {
include: vec![
temp_dir.path().join("data/test1.?s"),
temp_dir.path().join("nested/foo/*.ts"),
temp_dir.path().join("nested/fizz/*.ts"),
temp_dir.path().join("pages/[id].ts"),
temp_dir_path.join("data/test1.?s"),
temp_dir_path.join("nested/foo/*.ts"),
temp_dir_path.join("nested/fizz/*.ts"),
temp_dir_path.join("pages/[id].ts"),
],
exclude: vec![temp_dir.path().join("nested/**/*bazz.ts")],
exclude: vec![temp_dir_path.join("nested/**/*bazz.ts")],
}),
None,
)
@ -1609,24 +1610,24 @@ mod test {
assert_eq!(
resolved_files.include,
vec![
temp_dir.path().join("data/test1.js"),
temp_dir.path().join("data/test1.ts"),
temp_dir.path().join("nested/foo/bar.ts"),
temp_dir.path().join("nested/foo/bazz.ts"),
temp_dir.path().join("nested/foo/fizz.ts"),
temp_dir.path().join("nested/foo/foo.ts"),
temp_dir.path().join("nested/fizz/bar.ts"),
temp_dir.path().join("nested/fizz/bazz.ts"),
temp_dir.path().join("nested/fizz/fizz.ts"),
temp_dir.path().join("nested/fizz/foo.ts"),
temp_dir.path().join("pages/[id].ts"),
temp_dir_path.join("data/test1.js"),
temp_dir_path.join("data/test1.ts"),
temp_dir_path.join("nested/foo/bar.ts"),
temp_dir_path.join("nested/foo/bazz.ts"),
temp_dir_path.join("nested/foo/fizz.ts"),
temp_dir_path.join("nested/foo/foo.ts"),
temp_dir_path.join("nested/fizz/bar.ts"),
temp_dir_path.join("nested/fizz/bazz.ts"),
temp_dir_path.join("nested/fizz/fizz.ts"),
temp_dir_path.join("nested/fizz/foo.ts"),
temp_dir_path.join("pages/[id].ts"),
]
);
assert_eq!(
resolved_files.exclude,
vec![
temp_dir.path().join("nested/fizz/bazz.ts"),
temp_dir.path().join("nested/foo/bazz.ts"),
temp_dir_path.join("nested/fizz/bazz.ts"),
temp_dir_path.join("nested/foo/bazz.ts"),
]
)
}