build.spec.js 2.1 KB

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