index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }).then(() => {
  34. const spawn = require('../cli/tauri.js/dist/helpers/spawn').spawn
  35. const artifactPath = path.resolve(__dirname, 'src-tauri/target/debug/app')
  36. appPid = spawn(
  37. process.platform === 'win32'
  38. ? `${artifactPath}.exe`
  39. : artifactPath.replace('debug/app', 'debug/./app'),
  40. [],
  41. null
  42. )
  43. // if it didn't reply, throw an error
  44. setTimeout(() => {
  45. throw new Error("App didn't reply")
  46. }, 2000)
  47. })