Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
487 changes: 487 additions & 0 deletions .github/skills/tui-test/SKILL.md

Large diffs are not rendered by default.

476 changes: 225 additions & 251 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"wrap-ansi": "^8.1.0"
},
"devDependencies": {
"@microsoft/shell-use": "^0.0.1-beta.6",
"@microsoft/tui-test": "^0.1.0-beta.2",
"@tsconfig/node18": "^18.2.2",
"@types/color-convert": "^2.0.3",
"@types/jest": "^29.5.5",
Expand Down
8 changes: 4 additions & 4 deletions src/tests/ui/autocomplete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// Licensed under the MIT License.

import { jest } from "@jest/globals";
import { terminalSnapshot } from "@microsoft/shell-use/test";
import type { ShellUse } from "@microsoft/shell-use/test";
import { terminalSnapshot } from "@microsoft/tui-test/test";
import type { TuiTest } from "@microsoft/tui-test/test";
import { closeSession, configs, expectPrompt, returnChar, startSession } from "./helpers";

const accent = "#7d56f4";

jest.retryTimes(2, { logErrorsBeforeRetry: true });

describe("resize recovery", () => {
let terminal: ShellUse;
let terminal: TuiTest;
beforeEach(async () => {
terminal = await startSession({ label: "bash-resize", shell: "bash", env: { BASH_SILENCE_DEPRECATION_WARNING: "1" } }, ["-T", "-s", "bash"]);
});
Expand Down Expand Up @@ -47,7 +47,7 @@ configs.map((config) => {
const rc = returnChar(config.shell);
const args = ["-V", "-T", "-s", config.shell];
describe(`[${config.label}]`, () => {
let terminal: ShellUse;
let terminal: TuiTest;
beforeEach(async () => {
terminal = await startSession(config, args);
});
Expand Down
43 changes: 15 additions & 28 deletions src/tests/ui/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import os from "node:os";
import path from "node:path";
import fs from "node:fs";
import url from "node:url";
import { ShellUse } from "@microsoft/shell-use";
import { trackTerminal, untrackTerminal } from "@microsoft/shell-use/test";
import type { Shell } from "@microsoft/shell-use";
import type { TuiTest } from "@microsoft/tui-test";
import { createTerminal, untrackTerminal } from "@microsoft/tui-test/test";
import type { Shell } from "@microsoft/tui-test";

export type ShellConfig = {
label: string;
Expand Down Expand Up @@ -40,34 +40,30 @@ const idleTimeout = 15_000;
const promptTimeout = 20_000;
const timeouts = { text: expectTextTimeout, idle: idleTimeout };

export const expectPrompt = async (terminal: ShellUse, timeout = promptTimeout): Promise<void> => {
export const expectPrompt = async (terminal: TuiTest, timeout = promptTimeout): Promise<void> => {
await terminal.expectText("> ", { timeout });
await terminal.waitIdle();
};

export const closeSession = async (terminal: ShellUse | undefined): Promise<void> => {
export const closeSession = async (terminal: TuiTest | undefined): Promise<void> => {
if (terminal) {
await terminal.closeQuiet();
untrackTerminal(terminal);
}
};

const baseEnv = { ISTERM: "0", ISTERM_TESTING: "0" };
const ephemeralTerminal = (): ShellUse => {
const terminal = ShellUse.ephemeral(undefined, { timeouts });
trackTerminal(terminal);
return terminal;
};

export const startSession = async (config: ShellConfig, args: string[], cols = 80, rows = 30): Promise<ShellUse> => {
const terminal = ephemeralTerminal();
export const startSession = async (config: ShellConfig, args: string[], cols = 80, rows = 30): Promise<TuiTest> => {
const terminal = await createTerminal({
program: ["node", buildEntry, ...args],
cols,
rows,
env: { ...baseEnv, ...config.env },
timeouts,
retries: 2,
});
try {
await terminal.run("node", [buildEntry, ...args], {
cols,
rows,
env: { ...baseEnv, ...config.env },
retries: 2,
});
await expectPrompt(terminal);
return terminal;
} catch (error) {
Expand All @@ -76,13 +72,4 @@ export const startSession = async (config: ShellConfig, args: string[], cols = 8
}
};

export const startShell = async (shell: Shell): Promise<ShellUse> => {
const terminal = ephemeralTerminal();
try {
await terminal.open({ shell, env: baseEnv, retries: 2 });
return terminal;
} catch (error) {
await closeSession(terminal);
throw error;
}
};
export const startShell = async (shell: Shell): Promise<TuiTest> => createTerminal({ shell, env: baseEnv, timeouts, retries: 2 });
8 changes: 4 additions & 4 deletions src/tests/ui/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import os from "node:os";
import { jest } from "@jest/globals";
import type { ShellUse } from "@microsoft/shell-use/test";
import type { Shell } from "@microsoft/shell-use";
import type { TuiTest } from "@microsoft/tui-test/test";
import type { Shell } from "@microsoft/tui-test";
import { closeSession, startSession, startShell } from "./helpers";

const shell: Shell = os.platform() == "darwin" ? "zsh" : os.platform() == "linux" ? "bash" : "powershell";
Expand All @@ -13,7 +13,7 @@ jest.retryTimes(2, { logErrorsBeforeRetry: true });

describe("status checks", () => {
describe("inside inshellisense session", () => {
let terminal: ShellUse;
let terminal: TuiTest;
beforeEach(async () => {
terminal = await startSession({ label: "status", shell }, ["-T", "-s", shell]);
});
Expand All @@ -28,7 +28,7 @@ describe("status checks", () => {
});

describe("outside inshellisense session", () => {
let terminal: ShellUse;
let terminal: TuiTest;
beforeEach(async () => {
terminal = await startShell(shell);
});
Expand Down
Loading