| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A comprehensive testing framework for Codify plugins. This package provides utilities to test the complete lifecycle of Codify plugins including initialization, validation, planning, applying, importing, and destroying resources.
npm install --save-dev @codifycli/plugin-testimport { PluginTester } from '@codifycli/plugin-test';
import { ResourceConfig, ResourceOs } from '@codifycli/schemas';
// Define the resources you want to test
const configs: ResourceConfig[] = [
{
type: 'homebrew',
os: [ResourceOs.MACOS]
}
];
// Run a full lifecycle test
await PluginTester.fullTest('/path/to/your/plugin/index.js', configs, {
validatePlan: (plans) => {
// Assert that the plan is correct
expect(plans[0].operation).toBe('create');
},
validateApply: (plans) => {
// Verify the resource was created successfully
}
});The main API for testing plugins.
Runs a complete plugin lifecycle test including validate, plan, apply, import, modify (optional), and destroy.
Parameters:
Example:
await PluginTester.fullTest('/path/to/plugin', configs, {
validatePlan: (plans) => {
expect(plans).toHaveLength(1);
expect(plans[0].operation).toBe('create');
},
testModify: {
modifiedConfigs: [
{ type: 'my-resource', newParam: 'updated-value' }
],
validateModify: (plans) => {
expect(plans[0].operation).toBe('modify');
}
}
});Tests only the installation flow (validate → plan → apply).
Parameters:
Example:
await PluginTester.install('/path/to/plugin', [
{ type: 'homebrew', os: [ResourceOs.MACOS] }
]);Tests the destroy operation for resources.
Parameters:
Example:
await PluginTester.uninstall('/path/to/plugin', configs, {
validateDestroy: (plans) => {
expect(plans[0].operation).toBe('destroy');
}
});Low-level API for managing individual plugin processes.
Example:
import { PluginProcess } from '@codifycli/plugin-test';
const plugin = new PluginProcess('/path/to/plugin');
try {
// Initialize the plugin
const initResult = await plugin.initialize();
// Validate configs
const validateResult = await plugin.validate({
configs: [{ core: { type: 'my-resource' }, parameters: {} }]
});
// Create a plan
const plan = await plugin.plan({
core: { type: 'my-resource' },
desired: { param: 'value' },
isStateful: false,
state: undefined
});
// Apply the plan
await plugin.apply({ planId: plan.planId });
} finally {
plugin.kill();
}Utility functions for common testing scenarios.
Sends an IPC message to a plugin process and waits for the response.
Execute a command interactively in a PTY (for testing).
Parameters:
Example:
import { testSpawn } from '@codifycli/plugin-test';
const result = await testSpawn('which brew');
if (result.status === SpawnStatus.SUCCESS) {
console.log('Homebrew is installed at:', result.data);
}Tests automatically filter by OS using the os field:
const configs = [
{ type: 'homebrew', os: [ResourceOs.MACOS] }, // Only runs on macOS
{ type: 'apt', os: [ResourceOs.LINUX] }, // Only runs on Linux
{ type: 'git' } // Runs on all platforms
];
await PluginTester.fullTest('/path/to/plugin', configs);Test that your plugin properly handles resource modifications:
await PluginTester.fullTest('/path/to/plugin', [
{ type: 'my-resource', version: '1.0.0' }
], {
testModify: {
modifiedConfigs: [
{ type: 'my-resource', version: '2.0.0' }
],
validateModify: (plans) => {
expect(plans[0].operation).toBe('modify');
expect(plans[0].changes).toContain('version');
}
}
});Test multiple resources in a single test run:
const configs = [
{ type: 'homebrew', name: 'homebrew-main' },
{ type: 'homebrew-package', name: 'wget', formula: 'wget' },
{ type: 'homebrew-package', name: 'curl', formula: 'curl' }
];
await PluginTester.fullTest('/path/to/plugin', configs, {
validateApply: (plans) => {
expect(plans).toHaveLength(3);
}
});Ensure prerequisites are installed before running tests:
import { TestUtils, PluginTester } from '@codifycli/plugin-test';
// Ensure Homebrew is installed before testing Homebrew packages
await TestUtils.ensureHomebrewInstalledOnMacOs('/path/to/core-plugin');
await PluginTester.fullTest('/path/to/plugin', [
{ type: 'homebrew-package', formula: 'wget' }
]);npm testnpx vitest src/test-utils.test.tsnpm run prepublishOnlyThe testing framework spawns your plugin as a child process (using Node's fork()) and communicates with it via IPC messages, exactly how the Codify CLI does. This ensures your tests accurately reflect real-world plugin behavior.
When your plugin requests elevated permissions or needs to execute commands, the framework intercepts these requests and handles them automatically, allowing you to test plugin behavior in a controlled environment.
ISC
| Back | FazBrowse Home | New Git URL |