taskStatusPrinter.test.ts 993 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { describe, expect, it, vi } from "vitest";
  2. const { oraMock } = vi.hoisted(() => ({
  3. oraMock: vi.fn(),
  4. }));
  5. vi.mock("ora", () => ({
  6. default: oraMock,
  7. }));
  8. import { createStatusPrinter } from "../../../scripts/release-it/task-status-printer.mjs";
  9. describe("createStatusPrinter", () => {
  10. it("只输出任务名和状态", () => {
  11. const api = {
  12. start: vi.fn(),
  13. succeed: vi.fn(),
  14. fail: vi.fn(),
  15. };
  16. oraMock.mockReturnValue(api);
  17. const printer = createStatusPrinter("改写 changelog");
  18. printer.start("开始");
  19. printer.succeed("完成");
  20. printer.fail("失败");
  21. expect(oraMock).toHaveBeenCalledWith(
  22. expect.objectContaining({
  23. isEnabled: true,
  24. stream: process.stderr,
  25. }),
  26. );
  27. expect(api.start).toHaveBeenCalledWith("改写 changelog 开始");
  28. expect(api.succeed).toHaveBeenCalledWith("改写 changelog 完成");
  29. expect(api.fail).toHaveBeenCalledWith("改写 changelog 失败");
  30. });
  31. });