tauri.spec.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { jest } from '@jest/globals'
  2. import tauri from 'bin/tauri'
  3. import { createRequire } from 'module'
  4. const require = createRequire(import.meta.url)
  5. const { version } = require('../../../package.json')
  6. describe('[CLI] cli.js', () => {
  7. it('displays a help message', async () => {
  8. jest.spyOn(console, 'log')
  9. jest.spyOn(process, 'exit').mockImplementation(() => true)
  10. tauri('help')
  11. console.log(process.exit.mock.calls[0][0])
  12. expect(process.exit.mock.calls[0][0]).toBe(0)
  13. expect(!!console.log.mock.calls[0][0]).toBe(true)
  14. tauri('--help')
  15. expect(!!console.log.mock.calls[2][0]).toBe(true)
  16. tauri('-h')
  17. expect(!!console.log.mock.calls[3][0]).toBe(true)
  18. tauri(['help'])
  19. expect(!!console.log.mock.calls[4][0]).toBe(true)
  20. jest.clearAllMocks()
  21. })
  22. it('gets you help', async () => {
  23. jest.spyOn(console, 'log')
  24. const tests = ['--help', '-h']
  25. for (const test of tests) {
  26. tauri([test])
  27. expect(!!console.log.mock.calls[0][0]).toBe(true)
  28. jest.clearAllMocks()
  29. }
  30. })
  31. it('gets you version', async () => {
  32. jest.spyOn(console, 'log')
  33. const tests = ['--version', '-v']
  34. for (const test of tests) {
  35. tauri([test])
  36. expect(console.log.mock.calls[0][0]).toBe(version)
  37. jest.clearAllMocks()
  38. }
  39. })
  40. })