Pular para o conteúdo principal
Versão: v4.x.x

🥷🏻 Using Plugins

History
VersionChanges
v3.0.3-canary.68e71482
Introduce the Plugin System.
2Stable

Extend Poku's behavior with plugins — hook into the test lifecycle, customize how test files are spawned, enable inter-process communication, and more.

What Can Plugins Do?

  • Run setup logic before the test suite begins.
  • Intercept or customize file discovery.
  • Run teardown logic after the test suite completes.
  • Modify the command used to spawn each test file process.
  • Enable IPC channels between Poku and test processes.
  • React to each test process being spawned.
  • Customize output with custom reporters.

Quick Start

Add plugins to your Poku configuration file via the plugins option:

// poku.config.ts
import { defineConfig } from 'poku';
import { myPlugin } from './my-plugin';

export default defineConfig({
plugins: [myPlugin],
});

Plugin Lifecycle

Plugins are executed in the following order:

  1. setup() is called for each plugin, sequentially in array order.
  2. discoverFiles() from the first plugin that defines it determines the test files (if no plugin defines it, Poku scans the configured directories).
  3. For each test file:
    • runner() modifies the spawn command (only the first plugin with a runner hook is used).
    • The process is spawned — with an IPC channel if any plugin sets ipc: true.
    • onTestProcess() is called for every plugin that defines it.
  4. After all tests complete: teardown() is called for each plugin, sequentially in array order.

Existing Plugins

dica

Use definePlugin for type safety when creating plugins, and createReporter for custom output formatting.