Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"preparescript": "node scripts/prepare.js",
"localdev": "dotenv -e ../../.env -- vinxi dev --port 3001",
"build": "vinxi build",
"tauri": "tauri"
"tauri": "tauri",
"test:desktop": "cd src-tauri && cargo test"
},
"dependencies": {
"@aerofoil/rive-solid-canvas": "^2.1.4",
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ tauri-plugin-deep-link = "2.2.0"
tauri-plugin-clipboard-manager = "2.2.1"
tauri-plugin-opener = "2.2.6"

[[test]]
name = "tests"
path = "tests/main.rs"

Comment thread
Excellencedev marked this conversation as resolved.
Outdated
[dev-dependencies]
tauri = { workspace = true, features = ["testing"] }
serde_json = "1.0.111"

Comment thread
Excellencedev marked this conversation as resolved.
Outdated
[features]
# DO NOT REMOVE!
custom-protocol = ["tauri/custom-protocol"]

scap = { workspace = true }
serde = { workspace = true }
serde_json = "1.0.111"
Expand Down
28 changes: 28 additions & 0 deletions apps/desktop/src-tauri/tests/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::time::Duration;
use tauri::App;

pub fn setup_test_app() -> App {
let app = tauri::test::mock_app();
// Any additional setup for the app can go here
app
}

pub async fn wait_for_event<F, Fut>(app: &App, event_name: &str, trigger: F)
where
F: FnOnce() -> Fut,
Fut: std::future::Future<Output = ()>,
{
let mut rx = app.listen_global(event_name, |event| {
println!("Received event: {:?}", event);
});

trigger().await;

let handle = tokio::spawn(async move {
tokio::time::timeout(Duration::from_secs(5), rx.recv())
.await
.expect("event was not received")
});

handle.await.unwrap();
}
Comment thread
Excellencedev marked this conversation as resolved.
1 change: 1 addition & 0 deletions apps/desktop/src-tauri/tests/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod recording;
39 changes: 39 additions & 0 deletions apps/desktop/src-tauri/tests/recording.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use cap_desktop_lib::{
recording::{start_recording, stop_recording, StartRecordingInputs},
RecordingMode,
};
use common::setup_test_app;
use scap_targets::available_displays;
use tauri::Manager;

mod common;

#[tokio::test]
async fn test_start_and_stop_recording() {
let app = setup_test_app();
let window = app.get_window("main").unwrap();

Comment thread
coderabbitai[bot] marked this conversation as resolved.
let displays = available_displays().unwrap();
let first_display = displays.first().expect("No display found");

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
let inputs = StartRecordingInputs {
mode: RecordingMode::Instant,
target: cap_recording::sources::ScreenCaptureTarget::Display {
id: first_display.id(),
},
..Default::default()
};
Comment thread
Excellencedev marked this conversation as resolved.

let app_handle = app.handle().clone();
let state = app.state::<tauri::async_runtime::Mutex<cap_desktop_lib::App>>();

start_recording(app_handle.clone(), state.clone(), inputs)
.await
.expect("Failed to start recording");

let result = stop_recording(app_handle, state)
.await
.expect("Failed to stop recording");

assert!(result.is_some(), "Stopping the recording did not return a completed recording");
}
Comment thread
Excellencedev marked this conversation as resolved.