index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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, () =>
  16. console.log(`Test listening on port ${port}!`)
  17. )
  18. const exit = (code) => {
  19. server.close()
  20. process.kill(appPid)
  21. process.exit(code)
  22. }
  23. const path = require('path')
  24. const dist = path.resolve(__dirname, 'dist')
  25. const build = require('../cli/tauri.js/dist/api/build')
  26. build({
  27. build: {
  28. devPath: dist
  29. },
  30. ctx: {
  31. debug: true
  32. },
  33. tauri: {
  34. embeddedServer: {
  35. active: true
  36. }
  37. }
  38. }).then(() => {
  39. const spawn = require('../cli/tauri.js/dist/helpers/spawn').spawn
  40. const artifactPath = path.resolve(__dirname, 'src-tauri/target/debug/app')
  41. appPid = spawn(
  42. process.platform === 'win32'
  43. ? `${artifactPath}.exe`
  44. : artifactPath.replace('debug/app', 'debug/./app'),
  45. [],
  46. null
  47. )
  48. // if it didn't reply, throw an error
  49. setTimeout(() => {
  50. throw new Error("App didn't reply")
  51. }, 2000)
  52. })