diff --git a/test/core/commands/cd.test.ts b/test/core/commands/cd.test.ts index 7a8055a..8fb0812 100644 --- a/test/core/commands/cd.test.ts +++ b/test/core/commands/cd.test.ts @@ -1,5 +1,6 @@ import { descriptor as cd } from "@core/commands/cd"; -import type { ResultSuccess } from "@core/result"; +import type { PathResolutionError } from "@core/errors"; +import type { ResultError, ResultSuccess } from "@core/result"; import { getCurrentSession } from "@core/session"; import { createInitialShellState, withCwd, type ShellState } from "@core/shell_state"; import type { UserInfo } from "@core/user_info"; @@ -56,9 +57,9 @@ users.set(0, user); const state: ShellState = createInitialShellState(fs, users, user); test("changes cwd to home", () => { - withCwd(state, 2); - const output = cd.fn(state, [], []); - const newState = output.state; + let newState = withCwd(state, 2); + const output = cd.fn(newState, [], []); + newState = output.state; const result = output.result; const session = getCurrentSession(newState); @@ -67,14 +68,14 @@ test("changes cwd to home", () => { expect(session.pwd).toBe(2); }); test("changes cwd to pwd", () => { - withCwd(state, 2); + let newState = withCwd(state, 2); - const output = cd.fn(state, [], ["-"]); - const newState = output.state; + const output = cd.fn(newState, [], ["-"]); + newState = output.state; const result = output.result; const session = getCurrentSession(newState); - expect(session.exitCode).toBe(0); + expect((result as ResultSuccess).exitCode).toBe(0); expect(session.cwd).toBe(0); expect(session.pwd).toBe(2); }); @@ -84,7 +85,7 @@ test("changes cwd to 4", () => { const result = output.result; const session = getCurrentSession(newState); - expect(session.exitCode).toBe(0); + expect((result as ResultSuccess).exitCode).toBe(0); expect(session.cwd).toBe(4); expect(session.pwd).toBe(0); }); @@ -95,18 +96,18 @@ test("returns an error result (tried to enter a non existent location)", () => { const result = output.result; const session = getCurrentSession(newState); - console.log(result); - - expect(session.exitCode).toBe(0); - expect(session.cwd).toBe(4); + expect((result as ResultError).error.exitCode).toBe(64); + expect(session.cwd).toBe(0); expect(session.pwd).toBe(0); }); test("returns an error result (tried to enter a file)", () => { - const newState = cd.fn(state, [], ["/hello.txt"]).state; + const output = cd.fn(state, [], ["/hello.txt"]); + const newState = output.state; + const result = output.result; const session = getCurrentSession(newState); - expect(session.exitCode).toBe(0); - expect(session.cwd).toBe(4); + expect((result as ResultError).error.exitCode).toBe(64); + expect(session.cwd).toBe(0); expect(session.pwd).toBe(0); });