build.spec.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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(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. const failedCommands = Object.keys(responses).filter(k => responses[k] === null).join(', ')
  36. reject("App didn't reply to " + failedCommands)
  37. })
  38. }
  39. }, 15000)
  40. } catch (error) {
  41. reject(error)
  42. }
  43. })
  44. }
  45. describe('Tauri Build', () => {
  46. const build = {
  47. devPath: distDir,
  48. distDir: distDir
  49. }
  50. it.each`
  51. mode | flag
  52. ${'embedded-server'} | ${'debug'}
  53. ${'embedded-server'} | ${'release'}
  54. ${'no-server'} | ${'debug'}
  55. ${'no-server'} | ${'release'}
  56. `('works with the $mode $flag mode', ({ mode, flag }) => {
  57. return runBuildTest({
  58. build,
  59. ctx: {
  60. debug: flag === 'debug'
  61. },
  62. tauri: {
  63. embeddedServer: {
  64. active: mode === 'embedded-server'
  65. }
  66. }
  67. })
  68. })
  69. })