Compile PDF and EPUB files from static Web assets.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.test.ts 2.0 KiB

há 7 meses
há 7 meses
há 7 meses
há 7 meses
há 7 meses
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { describe, it, expect, vi, beforeAll } from 'vitest';
  2. import { createCli } from '../src/cli';
  3. import { addCommands } from '../src/commands';
  4. import { BindServiceImpl, InvalidArgumentTypeError, ArgumentOutOfRangeError } from '../src/modules/bind';
  5. import { Cli } from '../src/packages/cli-wrapper';
  6. vi.mock('process');
  7. describe('cli', () => {
  8. let cli: Cli;
  9. beforeAll(() => {
  10. cli = createCli({
  11. name: 'cli-test',
  12. logger: false,
  13. });
  14. addCommands(cli);
  15. });
  16. it('returns result when successful', async () => {
  17. const response = await cli.test().run(['add', '1', '2']);
  18. expect(response.exitCode).toBe(0);
  19. });
  20. it('returns error when given invalid inputs', async () => {
  21. vi.spyOn(BindServiceImpl.prototype, 'addNumbers').mockImplementationOnce(() => {
  22. throw new InvalidArgumentTypeError('Invalid input');
  23. });
  24. const response = await cli.test().run(['add', '1', '2']);
  25. expect(response.exitCode).toBe(-1);
  26. });
  27. it('returns error when given out-of-range inputs', async () => {
  28. vi.spyOn(BindServiceImpl.prototype, 'addNumbers').mockImplementationOnce(() => {
  29. throw new ArgumentOutOfRangeError('Out of range');
  30. });
  31. const response = await cli.test().run(['add', '1', '2']);
  32. expect(response.exitCode).toBe(-2);
  33. });
  34. it('returns error when an unexpected error occurs', async () => {
  35. vi.spyOn(BindServiceImpl.prototype, 'addNumbers').mockImplementationOnce(() => {
  36. throw new Error('Unexpected error');
  37. });
  38. const response = await cli.test().run(['add', '1', '2']);
  39. expect(response.exitCode).toBe(-3);
  40. });
  41. it('returns error when given insufficient arguments', async () => {
  42. const response = await cli.test().run(['add', '1']);
  43. expect(response.exitCode).toBe(-1);
  44. });
  45. describe('on interactive mode', () => {
  46. it('prompts values for insufficient arguments', async () => {
  47. const response = await cli
  48. .test()
  49. .promptValue({
  50. a: '1',
  51. b: '2',
  52. })
  53. .run(['add', '-i']);
  54. expect(response.exitCode).not.toBe(-1);
  55. });
  56. });
  57. });