build.spec.js 2.1 KB

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