build.spec.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. await build(args).promise
  22. const artifactFolder = args.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. `('works with the $mode $flag mode', ({ mode, flag }) => {
  66. return runBuildTest({
  67. debug: flag === 'debug',
  68. config: {
  69. build,
  70. tauri: {
  71. allowlist: {
  72. all: true
  73. }
  74. }
  75. }
  76. })
  77. })
  78. })