Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix: cargo test on windows

Louisf0a9080ef72f
diff --git a/.gitignore b/.gitignore
index f718cda44..b5177148e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,6 +51,8 @@ docs/.next/
**/yarn-error.log*
**/pnpm-debug.log*
-# Combined output for local testing
-combined-output/
+## cargo
target
+
+## test
+test-data
diff --git a/Makefile b/Makefile
index f314e7beb..9707b2815 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/src-tauri/.cargo/config.toml b/src-tauri/.cargo/config.toml
new file mode 100644
index 000000000..3c45f4de8
--- /dev/null
+++ b/src-tauri/.cargo/config.toml
@@ -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"
\ No newline at end of file
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 7efe29a70..4f93bd601 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -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"
diff --git a/src-tauri/src/core/cmd.rs b/src-tauri/src/core/cmd.rs
index ffa1b8a53..7e5589b0b 100644
--- a/src-tauri/src/core/cmd.rs
+++ b/src-tauri/src/core/cmd.rs
@@ -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);
diff --git a/src-tauri/src/core/fs.rs b/src-tauri/src/core/fs.rs
index e8e2ae8b4..2e23cab63 100644
--- a/src-tauri/src/core/fs.rs
+++ b/src-tauri/src/core/fs.rs
@@ -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();