index.js 1.3 KB

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