build.spec.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. const path = require('path')
  2. const fixtureSetup = require('../fixtures/app-test-setup')
  3. const appDir = path.join(fixtureSetup.fixtureDir, 'app')
  4. const distDir = path.join(appDir, 'dist')
  5. const spawn = require('helpers/spawn').spawn
  6. function runBuildTest(tauriConfig) {
  7. fixtureSetup.initJest('app')
  8. const build = require('api/build')
  9. return new Promise(async (resolve, reject) => {
  10. try {
  11. let success = false
  12. const server = fixtureSetup.startServer(() => {
  13. success = true
  14. try {
  15. process.kill(appPid)
  16. } catch {}
  17. // wait for the app process to be killed
  18. setTimeout(resolve, 2000)
  19. })
  20. const result = build(tauriConfig)
  21. await result.promise
  22. const artifactFolder = tauriConfig.ctx.debug ? 'debug' : 'release'
  23. const artifactPath = path.resolve(appDir, `src-tauri/target/${artifactFolder}/app`)
  24. const appPid = spawn(
  25. process.platform === 'win32' ? `${artifactPath}.exe` : artifactPath.replace(`${artifactFolder}/app`, `${artifactFolder}/./app`),
  26. [],
  27. null
  28. )
  29. setTimeout(() => {
  30. if (!success) {
  31. server.close(() => {
  32. try {
  33. process.kill(appPid)
  34. } catch {}
  35. reject("App didn't reply")
  36. })
  37. }
  38. }, 15000)
  39. } catch (error) {
  40. reject(error)
  41. }
  42. })
  43. }
  44. describe('Tauri Build', () => {
  45. const build = {
  46. devPath: distDir,
  47. distDir: distDir
  48. }
  49. it.each`
  50. mode | flag
  51. ${'embedded-server'} | ${'debug'}
  52. ${'embedded-server'} | ${'release'}
  53. ${'no-server'} | ${'debug'}
  54. ${'no-server'} | ${'release'}
  55. `('works with the $mode $flag mode', ({ mode, flag }) => {
  56. return runBuildTest({
  57. build,
  58. ctx: {
  59. debug: flag === 'debug'
  60. },
  61. tauri: {
  62. embeddedServer: {
  63. active: mode === 'embedded-server'
  64. }
  65. }
  66. })
  67. })
  68. })