terminalDataTransform.test.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { describe, expect, it } from "vitest";
  2. import { normalizePowerShellReadlineRedraw } from "../src/terminal/terminalDataTransform.js";
  3. const ESC = String.fromCharCode(0x1b);
  4. describe("normalizePowerShellReadlineRedraw", () => {
  5. it("should reset PSReadLine redraw black backgrounds to the default background", () => {
  6. const input = `${ESC}[1;29H${ESC}[93mls${ESC}[37m${ESC}[40m ${ESC}[37m${ESC}[40m${ESC}[0m${ESC}[1;33H`;
  7. const result = normalizePowerShellReadlineRedraw(input, "powershell.exe");
  8. expect(result).toBe(`${ESC}[1;29H${ESC}[93mls${ESC}[37m${ESC}[49m ${ESC}[37m${ESC}[49m${ESC}[0m${ESC}[1;33H`);
  9. });
  10. it("should handle PowerShell 7 shell names", () => {
  11. const input = `${ESC}[1;29H${ESC}[37m${ESC}[40m `;
  12. expect(normalizePowerShellReadlineRedraw(input, "C:\\Program Files\\PowerShell\\7\\pwsh.exe")).toBe(
  13. `${ESC}[1;29H${ESC}[37m${ESC}[49m `,
  14. );
  15. });
  16. it("should leave non-PowerShell data unchanged", () => {
  17. const input = `${ESC}[1;29H${ESC}[37m${ESC}[40m `;
  18. expect(normalizePowerShellReadlineRedraw(input, "bash")).toBe(input);
  19. });
  20. it("should leave command output with newlines unchanged", () => {
  21. const input = `${ESC}[37m${ESC}[40moutput${ESC}[0m\n`;
  22. expect(normalizePowerShellReadlineRedraw(input, "powershell.exe")).toBe(input);
  23. });
  24. });