Skip to content
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

docs improvements for test module #2094

Open
ospfranco opened this issue Apr 30, 2024 · 3 comments
Open

docs improvements for test module #2094

ospfranco opened this issue Apr 30, 2024 · 3 comments
Labels
enhancement Does it add or improve content?
Milestone

Comments

@ospfranco
Copy link

Describe the bug

I'm trying to write some tests for the Rust backend. In those tests I'm trying to create instances of a mock api so I can tests the bindings to JS are properly setup:

#[cfg(test)]
mod tests {
    use super::*;
    use std::fs;
    use std::path::Path;

    fn setup<R: tauri::Runtime>(
        builder: tauri::Builder<R>,
    ) -> Result<tauri::App<R>, std::io::Error> {
        let app = builder
            .plugin(super::init())
            .build(tauri::generate_context!())
            .unwrap();
		
		...

        Ok(app)
    }

    #[test]
    fn should_drop_model() {
        let app = setup(tauri::test::mock_builder()).unwrap();
        let app_data_dir = app.handle().path_resolver().app_data_dir().unwrap();
		...
    }

    #[test]
    fn should_drop_model2() {
        let app = setup(tauri::test::mock_builder()).unwrap();
        let app_data_dir = app.handle().path_resolver().app_data_dir().unwrap();
		...
    }
}

However, whenever I try to run my tests I get the following error:

error: symbol `_EMBED_INFO_PLIST` is already defined
   --> src/nebula/nebula.rs:352:20
    |
352 |             .build(tauri::generate_context!())
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in the macro `$crate::embed_info_plist_bytes` which comes from the expansion of the macro `tauri::generate_context` (in Nightly builds, run with -Z macro-backtrace for more info)

There is not a lot of documentation on how to achieve this but I can assume that creating multiple instances of a tauri app is not supported?

Reproduction

No response

Expected behavior

No response

Full tauri info output

~/Developer/pulsar (osp/vss*) » yarn tauri info                                                                                                                                                                                           130 ↵ osp@Oscars-MBP

[✔] Environment
    - OS: Mac OS 14.4.1 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.77.2 (25ef9e3d8 2024-04-09)
    ✔ cargo: 1.77.2 (e52e36006 2024-03-26)
    ✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 18.20.2
    - yarn: 4.1.0
    - npm: 10.5.0

[-] Packages
    - tauri [RUST]: 1.6.2
    - tauri-build [RUST]: 1.5.1
    - wry [RUST]: 0.24.7
    - tao [RUST]: 0.16.8
    - @tauri-apps/api [NPM]: 1.5.3 (outdated, latest: 1.5.4)
    - @tauri-apps/cli [NPM]: 1.5.11 (outdated, latest: 1.5.12)

[-] App
    - build-type: bundle
    - CSP: asset:
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

No response

Additional context

No response

@ospfranco ospfranco added the bug Does it fix inaccurate content or fix a bug? label Apr 30, 2024
@ospfranco
Copy link
Author

I just stumbled upon mock_app():

let app = tauri::test::mock_app();

That seems to work. Would be great to have this documented better.

@FabianLars FabianLars transferred this issue from tauri-apps/tauri Apr 30, 2024
@FabianLars
Copy link
Member

Moved this to the docs repo because i think the whole testing guide needs improvements, however this also needs to be fixed in the rust code docs so it's really an issue in both repos.

@FabianLars FabianLars changed the title [bug] cannot create more than one mock app? docs improvements for test module Apr 30, 2024
@ospfranco
Copy link
Author

ospfranco commented Apr 30, 2024

In order to create an app with the JS bindings I needed to test I had to do it this way, not sure if it is the correct way but it works for me:

let app = tauri::test::mock_builder()
            .plugin(super::init())
            .build(mock_context(noop_assets()))
            .unwrap();

@simonhyll simonhyll added this to the Version 1.x milestone May 19, 2024
@simonhyll simonhyll added enhancement Does it add or improve content? and removed bug Does it fix inaccurate content or fix a bug? labels May 21, 2024
@simonhyll simonhyll modified the milestones: Version 1.x, Version 2.0 May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Does it add or improve content?
Projects
Status: 💪 Ready
Development

No branches or pull requests

3 participants