日本語

@vimee/testkit

Testing utilities for vimee

Ergonomic testing utilities for vimee. Write Vim operation tests with a natural, chainable syntax.

Installation

npm install -D @vimee/testkit

Usage

import { vim } from "@vimee/testkit";
import { expect, test } from "vitest";

test("dd deletes the current line", () => {
  const v = vim("line 1\nline 2\nline 3", { cursor: [1, 0] });
  v.type("dd");

  expect(v.content()).toBe("line 1\nline 3");
  expect(v.cursor()).toEqual({ line: 1, col: 0 });
});

API

vim(text, options?)

Creates a test harness:

const v = vim("Hello, World!", {
  cursor: [0, 5],      // [line, col] 0-based
  mode: "normal",       // starting mode
  indentStyle: "space", // "space" | "tab"
  indentWidth: 2,
});

VimHarness methods

MethodReturnDescription
.type(keys)VimHarnessSend key sequence (chainable)
.content()stringGet buffer content
.cursor()CursorPositionGet cursor position (0-based)
.mode()VimModeGet current Vim mode
.lines()string[]Get all lines
.line(index)stringGet line at index (0-based)
.register(name)stringGet register content
.actions()VimAction[]Actions from last .type()
.allActions()VimAction[]All actions since creation
.statusMessage()stringGet status bar message
.raw(){ ctx, buffer }Access raw VimContext and TextBuffer

Key notation

v.type("dd");           // delete line
v.type("<Esc>");        // Escape
v.type("<C-d>");        // Ctrl+D
v.type("<CR>");         // Enter
v.type("ciw");          // change inner word
v.type("dw");           // delete word

Chaining

vim("hello world")
  .type("w")        // move to "world"
  .type("dw");      // delete "world"

// Verify
expect(vim("hello world").type("wdw").content()).toBe("hello ");