Skip to content

Commit

Permalink
test: fix symlink test init on windows (#307)
Browse files Browse the repository at this point in the history
* test: fix symlink test init on windows

* test: skip two tests on Windows

* test: fix relative symlink file tests

* chore: reduce diff
  • Loading branch information
sapphi-red authored Nov 12, 2024
1 parent e591956 commit ebc6c36
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/tests/symlink.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{fs, io, path::Path};

use normalize_path::NormalizePath;

use crate::{ResolveOptions, Resolver};

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

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

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

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

0 comments on commit ebc6c36

Please # to comment.