continue-custom/extensions/cli/src/ui/__tests__
Nate 34d59b8530 fix: fix flaky TUIChat special characters test in remote mode
In remote mode, the component connects to a non-existent server, so
typed text may not appear in the rendered frame. Only assert text
content in local mode; the crash-safety check still runs in both modes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 19:52:22 -08:00
..
mocks chore: mcp 1.24.0 (#8974) 2025-12-04 12:58:28 -08:00
BottomStatusBarCtrlC.test.tsx feat: cli fetch tool to use fetchUrlContent from core 2025-09-09 20:25:35 -07:00
CtrlC.test.tsx fix linting 2025-08-24 14:30:31 -07:00
CtrlCInputClearing.test.tsx fix: lint 2025-09-03 17:15:39 -07:00
FreeTrialTransitionUI.test.tsx chore: refactor cn box styling, mcp selector, update clearer arrow icon 2025-08-23 10:41:44 -07:00
FreeTrialTransitionUI.urlHandling.test.tsx chore: run prettier --write on cli 2025-08-20 17:57:35 -07:00
mockRemoteServer.ts fix: use Session type for cn serve / remote 2025-08-28 17:59:35 -07:00
README.md Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
TUIChat.actionStatus.test.tsx feat: improve compaction UI, show compaction message as status message 2025-09-10 21:38:36 -07:00
TUIChat.basic.test.tsx chore: run prettier --write on cli 2025-08-20 17:57:35 -07:00
TUIChat.compactionCancellation.test.tsx /compact use ActionStatus and support esc to cancel 2025-09-10 21:38:36 -07:00
TUIChat.dualModeHelper.tsx Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
TUIChat.editMessage.test.tsx refactor waitForCondition into file 2025-12-03 18:14:27 +05:30
TUIChat.fileSearch.test.tsx update lastFrame 2025-12-03 18:41:19 +05:30
TUIChat.freeTrialTransition.test.tsx chore: run prettier --write on cli 2025-08-20 17:57:35 -07:00
TUIChat.input.test.tsx fix: fix flaky TUIChat special characters test in remote mode 2026-02-17 19:52:22 -08:00
TUIChat.interruption.minimal.test.tsx fix tests 2025-09-08 21:48:47 -07:00
TUIChat.messages.test.tsx chore: run prettier --write on cli 2025-08-20 17:57:35 -07:00
TUIChat.permissionPolicyReload.test.tsx fix: tests, formatting, linting 2025-10-03 18:04:39 -07:00
TUIChat.planModeBug.test.tsx fix(cli): exclude ask first tools in headless (#8416) 2025-10-23 19:12:47 -07:00
TUIChat.remote.test.tsx chore: run prettier --write on cli 2025-08-20 17:57:35 -07:00
TUIChat.setup.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
TUIChat.slashCommands.test.tsx Fix flaky slash command test on Windows 2025-12-10 23:20:29 +00:00
TUIChat.streamStopping.test.tsx chore: format 2025-08-25 10:44:06 -07:00
TUIChat.testHelper.ts refactor waitForCondition into file 2025-12-03 18:14:27 +05:30
TUIChat.toolDisplay.test.tsx chore: run prettier --write on cli 2025-08-20 17:57:35 -07:00
TUIChat.toolPermission.test.tsx chore: format 2025-08-25 10:44:06 -07:00
UserInput.missingFile.test.tsx feat: revamp efficient file search and support fuzzy matching 2025-09-17 13:43:03 -07:00

TUI Testing Framework

This directory contains a comprehensive testing framework for the Continue CLI's Terminal User Interface (TUI) that supports running tests in both normal (local) and remote modes.

Overview

The testing framework ensures that the TUI behaves consistently whether running locally or connected to a remote cn serve instance. Most tests run in both modes automatically, verifying feature parity between local and remote operation.

Key Components

1. Mock Remote Server (mockRemoteServer.ts)

A mock Express server that simulates the cn serve endpoints:

  • GET /state - Returns current chat state
  • POST /message - Receives user messages and can simulate responses

2. Test Helper (TUIChat.testHelper.ts)

Provides utilities for writing tests that work in both modes:

  • runTest() - Run a single test in specified mode(s)
  • runTestSuite() - Run a test suite in specified mode(s)
  • Helper functions for common operations

3. Test Files

  • TUIChat.basic.test.tsx - Basic UI and layout tests
  • TUIChat.messages.test.tsx - Message handling tests
  • TUIChat.remote.test.tsx - Remote-specific behavior tests
  • Additional test files for other features...

Writing Tests

Basic Test (runs in both modes)

import { runTest } from "./TUIChat.testHelper.js";

runTest("my test name", async (ctx) => {
  const { renderResult, mode, server } = ctx;

  // Your test code here
  const frame = renderResult.lastFrame();
  expect(frame).toContain("Expected content");

  // Mode-specific logic if needed
  if (mode === "remote" && server) {
    // Remote-specific assertions
  }
});

Test Suite (runs all tests in both modes)

import { runTestSuite } from "./TUIChat.testHelper.js";

runTestSuite("My Test Suite", () => {
  runTest("test 1", async (ctx) => {
    // Test code
  });

  runTest("test 2", async (ctx) => {
    // Test code
  });
});

Mode-Specific Tests

// Remote-only test
runTest(
  "remote-specific behavior",
  async (ctx) => {
    // This only runs in remote mode
  },
  { mode: "remote" },
);

// Normal-only test
runTest(
  "local-specific behavior",
  async (ctx) => {
    // This only runs in normal mode
  },
  { mode: "normal" },
);

Helper Functions

sendMessage(ctx, message, waitTime?)

Sends a message and waits for it to be processed:

await sendMessage(ctx, "Hello world");

waitForServerState(server, predicate, timeout?)

Waits for server state to match a condition (remote mode only):

await waitForServerState(server, (state) => state.messages.length > 0, 5000);

expectRemoteMode(frame) / expectNormalMode(frame)

Verify mode-specific UI indicators:

if (mode === "remote") {
  expectRemoteMode(frame);
} else {
  expectNormalMode(frame);
}

Server Setup

For tests that need specific server behavior:

runTest(
  "test with custom server",
  async (ctx) => {
    // Test code
  },
  {
    serverSetup: (server) => {
      server.onMessage((msg) => {
        // Custom response logic
        server.simulateResponse(`Echo: ${msg}`);
      });
    },
  },
);

Running Tests

# Run all tests
npm test

# Run specific test file
npm test TUIChat.basic.test.tsx

# Run with coverage
npm test -- --coverage

Best Practices

  1. Write mode-agnostic tests by default - Most functionality should work the same in both modes
  2. Use helper functions - They handle mode-specific details automatically
  3. Test server state in remote mode - Verify both UI and server state for comprehensive coverage
  4. Handle async operations properly - Use appropriate wait times and state checks
  5. Clean up resources - The framework handles server lifecycle automatically

Debugging

  • Tests output the current mode in brackets: [NORMAL MODE] or [REMOTE MODE]
  • Server state can be inspected with server.getState()
  • Use console.log(renderResult.lastFrame()) to see the current UI state
  • Mock server runs on a random port to avoid conflicts