From 64d7625b2877390185d1bc98adc8de708486ca34 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 13 Apr 2021 01:47:34 -0300 Subject: [PATCH] fix(tests): update cli.js app fixture (#1469) --- .../cli.js/test/jest/__tests__/build.spec.js | 1 + .../test/jest/fixtures/app/dist/index.html | 19 +++++------- .../jest/fixtures/app/src-tauri/Cargo.toml | 11 ++++--- .../test/jest/fixtures/app/src-tauri/build.rs | 7 +++++ .../jest/fixtures/app/src-tauri/src/main.rs | 30 ++++++++----------- .../fixtures/app/src-tauri/tauri.conf.json | 8 +++-- tooling/cli.rs/config_definition.rs | 2 ++ tooling/cli.rs/schema.json | 8 ++--- 8 files changed, 42 insertions(+), 44 deletions(-) create mode 100644 tooling/cli.js/test/jest/fixtures/app/src-tauri/build.rs diff --git a/tooling/cli.js/test/jest/__tests__/build.spec.js b/tooling/cli.js/test/jest/__tests__/build.spec.js index fcc0ccb41..d78342e15 100644 --- a/tooling/cli.js/test/jest/__tests__/build.spec.js +++ b/tooling/cli.js/test/jest/__tests__/build.spec.js @@ -20,6 +20,7 @@ function runBuildTest(args) { setTimeout(resolve, 2000) }) process.chdir(appDir) + console.log(server) await build(args).promise const artifactFolder = args.debug ? 'debug' : 'release' diff --git a/tooling/cli.js/test/jest/fixtures/app/dist/index.html b/tooling/cli.js/test/jest/fixtures/app/dist/index.html index 052a4fa74..6bf0b6149 100644 --- a/tooling/cli.js/test/jest/fixtures/app/dist/index.html +++ b/tooling/cli.js/test/jest/fixtures/app/dist/index.html @@ -5,16 +5,13 @@ function callBackEnd(route, args) { console.log(route) console.log(args) - var xhr = new XMLHttpRequest() - xhr.onload = function () { - console.log(route, args, 'done', xhr.status) - } - xhr.onerror = function () { - console.log(route, args, 'error with ' + xhr.status) - } - xhr.open('POST', 'http://localhost:7000/' + route) - xhr.setRequestHeader('Content-type', 'application/json') - xhr.send(JSON.stringify(args)) + window.__TAURI__.http + .fetch('http://localhost:7000/' + route, { + method: 'POST', + body: window.__TAURI__.http.Body.json(args), + responseType: window.__TAURI__.http.ResponseType.Binary + }) + .catch(console.error) } function reply(args) { @@ -136,7 +133,7 @@ }) setTimeout(function () { - window.rpc.notify('exit') + window.__TAURI__.invoke('exit') }, 15000) diff --git a/tooling/cli.js/test/jest/fixtures/app/src-tauri/Cargo.toml b/tooling/cli.js/test/jest/fixtures/app/src-tauri/Cargo.toml index e2d8bfdbc..963ad38d7 100644 --- a/tooling/cli.js/test/jest/fixtures/app/src-tauri/Cargo.toml +++ b/tooling/cli.js/test/jest/fixtures/app/src-tauri/Cargo.toml @@ -4,10 +4,9 @@ workspace = { } name = "app" version = "0.1.0" description = "A Tauri App" -author = [ "Daniel Thompson-Yvetot" ] +authors = [ "Daniel Thompson-Yvetot" ] license = "" repository = "" -default-run = "app" edition = "2018" [package.metadata.bundle] @@ -20,6 +19,9 @@ icon = [ "icons/icon.ico" ] +[build-dependencies] +tauri-build = { path = "../../../../../../../core/tauri-build" } + [dependencies] serde_json = "1.0.64" serde = "1.0" @@ -27,8 +29,5 @@ serde_derive = "1.0" tauri = { path = "../../../../../../../core/tauri", features =["api-all"]} [features] +default = [ "custom-protocol" ] custom-protocol = [ "tauri/custom-protocol" ] - -[[bin]] -name = "app" -path = "src/main.rs" diff --git a/tooling/cli.js/test/jest/fixtures/app/src-tauri/build.rs b/tooling/cli.js/test/jest/fixtures/app/src-tauri/build.rs new file mode 100644 index 000000000..71557e5b9 --- /dev/null +++ b/tooling/cli.js/test/jest/fixtures/app/src-tauri/build.rs @@ -0,0 +1,7 @@ +// Copyright 2019-2021 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +fn main() { + tauri_build::build() +} diff --git a/tooling/cli.js/test/jest/fixtures/app/src-tauri/src/main.rs b/tooling/cli.js/test/jest/fixtures/app/src-tauri/src/main.rs index 3bdd48da3..6f05ad621 100644 --- a/tooling/cli.js/test/jest/fixtures/app/src-tauri/src/main.rs +++ b/tooling/cli.js/test/jest/fixtures/app/src-tauri/src/main.rs @@ -1,26 +1,20 @@ -use tauri::ApplicationDispatcherExt; +#[tauri::command(with_window)] +fn exit(window: tauri::Window) { + window.close().unwrap(); +} fn main() { tauri::Builder::default() - .setup(|webview_manager| async move { - let mut webview_manager_ = webview_manager.clone(); - tauri::event::listen(String::from("hello"), move |_| { - tauri::event::emit( - &webview_manager_, - String::from("reply"), - Some("{ msg: 'TEST' }".to_string()), - ) - .unwrap(); + .on_page_load(|window, _| { + let window_ = window.clone(); + window.listen("hello".into(), move |_| { + window_ + .emit(&"reply".to_string(), Some("{ msg: 'TEST' }".to_string())) + .unwrap(); }); - webview_manager - .current_webview() - .eval("window.onTauriInit && window.onTauriInit()"); - }) - .invoke_handler(|webview_manager, command, _arg| async move { - if &command == "exit" { - webview_manager.close().unwrap(); - } + window.eval("window.onTauriInit()").unwrap(); }) + .invoke_handler(tauri::generate_handler![exit]) .run(tauri::generate_context!()) .expect("error encountered while running tauri application"); } diff --git a/tooling/cli.js/test/jest/fixtures/app/src-tauri/tauri.conf.json b/tooling/cli.js/test/jest/fixtures/app/src-tauri/tauri.conf.json index 298aa0e37..ca1fe4e6a 100644 --- a/tooling/cli.js/test/jest/fixtures/app/src-tauri/tauri.conf.json +++ b/tooling/cli.js/test/jest/fixtures/app/src-tauri/tauri.conf.json @@ -1,7 +1,8 @@ { "build": { - "devPath": "http://localhost:4000", - "distDir": "../dist" + "devPath": "../dist", + "distDir": "../dist", + "withGlobalTauri": true }, "tauri": { "allowlist": { @@ -19,7 +20,8 @@ }, "windows": [ { - "title": "Fixture" + "title": "Fixture", + "visible": false } ] } diff --git a/tooling/cli.rs/config_definition.rs b/tooling/cli.rs/config_definition.rs index e9de0162c..bf5ec3cbe 100644 --- a/tooling/cli.rs/config_definition.rs +++ b/tooling/cli.rs/config_definition.rs @@ -64,6 +64,7 @@ pub struct PackageConfig { #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct BundleConfig { /// Whether we should build your app with tauri-bundler or plain `cargo build` + #[serde(default)] pub active: bool, /// The bundle targets, currently supports ["deb", "app", "msi", "appimage", "dmg"] or "all" pub targets: Option, @@ -535,6 +536,7 @@ impl TauriConfig { #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct UpdaterConfig { /// Whether the updater is active or not. + #[serde(default)] pub active: bool, /// Display built-in dialog or use event system if disabled. #[serde(default = "default_dialog")] diff --git a/tooling/cli.rs/schema.json b/tooling/cli.rs/schema.json index 7e0d85d1d..a301f5b88 100644 --- a/tooling/cli.rs/schema.json +++ b/tooling/cli.rs/schema.json @@ -242,12 +242,10 @@ }, "BundleConfig": { "type": "object", - "required": [ - "active" - ], "properties": { "active": { "description": "Whether we should build your app with tauri-bundler or plain `cargo build`", + "default": false, "type": "boolean" }, "category": { @@ -966,12 +964,10 @@ }, "UpdaterConfig": { "type": "object", - "required": [ - "active" - ], "properties": { "active": { "description": "Whether the updater is active or not.", + "default": false, "type": "boolean" }, "dialog": {