-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Feat: Implement Rust Testing Framework for Desktop #1000
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8663971
Add tests
Excellencedev 3729a51
CodeRabbit reviews
Excellencedev 6bb8f15
Update apps/desktop/src-tauri/Cargo.toml
Excellencedev 6933876
Finish remaining tests
Excellencedev 02fc5ff
Merge branch 'fix-184' of https://github.com/Excellencedev/Cap into f…
Excellencedev d0adac1
Update apps/desktop/src-tauri/tests/export.rs
Excellencedev 8066260
Fix nitpicks
Excellencedev b2e02c5
Fix builds
Excellencedev 6346b46
Merge branch 'fix-184' of https://github.com/Excellencedev/Cap into f…
Excellencedev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
|
Excellencedev marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| mod recording; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| let displays = available_displays().unwrap(); | ||
| let first_display = displays.first().expect("No display found"); | ||
|
|
||
|
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() | ||
| }; | ||
|
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"); | ||
| } | ||
|
Excellencedev marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.