Kaynağa Gözat

test(tauri.js) update fixture app and fix build/dev e2e tests (#1058)

Lucas Fernandes Nogueira 4 yıl önce
ebeveyn
işleme
a3b724738e

+ 1 - 0
cli/tauri.js/jest.config.js

@@ -41,6 +41,7 @@ module.exports = {
   transform: {
     'templates[\\\\/](tauri|mutation-observer).js':
       './test/jest/raw-loader-transformer.js',
+    'api[\\\\/]tauri.bundle.umd.js': './test/jest/raw-loader-transformer.js',
     '\\.(js|ts)$': 'babel-jest'
   }
 }

+ 5 - 1
cli/tauri.js/test/jest/__tests__/build.spec.js

@@ -61,7 +61,8 @@ function runBuildTest(tauriConfig) {
 describe('Tauri Build', () => {
   const build = {
     devPath: distDir,
-    distDir: distDir
+    distDir: distDir,
+    withGlobalTauri: true
   }
 
   it.each`
@@ -77,6 +78,9 @@ describe('Tauri Build', () => {
         debug: flag === 'debug'
       },
       tauri: {
+        allowlist: {
+          all: true
+        },
         embeddedServer: {
           active: mode === 'embedded-server'
         }

+ 2 - 1
cli/tauri.js/test/jest/__tests__/dev.spec.js

@@ -66,7 +66,8 @@ function runDevTest(tauriConfig) {
 
 describe('Tauri Dev', () => {
   const build = {
-    distDir: distDir
+    distDir: distDir,
+    withGlobalTauri: true
   }
 
   const devServer = startDevServer()

+ 2 - 2
cli/tauri.js/test/jest/fixtures/app/dist/index.html

@@ -36,7 +36,7 @@
         return window.__TAURI__.fs
           .writeFile(
             {
-              file: 'tauri-test.txt',
+              path: 'tauri-test.txt',
               contents: contents
             },
             options
@@ -136,7 +136,7 @@
       })
 
       setTimeout(function () {
-        window.__TAURI__.invoke({
+        window.__TAURI_INVOKE_HANDLER__({
           cmd: 'exit'
         })
       }, 15000)

+ 1 - 1
cli/tauri.js/test/jest/fixtures/app/src-tauri/Cargo.toml

@@ -27,7 +27,7 @@ serde_derive = "1.0"
 tiny_http = "0.7"
 phf = "0.8.0"
 includedir = "0.6.0"
-tauri = { path = "../../../../../../../tauri", features = [ "all-api", "edge" ] }
+tauri = { path = "../../../../../../../tauri", features = [ "all-api" ] }
 
 [features]
 embedded-server = [ "tauri/embedded-server" ]

+ 12 - 9
cli/tauri.js/test/jest/fixtures/app/src-tauri/src/main.rs

@@ -7,23 +7,26 @@ extern crate serde_json;
 fn main() {
   tauri::AppBuilder::new()
     .setup(|webview, _| {
-      let handle = webview.handle();
+      let mut webview_ = webview.as_mut();
       tauri::event::listen(String::from("hello"), move |_| {
-        tauri::event::emit(&handle, String::from("reply"), Some("{ msg: 'TEST' }".to_string()));
+        tauri::event::emit(
+          &mut webview_,
+          String::from("reply"),
+          Some("{ msg: 'TEST' }".to_string()),
+        )
+        .unwrap();
       });
-      webview.eval("window.onTauriInit && window.onTauriInit()").unwrap();
+      webview.eval("window.onTauriInit && window.onTauriInit()");
     })
-     .invoke_handler(|webview, arg| {
+    .invoke_handler(|webview, arg| {
       use cmd::Cmd::*;
       match serde_json::from_str(arg) {
-        Err(e) => {
-          Err(e.to_string())
-        }
+        Err(e) => Err(e.to_string()),
         Ok(command) => {
           match command {
             // definitions for your custom commands from Cmd here
-            Exit { } => {
-              webview.exit();
+            Exit {} => {
+              webview.terminate();
             }
           }
           Ok(())