template.spec.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import * as fixtureSetup from '../fixtures/app-test-setup.js'
  2. import { resolve, dirname } from 'path'
  3. import { existsSync, readFileSync, writeFileSync } from 'fs'
  4. import { move } from 'fs-extra'
  5. import { init, build } from 'dist/api/cli'
  6. import { fileURLToPath } from 'url'
  7. const currentDirName = dirname(fileURLToPath(import.meta.url))
  8. describe('[CLI] cli.js template', () => {
  9. it('init a project and builds it', async () => {
  10. const cwd = process.cwd()
  11. const fixturePath = resolve(currentDirName, '../fixtures/empty')
  12. const tauriFixturePath = resolve(fixturePath, 'src-tauri')
  13. const outPath = resolve(tauriFixturePath, 'target')
  14. const cacheOutPath = resolve(fixturePath, 'target')
  15. fixtureSetup.initJest('empty')
  16. process.chdir(fixturePath)
  17. const outExists = existsSync(outPath)
  18. if (outExists) {
  19. await move(outPath, cacheOutPath)
  20. }
  21. const { promise } = await init({
  22. directory: process.cwd(),
  23. force: true,
  24. tauriPath: resolve(currentDirName, '../../../../..'),
  25. ci: true
  26. })
  27. await promise
  28. if (outExists) {
  29. await move(cacheOutPath, outPath)
  30. }
  31. process.chdir(tauriFixturePath)
  32. const manifestPath = resolve(tauriFixturePath, 'Cargo.toml')
  33. const manifestFile = readFileSync(manifestPath).toString()
  34. writeFileSync(manifestPath, `workspace = { }\n${manifestFile}`)
  35. const { promise: buildPromise } = await build()
  36. await buildPromise
  37. process.chdir(cwd)
  38. })
  39. })