fix: cargo test on windows

This commit is contained in:
Louis 2025-08-10 22:46:44 +07:00
parent fc7d8a7a9c
commit f0a9080ef7
6 changed files with 48 additions and 14 deletions

6
.gitignore vendored
View File

@ -51,6 +51,8 @@ docs/.next/
**/yarn-error.log*
**/pnpm-debug.log*
# Combined output for local testing
combined-output/
## cargo
target
## test
test-data

View File

@ -43,7 +43,7 @@ test: lint
yarn test
yarn copy:assets:tauri
yarn build:icon
cargo test --manifest-path src-tauri/Cargo.toml
cargo test --manifest-path src-tauri/Cargo.toml --no-default-features --features test-tauri
# Builds and publishes the app
build-and-publish: install-and-build

View File

@ -0,0 +1,4 @@
[env]
# workaround needed to prevent `STATUS_ENTRYPOINT_NOT_FOUND` error in tests
# see https://github.com/tauri-apps/tauri/pull/4383#issuecomment-1212221864
__TAURI_WORKSPACE__ = "true"

View File

@ -7,11 +7,30 @@ license = "MIT"
repository = "https://github.com/menloresearch/jan"
edition = "2021"
rust-version = "1.77.2"
resolver = "2"
[lib]
name = "app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[features]
default = [
"tauri/wry",
"tauri/common-controls-v6",
"tauri/x11",
"tauri/protocol-asset",
"tauri/macos-private-api",
"tauri/test",
]
test-tauri = [
"tauri/wry",
"tauri/x11",
"tauri/protocol-asset",
"tauri/macos-private-api",
"tauri/test",
]
[build-dependencies]
tauri-build = { version = "2.0.2", features = [] }
@ -19,9 +38,6 @@ tauri-build = { version = "2.0.2", features = [] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
log = "0.4"
tauri = { version = "2.5.0", features = [ "protocol-asset", "macos-private-api",
"test"
] }
tauri-plugin-log = "2.0.0-rc"
tauri-plugin-shell = "2.2.0"
tauri-plugin-os = "2.2.1"
@ -60,7 +76,19 @@ base64 = "0.22.1"
libloading = "0.8.7"
thiserror = "2.0.12"
[target.'cfg(not(windows))'.dependencies]
[dependencies.tauri]
version = "2.5.0"
default-features = false
features = [
"protocol-asset",
"macos-private-api",
"test",
]
[target.'cfg(windows)'.dev-dependencies]
tempfile = "3.20.0"
[target.'cfg(unix)'.dependencies]
nix = "=0.30.1"
[target.'cfg(windows)'.dependencies]
@ -71,6 +99,3 @@ windows-sys = { version = "0.60.2", features = ["Win32_Storage_FileSystem"] }
tauri-plugin-updater = "2"
once_cell = "1.18"
tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] }
[target.'cfg(windows)'.dev-dependencies]
tempfile = "3.20.0"

View File

@ -94,7 +94,11 @@ pub fn update_app_configuration(
#[tauri::command]
pub fn get_jan_data_folder_path<R: Runtime>(app_handle: tauri::AppHandle<R>) -> PathBuf {
if cfg!(test) {
return PathBuf::from("./data");
let path = PathBuf::from("test-data");
if !path.exists() {
let _ = fs::create_dir_all(&path);
}
return path;
}
let app_configurations = get_app_configurations(app_handle);

View File

@ -194,7 +194,7 @@ mod tests {
assert_eq!(
result,
get_jan_data_folder_path(app.handle().clone())
.join("test_dir/test_file")
.join(&format!("test_dir{}test_file", std::path::MAIN_SEPARATOR))
.to_string_lossy()
.to_string()
);
@ -232,8 +232,7 @@ mod tests {
#[test]
fn test_readdir_sync() {
let app = mock_app();
let path = "file://test_readdir_sync_dir";
let dir_path = get_jan_data_folder_path(app.handle().clone()).join(path);
let dir_path = get_jan_data_folder_path(app.handle().clone()).join("test_readdir_sync_dir");
fs::create_dir_all(&dir_path).unwrap();
File::create(dir_path.join("file1.txt")).unwrap();
File::create(dir_path.join("file2.txt")).unwrap();