|
|
@@ -0,0 +1,35 @@
|
|
|
+// npx vitest run src/integrations/terminal/__tests__/ExecaTerminal.spec.ts
|
|
|
+
|
|
|
+import { vi, describe, it, expect } from "vitest"
|
|
|
+
|
|
|
+import { RooTerminalCallbacks } from "../types"
|
|
|
+import { ExecaTerminal } from "../ExecaTerminal"
|
|
|
+
|
|
|
+describe("ExecaTerminal", () => {
|
|
|
+ it("should run terminal commands and collect output", async () => {
|
|
|
+ // TODO: Run the equivalent test for Windows.
|
|
|
+ if (process.platform === "win32") {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const terminal = new ExecaTerminal(1, "/tmp")
|
|
|
+ let result
|
|
|
+
|
|
|
+ const callbacks: RooTerminalCallbacks = {
|
|
|
+ onLine: vi.fn(),
|
|
|
+ onCompleted: (output) => (result = output),
|
|
|
+ onShellExecutionStarted: vi.fn(),
|
|
|
+ onShellExecutionComplete: vi.fn(),
|
|
|
+ }
|
|
|
+
|
|
|
+ const subprocess = terminal.runCommand("ls -al", callbacks)
|
|
|
+ await subprocess
|
|
|
+
|
|
|
+ expect(callbacks.onLine).toHaveBeenCalled()
|
|
|
+ expect(callbacks.onShellExecutionStarted).toHaveBeenCalled()
|
|
|
+ expect(callbacks.onShellExecutionComplete).toHaveBeenCalled()
|
|
|
+
|
|
|
+ expect(result).toBeTypeOf("string")
|
|
|
+ expect(result).toContain("total")
|
|
|
+ })
|
|
|
+})
|