index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const express = require('express')
  2. const cors = require('cors')
  3. const app = express()
  4. app.use(cors())
  5. app.use(express.json())
  6. const port = 7000
  7. let appPid
  8. app.post('/reply', (req, res) => {
  9. if (req.body && req.body.msg !== 'TEST') {
  10. throw new Error(`unexpected reply ${JSON.stringify(req.body)}`)
  11. }
  12. console.log('App event replied')
  13. exit(0)
  14. })
  15. const server = app.listen(port, () => console.log(`Test listening on port ${port}!`))
  16. const exit = code => {
  17. server.close()
  18. process.kill(appPid)
  19. process.exit(code)
  20. }
  21. const path = require('path')
  22. const dist = path.resolve(__dirname, 'dist')
  23. const build = require('../cli/tauri.js/dist/api/build')
  24. build({
  25. build: {
  26. devPath: dist
  27. },
  28. ctx: {
  29. debug: true
  30. },
  31. tauri: {
  32. embeddedServer: {
  33. active: true
  34. }
  35. }
  36. }).then(() => {
  37. const spawn = require('../cli/tauri.js/dist/helpers/spawn').spawn
  38. const artifactPath = path.resolve(__dirname, 'src-tauri/target/debug/app')
  39. appPid = spawn(
  40. process.platform === 'win32' ? `${artifactPath}.exe` : artifactPath.replace('debug/app', 'debug/./app'),
  41. [],
  42. null
  43. )
  44. // if it didn't reply, throw an error
  45. setTimeout(() => {
  46. throw new Error("App didn't reply")
  47. }, 2000)
  48. })