Repterm
Plugins

Plugin API Reference

Complete API reference for plugin-related functions and types.

definePlugin()

Define a new plugin with a name and setup function.

import { definePlugin } from 'repterm';

const myPlugin = definePlugin('name', (ctx) => ({
  methods: { /* ... */ },
  context: { /* ... */ },
  hooks: { /* ... */ },
}));

Parameters

ParameterTypeDescription
namestringUnique plugin identifier
setup(ctx) => PluginDefinitionSetup function receiving context, returning methods, context, and hooks

Return Type: PluginDefinition

FieldTypeDescription
methodsobjectCustom methods accessible via ctx.plugins.<name>
contextobjectProperties injected into the test context
hooksPluginHooksOptional lifecycle hooks

defineConfig()

Create a configuration object with plugins.

import { defineConfig } from 'repterm';

const config = defineConfig({
  plugins: [plugin1, plugin2] as const,
});

The as const assertion ensures full type inference for plugin methods and context.

createTestWithPlugins()

Create a test function with plugin injection.

import { createTestWithPlugins } from 'repterm';

const test = createTestWithPlugins(config);

test('name', async (ctx) => {
  ctx.plugins.pluginName.method();
  ctx.contextProperty;
});

describeWithPlugins()

Create a describe block with plugin injection.

import { describeWithPlugins } from 'repterm';

describeWithPlugins(config, 'suite name', () => {
  // tests inside have access to plugins
});

PluginHooks

HookSignatureDescription
beforeTest(ctx) => Promise<void> | voidRuns before each test
afterTest(ctx, error?) => Promise<void> | voidRuns after each test
beforeCommand(command: string) => string | Promise<string>Transform command before execution
afterOutput(output: string) => string | Promise<string>Transform output after capture

repterm-api Package

For third-party plugin development, repterm-api provides a minimal API surface:

bun add -d repterm-api

Exported Types

TypeDescription
PluginContextContext passed to plugin setup functions
MinimalTerminalMinimal terminal interface (run, snapshot, isPtyMode)
MinimalTestContextMinimal test context with terminal
PluginHooks<TContext>Lifecycle hooks interface
MatcherResultResult type for custom matchers (pass, message, actual, expected)