فهرست منبع

fix(tauri.js) default config is invalid closes #777 (#785)

Lucas Fernandes Nogueira 5 سال پیش
والد
کامیت
6a179997b4

+ 6 - 0
.changes/fix-template.md

@@ -0,0 +1,6 @@
+---
+"tauri.js": patch
+---
+
+Fixes the wrong `cli` value on the template that's used by `tauri init`.
+Also fixes the template test.

+ 0 - 1
cli/tauri.js/src/template/defaultConfig.ts

@@ -7,7 +7,6 @@ export default {
   },
   ctx: {},
   tauri: {
-    cli: null,
     embeddedServer: {
       active: true
     },

+ 25 - 24
cli/tauri.js/test/jest/__tests__/template.spec.js

@@ -1,44 +1,45 @@
 const fixtureSetup = require('../fixtures/app-test-setup')
-const { resolve } = require('path')
-const { rmdirSync, existsSync, writeFileSync, readFileSync } = require('fs')
+const {
+  resolve
+} = require('path')
+const {
+  writeFileSync,
+  readFileSync
+} = require('fs')
 
 describe('[CLI] tauri.js template', () => {
-  it('init a project and builds it', done => {
+  it('init a project and builds it', async () => {
     const cwd = process.cwd()
-    try {
-      const fixturePath = resolve(__dirname, '../fixtures/empty')
-      const tauriFixturePath = resolve(fixturePath, 'src-tauri')
+    const fixturePath = resolve(__dirname, '../fixtures/empty')
+    const tauriFixturePath = resolve(fixturePath, 'src-tauri')
 
-      fixtureSetup.initJest('empty')
+    fixtureSetup.initJest('empty')
 
-      process.chdir(fixturePath)
+    process.chdir(fixturePath)
 
-      const init = require('api/init')
-      init({
-        directory: process.cwd(),
-        force: 'all',
-        tauriPath: resolve(__dirname, '../../../../..')
-      })
+    const init = require('api/init')
+    init({
+      directory: process.cwd(),
+      force: 'all',
+      tauriPath: resolve(__dirname, '../../../../..')
+    })
 
-      process.chdir(tauriFixturePath)
+    process.chdir(tauriFixturePath)
 
-      const manifestPath = resolve(tauriFixturePath, 'Cargo.toml')
-      const manifestFile = readFileSync(manifestPath).toString()
-      writeFileSync(manifestPath, `workspace = { }\n\n${manifestFile}`)
-    } catch (e) {
-      done(e)
-    }
+    const manifestPath = resolve(tauriFixturePath, 'Cargo.toml')
+    const manifestFile = readFileSync(manifestPath).toString()
+    writeFileSync(manifestPath, `workspace = { }\n\n${manifestFile}`)
 
     const build = require('api/build')
-    build({
+    await build({
       tauri: {
         bundle: {
           targets: ['deb', 'osx', 'msi', 'appimage'] // we can't bundle dmg on CI so we remove it here
         }
       }
     }).promise.then(() => {
+      writeFileSync('a.b', 'finished')
       process.chdir(cwd)
-      done()
-    }).catch(done)
+    })
   })
 })

+ 10 - 8
cli/tauri.js/test/jest/fixtures/app-test-setup.js

@@ -5,10 +5,10 @@ const mockFixtureDir = path.resolve(__dirname, '../fixtures')
 
 module.exports.fixtureDir = mockFixtureDir
 
-function mockResolvePath (basePath, dir) {
-  return dir && path.isAbsolute(dir)
-    ? dir
-    : path.resolve(basePath, dir)
+function mockResolvePath(basePath, dir) {
+  return dir && path.isAbsolute(dir) ?
+    dir :
+    path.resolve(basePath, dir)
 }
 
 module.exports.initJest = (mockFixture) => {
@@ -36,8 +36,6 @@ module.exports.initJest = (mockFixture) => {
       }
     }
   })
-
-  jest.spyOn(process, 'exit').mockImplementation(() => {})
 }
 
 module.exports.startServer = (onSuccess) => {
@@ -62,7 +60,8 @@ module.exports.startServer = (onSuccess) => {
     renameFileWithDir: null,
     listen: null
   }
-  function addResponse (response) {
+
+  function addResponse(response) {
     responses[response.cmd] = true
     if (!Object.values(responses).some(c => c === null)) {
       server.close(onSuccess)
@@ -107,5 +106,8 @@ module.exports.startServer = (onSuccess) => {
 
   const port = 7000
   const server = app.listen(port)
-  return { server, responses }
+  return {
+    server,
+    responses
+  }
 }