浏览代码

fix(tests): update cli.js app fixture (#1469)

Lucas Fernandes Nogueira 4 年之前
父节点
当前提交
64d7625b28

+ 1 - 0
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'

+ 8 - 11
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)
     </script>
   </body>

+ 5 - 6
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"

+ 7 - 0
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()
+}

+ 12 - 18
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<M: tauri::Params>(window: tauri::Window<M>) {
+  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");
 }

+ 5 - 3
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
       }
     ]
   }

+ 2 - 0
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<BundleTarget>,
@@ -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")]

+ 2 - 6
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": {