tauri.spec.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const { tauri } = require('bin/tauri')
  2. describe('[CLI] tauri.js', () => {
  3. it('displays a help message', async () => {
  4. jest.spyOn(console, 'log')
  5. jest.spyOn(process, 'exit').mockImplementation(() => true)
  6. tauri('help')
  7. console.log(process.exit.mock.calls[0][0])
  8. expect(process.exit.mock.calls[0][0]).toBe(0)
  9. expect(!!console.log.mock.calls[0][0]).toBe(true)
  10. tauri('--help')
  11. expect(!!console.log.mock.calls[2][0]).toBe(true)
  12. tauri('-h')
  13. expect(!!console.log.mock.calls[3][0]).toBe(true)
  14. tauri(['help'])
  15. expect(!!console.log.mock.calls[4][0]).toBe(true)
  16. jest.clearAllMocks()
  17. })
  18. it('will not run an unavailable command', async () => {
  19. jest.spyOn(console, 'log')
  20. tauri('foo')
  21. expect(console.log.mock.calls[0][0].split('.')[0]).toBe('Invalid command foo')
  22. jest.clearAllMocks()
  23. })
  24. it('will pass on an available command', async () => {
  25. jest.spyOn(console, 'log')
  26. jest.mock('fs')
  27. try {
  28. tauri('init')
  29. } catch {}
  30. expect(console.log.mock.calls[0][0].split('.')[0]).toBe('[tauri]: running init')
  31. jest.clearAllMocks()
  32. })
  33. it('gets you help', async () => {
  34. jest.spyOn(console, 'log')
  35. const tests = ['--help', '-h', 'invalid command']
  36. for (const test of tests) {
  37. tauri([test])
  38. expect(!!console.log.mock.calls[0][0]).toBe(true)
  39. jest.clearAllMocks()
  40. }
  41. })
  42. it('gets you version', async () => {
  43. jest.spyOn(console, 'log')
  44. const tests = ['--version', '-v']
  45. const version = require('../../../package.json').version
  46. for (const test of tests) {
  47. tauri([test])
  48. expect(console.log.mock.calls[0][0]).toBe(version)
  49. jest.clearAllMocks()
  50. }
  51. })
  52. })