mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-01-31 00:45:24 +01:00
6
.changes/make-sidecars-work-in-tests.md
Normal file
6
.changes/make-sidecars-work-in-tests.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'shell': 'patch:bug'
|
||||
'shell-js': 'patch:bug'
|
||||
---
|
||||
|
||||
Make sidecars work in tests. Executable resolution is aware of the "deps" directory.
|
||||
@@ -118,27 +118,38 @@ pub struct Output {
|
||||
}
|
||||
|
||||
fn relative_command_path(command: &Path) -> crate::Result<PathBuf> {
|
||||
match platform::current_exe()?.parent() {
|
||||
let exe_path = platform::current_exe()?;
|
||||
|
||||
let exe_dir = exe_path
|
||||
.parent()
|
||||
.ok_or(crate::Error::CurrentExeHasNoParent)?;
|
||||
|
||||
// If a test is being run, the executable is in the "deps" directory, so we need to go up one level.
|
||||
let base_dir = if exe_dir.ends_with("deps") {
|
||||
exe_dir.parent().unwrap_or(exe_dir)
|
||||
} else {
|
||||
exe_dir
|
||||
};
|
||||
|
||||
let mut command_path = base_dir.join(command);
|
||||
|
||||
#[cfg(windows)]
|
||||
Some(exe_dir) => {
|
||||
let mut command_path = exe_dir.join(command);
|
||||
{
|
||||
let already_exe = command_path.extension().is_some_and(|ext| ext == "exe");
|
||||
if !already_exe {
|
||||
// do not use with_extension to retain dots in the command filename
|
||||
command_path.as_mut_os_string().push(".exe");
|
||||
}
|
||||
Ok(command_path)
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
Some(exe_dir) => {
|
||||
let mut command_path = exe_dir.join(command);
|
||||
{
|
||||
if command_path.extension().is_some_and(|ext| ext == "exe") {
|
||||
command_path.set_extension("");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(command_path)
|
||||
}
|
||||
None => Err(crate::Error::CurrentExeHasNoParent),
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Command> for StdCommand {
|
||||
@@ -508,6 +519,8 @@ mod tests {
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent() // Go up once more to get out of the "deps" directory
|
||||
.unwrap()
|
||||
.to_owned();
|
||||
assert_eq!(
|
||||
relative_command_path(Path::new("Tauri.Example")).unwrap(),
|
||||
|
||||
Reference in New Issue
Block a user