template.spec.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. import { resolve } from 'node:path'
  5. import {
  6. existsSync,
  7. readFileSync,
  8. writeFileSync,
  9. rmSync,
  10. renameSync
  11. } from 'node:fs'
  12. import cli from '../main.js'
  13. import { describe, it } from 'vitest'
  14. describe('[CLI] @tauri-apps/cli template', () => {
  15. it('init a project and builds it', { timeout: 200000 }, async () => {
  16. const cwd = process.cwd()
  17. const fixturePath = resolve(__dirname, './fixtures/empty')
  18. const tauriFixturePath = resolve(fixturePath, 'src-tauri')
  19. const outPath = resolve(tauriFixturePath, 'target')
  20. const cacheOutPath = resolve(fixturePath, 'target')
  21. process.chdir(fixturePath)
  22. const outExists = existsSync(outPath)
  23. if (outExists) {
  24. if (existsSync(cacheOutPath)) {
  25. rmSync(cacheOutPath, { recursive: true, force: true })
  26. }
  27. renameSync(outPath, cacheOutPath)
  28. }
  29. await cli.run([
  30. 'init',
  31. '--directory',
  32. process.cwd(),
  33. '--force',
  34. '--tauri-path',
  35. resolve(__dirname, '../../..'),
  36. '--before-build-command',
  37. '',
  38. '--before-dev-command',
  39. '',
  40. '--ci'
  41. ])
  42. if (outExists) {
  43. renameSync(cacheOutPath, outPath)
  44. }
  45. process.chdir(tauriFixturePath)
  46. const manifestPath = resolve(tauriFixturePath, 'Cargo.toml')
  47. const manifestFile = readFileSync(manifestPath).toString()
  48. writeFileSync(manifestPath, `workspace = { }\n${manifestFile}`)
  49. const configPath = resolve(tauriFixturePath, 'tauri.conf.json')
  50. const config = readFileSync(configPath).toString()
  51. writeFileSync(configPath, config.replace('com.tauri.dev', 'com.tauri.test'))
  52. await cli.run(['build', '--verbose'])
  53. process.chdir(cwd)
  54. })
  55. })