Files
termos/test/core/commands/echo.test.ts
ChaosMaker 1ee2a2fe7a - Old tests fixed
- Added a static Fixuture class for test mockups
2026-08-28 16:52:59 +02:00

34 lines
1.0 KiB
TypeScript

import type { CommandIO } from "@core/command_io";
import { descriptor as echo } from "@core/commands/echo";
import type { ResultSuccess } from "@core/result";
import { type ShellState } from "@core/shell_state";
import { Fixture } from "@tests/helpers/state_fixture";
import { expect, test } from "vitest";
const stdout: Uint8Array[] = [];
const stderr: Uint8Array[] = [];
const io: CommandIO = {
writeStdout: (data: Uint8Array) => {
stdout.push(data);
},
writeStderr: (data: Uint8Array) => {
stderr.push(data);
},
getSignal: () => {
return new Promise(() => {});
},
};
const state: ShellState = Fixture.State;
test("returns a Result of type success", async () => {
const output = await echo.fn(io, state, [], ["hello", "world"]);
const string = new TextDecoder().decode(stdout[0]);
expect(output.result.type).toBe("success");
expect((output.result as ResultSuccess).exitCode).toBe(0);
// Fix: added a newline character
expect(string).toEqual("hello world\n");
});