WRITE UNIT TESTS!!!

first async command working, no unit tests done AGAING
This commit is contained in:
2026-08-23 06:39:37 +02:00
parent e313aa5b9d
commit 268729bb62
18 changed files with 331 additions and 93 deletions
+26 -10
View File
@@ -1,3 +1,4 @@
import type { CommandIO } from "@core/command_io";
import { descriptor as cd } from "@core/commands/cd";
import type { ResultError, ResultSuccess } from "@core/result";
import type { UserInfo } from "@core/session_manager";
@@ -44,6 +45,21 @@ const testTree: FixtureNode = {
const fs = buildTestFS(testTree);
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 users: Map<number, UserInfo> = new Map();
const user: UserInfo = {
username: "root",
@@ -56,9 +72,9 @@ users.set(0, user);
const state: ShellState = createInitialShellState(fs, users, user);
test("changes cwd to home", () => {
test("changes cwd to home", async () => {
let newState = withCwd(state, 2);
const output = cd.fn(newState, [], []);
const output = await cd.fn(io, newState, [], []);
newState = output.state;
const result = output.result;
const session = getCurrentSession(newState);
@@ -67,10 +83,10 @@ test("changes cwd to home", () => {
expect(session.cwd).toBe(0);
expect(session.pwd).toBe(2);
});
test("changes cwd to pwd", () => {
test("changes cwd to pwd", async () => {
let newState = withCwd(state, 2);
const output = cd.fn(newState, [], ["-"]);
const output = await cd.fn(io, newState, [], ["-"]);
newState = output.state;
const result = output.result;
const session = getCurrentSession(newState);
@@ -79,8 +95,8 @@ test("changes cwd to pwd", () => {
expect(session.cwd).toBe(0);
expect(session.pwd).toBe(2);
});
test("changes cwd to 4", () => {
const output = cd.fn(state, [], ["/sub/bye"]);
test("changes cwd to 4", async () => {
const output = await cd.fn(io, state, [], ["/sub/bye"]);
const newState = output.state;
const result = output.result;
const session = getCurrentSession(newState);
@@ -90,8 +106,8 @@ test("changes cwd to 4", () => {
expect(session.pwd).toBe(0);
});
test("returns an error result (tried to enter a non existent location)", () => {
const output = cd.fn(state, [], ["/not/real"]);
test("returns an error result (tried to enter a non existent location)", async () => {
const output = await cd.fn(io, state, [], ["/not/real"]);
const newState = output.state;
const result = output.result;
const session = getCurrentSession(newState);
@@ -101,8 +117,8 @@ test("returns an error result (tried to enter a non existent location)", () => {
expect(session.pwd).toBe(0);
});
test("returns an error result (tried to enter a file)", () => {
const output = cd.fn(state, [], ["/hello.txt"]);
test("returns an error result (tried to enter a file)", async () => {
const output = await cd.fn(io, state, [], ["/hello.txt"]);
const newState = output.state;
const result = output.result;
const session = getCurrentSession(newState);