build.spec.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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, responses } = 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(
  24. appDir,
  25. `src-tauri/target/${artifactFolder}/app`
  26. )
  27. const appPid = spawn(
  28. process.platform === 'win32'
  29. ? `${artifactPath}.exe`
  30. : artifactPath.replace(
  31. `${artifactFolder}/app`,
  32. `${artifactFolder}/./app`
  33. ),
  34. [],
  35. null
  36. )
  37. setTimeout(() => {
  38. if (!success) {
  39. server.close(() => {
  40. try {
  41. process.kill(appPid)
  42. } catch {}
  43. const failedCommands = Object.keys(responses)
  44. .filter((k) => responses[k] === null)
  45. .join(', ')
  46. reject("App didn't reply to " + failedCommands)
  47. })
  48. }
  49. }, 15000)
  50. } catch (error) {
  51. reject(error)
  52. }
  53. })
  54. }
  55. describe('Tauri Build', () => {
  56. const build = {
  57. devPath: distDir,
  58. distDir: distDir,
  59. withGlobalTauri: true
  60. }
  61. it.each`
  62. mode | flag
  63. ${'embedded-server'} | ${'debug'}
  64. ${'embedded-server'} | ${'release'}
  65. ${'no-server'} | ${'debug'}
  66. ${'no-server'} | ${'release'}
  67. `('works with the $mode $flag mode', ({ mode, flag }) => {
  68. return runBuildTest({
  69. build,
  70. ctx: {
  71. debug: flag === 'debug'
  72. },
  73. tauri: {
  74. allowlist: {
  75. all: true
  76. },
  77. embeddedServer: {
  78. active: mode === 'embedded-server'
  79. }
  80. }
  81. })
  82. })
  83. })