π₯·π» Using Plugins
History
| Version | Changes |
|---|---|
| v4.0.0 (Canary) |
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.
- 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:
setup()is called for each plugin, sequentially in array order.- For each test file:
runner()modifies the spawn command (only the first plugin with arunnerhook 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.
- After all tests complete:
teardown()is called for each plugin, sequentially in array order.
Existing Pluginsβ
- @pokujs/shared-resources β Share state, servers, database connections, and more between parallel test files. See the documentation.
tip
Use definePlugin for type safety when creating plugins, and createReporter for custom output formatting.