This is an example plugin demonstrating how to extend the Vizzly CLI with custom commands.
This example plugin adds several commands to demonstrate different plugin capabilities:
vizzly hello- Simple greeting commandvizzly greet <name>- Command with arguments and optionsvizzly check-api- Command that accesses Vizzly servicesvizzly list-screenshots- Command with file system operations
Since this is an example, you can use it locally without publishing:
Add to your vizzly.config.js:
export default {
plugins: [
'./examples/custom-plugin/plugin.js'
]
};# From the vizzly-cli root
npm link
# Create symlink for the plugin
cd examples/custom-plugin
npm link @vizzly-testing/cli
cd ../..
mkdir -p node_modules/@vizzly-testing
ln -s ../../examples/custom-plugin node_modules/@vizzly-testing/example-pluginAfter installation, run:
# See the new commands in help
vizzly --help
# Try the commands
vizzly hello
vizzly greet "World" --loud
vizzly check-api
vizzly list-screenshotsThe plugin exports an object with:
name- Unique identifier for the pluginversion- Plugin version (optional but recommended)register(program, context)- Function called during CLI initialization
The register function receives:
program- Commander.js program instance for adding commandscontext- Object containing:config- Merged Vizzly configurationoutput- Output utilities for consistent CLI outputservices- Service container (see below)
The services object provides stable APIs for plugins:
let { git, testRunner, serverManager } = services;
// Git detection (v0.25.0+) - handles CI environments correctly
let gitInfo = await git.detect({ buildPrefix: 'MyPlugin' });
// Returns: { branch, commit, message, prNumber, buildName }
// Build lifecycle
let buildId = await testRunner.createBuild(options);
await testRunner.finalizeBuild(buildId, wait, success, executionTime);
// Server control
await serverManager.start(buildId, tddMode, setBaseline);
await serverManager.stop();- Create a new directory for your plugin
- Create
package.jsonwithvizzly.pluginfield:
{
"name": "@vizzly-testing/my-plugin",
"vizzly": {
"plugin": "./plugin.js"
}
}- Create
plugin.jswith your plugin logic:
export default {
name: 'my-plugin',
version: '1.0.0',
register(program, { config, logger, services }) {
program
.command('my-command')
.description('My custom command')
.action(() => {
logger.info('Running my command!');
});
}
};- Test locally using
vizzly.config.js:
export default {
plugins: ['./path/to/your/plugin.js']
};- Publish to npm under
@vizzly-testing/*scope for auto-discovery