tauri.spec.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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(
  22. 'Invalid command foo'
  23. )
  24. jest.clearAllMocks()
  25. })
  26. it('will pass on an available command', async () => {
  27. jest.spyOn(console, 'log')
  28. jest.mock('fs')
  29. try {
  30. tauri('init')
  31. } catch {}
  32. expect(console.log.mock.calls[0][0].split('.')[0]).toBe(
  33. '[tauri]: running init'
  34. )
  35. jest.clearAllMocks()
  36. })
  37. it('gets you help', async () => {
  38. jest.spyOn(console, 'log')
  39. const tests = ['--help', '-h', 'invalid command']
  40. for (const test of tests) {
  41. tauri([test])
  42. expect(!!console.log.mock.calls[0][0]).toBe(true)
  43. jest.clearAllMocks()
  44. }
  45. })
  46. it('gets you version', async () => {
  47. jest.spyOn(console, 'log')
  48. const tests = ['--version', '-v']
  49. const version = require('../../../package.json').version
  50. for (const test of tests) {
  51. tauri([test])
  52. expect(console.log.mock.calls[0][0]).toBe(version)
  53. jest.clearAllMocks()
  54. }
  55. })
  56. })