Skip to content

Commit ebc6c36

Browse files
authored
test: fix symlink test init on windows (#307)
* test: fix symlink test init on windows * test: skip two tests on Windows * test: fix relative symlink file tests * chore: reduce diff
1 parent e591956 commit ebc6c36

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/tests/symlink.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::{fs, io, path::Path};
22

3+
use normalize_path::NormalizePath;
4+
35
use crate::{ResolveOptions, Resolver};
46

57
#[derive(Debug, Clone, Copy)]
@@ -21,8 +23,10 @@ fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(
2123

2224
#[cfg(target_family = "windows")]
2325
match file_type {
24-
FileType::File => std::os::windows::fs::symlink_file(original, link),
25-
FileType::Dir => std::os::windows::fs::symlink_dir(original, link),
26+
// NOTE: original path should use `\` instead of `/` for relative paths
27+
// otherwise the symlink will be broken and the test will fail with InvalidFilename error
28+
FileType::File => std::os::windows::fs::symlink_file(original.as_ref().normalize(), link),
29+
FileType::Dir => std::os::windows::fs::symlink_dir(original.as_ref().normalize(), link),
2630
}
2731
}
2832

@@ -33,9 +37,7 @@ fn init(dirname: &Path, temp_path: &Path) -> io::Result<()> {
3337
fs::create_dir(temp_path)?;
3438
symlink(dirname.join("../lib/index.js"), temp_path.join("test"), FileType::File)?;
3539
symlink(dirname.join("../lib"), temp_path.join("test2"), FileType::Dir)?;
36-
fs::remove_file(temp_path.join("test"))?;
37-
fs::remove_file(temp_path.join("test2"))?;
38-
fs::remove_dir(temp_path)
40+
fs::remove_dir_all(temp_path)
3941
}
4042

4143
fn create_symlinks(dirname: &Path, temp_path: &Path) -> io::Result<()> {

0 commit comments

Comments
 (0)