CLI for Oblique Strategies.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3 KiB

  1. import wrapAnsi from 'wrap-ansi';
  2. import {
  3. afterAll,
  4. beforeAll,
  5. describe,
  6. expect,
  7. it, SpyInstanceFn,
  8. vi,
  9. } from 'vitest';
  10. import centered from '../centered';
  11. vi.mock('wrap-ansi');
  12. describe('centered', () => {
  13. let log: SpyInstanceFn<[], void>;
  14. let defaultConsole: typeof console;
  15. beforeAll(() => {
  16. defaultConsole = console;
  17. log = vi.fn();
  18. global.console = {
  19. log,
  20. } as unknown as typeof console;
  21. });
  22. afterAll(() => {
  23. global.console = defaultConsole;
  24. });
  25. it('calls wrap and ensures console has an assumed width of 80 text columns', async () => {
  26. const defaultColumns = process.stdout.columns;
  27. process.stdout.columns = undefined as unknown as typeof process.stdout.columns;
  28. await centered()('foo\n-italic');
  29. expect(wrapAnsi).toBeCalledWith('foo\n-italic', 80, { hard: true, trim: true });
  30. process.stdout.columns = defaultColumns;
  31. });
  32. it('calls wrap and respects current text column count', async () => {
  33. const defaultColumns = process.stdout.columns;
  34. process.stdout.columns = 420;
  35. await centered()('foo\n-italic');
  36. expect(wrapAnsi).toBeCalledWith('foo\n-italic', 420, { hard: true, trim: true });
  37. process.stdout.columns = defaultColumns;
  38. });
  39. it('calls the console output function', async () => {
  40. await centered()('foo\n-italic');
  41. expect(log).toBeCalled();
  42. });
  43. });