Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix symlink test init on windows #307

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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