tauri.spec.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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('gets you help', async () => {
  27. jest.spyOn(console, 'log')
  28. const tests = ['--help', '-h', 'invalid command']
  29. for (const test of tests) {
  30. tauri([test])
  31. expect(!!console.log.mock.calls[0][0]).toBe(true)
  32. jest.clearAllMocks()
  33. }
  34. })
  35. it('gets you version', async () => {
  36. jest.spyOn(console, 'log')
  37. const tests = ['--version', '-v']
  38. const version = require('../../../package.json').version
  39. for (const test of tests) {
  40. tauri([test])
  41. expect(console.log.mock.calls[0][0]).toBe(version)
  42. jest.clearAllMocks()
  43. }
  44. })
  45. })