index.spec.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. import execa from 'execa'
  5. import fixtures from 'fixturez'
  6. const f = fixtures(__dirname)
  7. import path from 'path'
  8. import fs from 'fs'
  9. const ctaBinary = path.resolve('./bin/create-tauri-app.js')
  10. const clijs = path.resolve('../cli.js/')
  11. const api = path.resolve('../api/')
  12. const manager = process.env.TAURI_RUN_MANAGER ?? 'npm'
  13. const recipes = process.env.TAURI_RECIPE
  14. ? [process.env.TAURI_RECIPE]
  15. : ['vanillajs', 'reactjs', 'reactts', 'vite', 'vuecli']
  16. const timeoutLong = 900000
  17. const timeoutLittleLonger = 930000
  18. const logOut = false ? 'inherit' : 'pipe'
  19. beforeAll(async () => {
  20. const installCLI = await execa('yarn', [], {
  21. stdio: logOut,
  22. cwd: clijs,
  23. timeout: timeoutLong
  24. })
  25. const buildCLI = await execa('yarn', ['build-release'], {
  26. stdio: logOut,
  27. cwd: clijs,
  28. timeout: timeoutLong
  29. })
  30. const linkCLI = await execa('yarn', ['link'], {
  31. stdio: logOut,
  32. cwd: clijs,
  33. timeout: timeoutLong
  34. })
  35. const installAPI = await execa('yarn', [], {
  36. stdio: logOut,
  37. cwd: api,
  38. timeout: timeoutLong
  39. })
  40. const buildAPI = await execa('yarn', ['build'], {
  41. stdio: logOut,
  42. cwd: api,
  43. timeout: timeoutLong
  44. })
  45. const linkAPI = await execa('yarn', ['link'], {
  46. stdio: logOut,
  47. cwd: api,
  48. timeout: timeoutLong
  49. })
  50. }, timeoutLittleLonger)
  51. describe('CTA', () => {
  52. describe.each(recipes.map((recipe) => [recipe, 'tauri-app']))(
  53. `%s recipe`,
  54. (recipe: string, appName: string) => {
  55. it(
  56. 'runs',
  57. async () => {
  58. // creates a temp folder to run CTA within (this is our cwd)
  59. const folder = f.temp()
  60. const appFolder = path.join(folder, appName)
  61. // runs CTA with all args set to avoid any prompts
  62. const cta = await execa(
  63. 'node',
  64. [
  65. ctaBinary,
  66. '--manager',
  67. manager,
  68. '--recipe',
  69. recipe,
  70. '--ci',
  71. '--dev'
  72. ],
  73. {
  74. all: true,
  75. stdio: logOut,
  76. cwd: folder,
  77. timeout: timeoutLong
  78. }
  79. )
  80. // check to make certain it didn't fail anywhere
  81. expect(cta.failed).toBe(false)
  82. expect(cta.timedOut).toBe(false)
  83. expect(cta.isCanceled).toBe(false)
  84. expect(cta.killed).toBe(false)
  85. expect(cta.signal).toBe(undefined)
  86. // run a tauri build to check if what we produced
  87. // can actually create an app
  88. // TODO long term we will want to hook this up to a real test harness
  89. // and then run that test suite instead
  90. let opts: string[] = []
  91. if (manager === 'npm') {
  92. opts = ['run', 'tauri', '--', 'build']
  93. } else if (manager === 'yarn') {
  94. opts = ['tauri', 'build']
  95. }
  96. const tauriBuild = await execa(manager, opts, {
  97. all: true,
  98. stdio: logOut,
  99. cwd: appFolder,
  100. timeout: timeoutLong
  101. })
  102. expect(tauriBuild.failed).toBe(false)
  103. expect(tauriBuild.timedOut).toBe(false)
  104. expect(tauriBuild.isCanceled).toBe(false)
  105. expect(tauriBuild.killed).toBe(false)
  106. expect(tauriBuild.signal).toBe(undefined)
  107. const packageFileOutput: {
  108. [k: string]: string | object
  109. } = JSON.parse(
  110. await fs.promises.readFile(
  111. path.join(appFolder, 'package.json'),
  112. 'utf-8'
  113. )
  114. )
  115. expect(packageFileOutput['name']).toBe(appName)
  116. const assertCustom: { [k: string]: Function } = {
  117. vanillajs: () => {
  118. expect(packageFileOutput['scripts']).toMatchObject({
  119. tauri: 'tauri'
  120. })
  121. },
  122. reactjs: () => {
  123. expect(packageFileOutput['scripts']).toEqual(
  124. expect.objectContaining({
  125. tauri: 'tauri'
  126. })
  127. )
  128. },
  129. reactts: () => {
  130. expect(packageFileOutput['scripts']).toEqual(
  131. expect.objectContaining({
  132. tauri: 'tauri'
  133. })
  134. )
  135. }
  136. }
  137. const getCustomAsserts = assertCustom[recipe]
  138. if (getCustomAsserts) getCustomAsserts()
  139. },
  140. timeoutLittleLonger
  141. )
  142. }
  143. )
  144. })