build.spec.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // wait for the app process to be killed
  15. setTimeout(resolve, 2000)
  16. })
  17. const result = build(tauriConfig)
  18. await result.promise
  19. const artifactFolder = tauriConfig.ctx.debug ? 'debug' : 'release'
  20. const artifactPath = path.resolve(appDir, `src-tauri/target/${artifactFolder}/app`)
  21. const appPid = spawn(
  22. process.platform === 'win32' ? `${artifactPath}.exe` : artifactPath.replace(`${artifactFolder}/app`, `${artifactFolder}/./app`),
  23. [],
  24. null
  25. )
  26. setTimeout(() => {
  27. if (!success) {
  28. server.close(() => {
  29. try {
  30. process.kill(appPid)
  31. } catch {}
  32. reject("App didn't reply")
  33. })
  34. }
  35. }, 2500)
  36. } catch (error) {
  37. reject(error)
  38. }
  39. })
  40. }
  41. describe('Tauri Build', () => {
  42. const build = {
  43. devPath: distDir,
  44. distDir: distDir
  45. }
  46. it.each`
  47. mode | flag
  48. ${'embedded-server'} | ${'debug'}
  49. ${'embedded-server'} | ${'release'}
  50. ${'no-server'} | ${'debug'}
  51. ${'no-server'} | ${'release'}
  52. `('works with the $mode $flag mode', ({ mode, flag }) => {
  53. return runBuildTest({
  54. build,
  55. ctx: {
  56. debug: flag === 'debug'
  57. },
  58. tauri: {
  59. embeddedServer: {
  60. active: mode === 'embedded-server'
  61. }
  62. }
  63. })
  64. })
  65. })