Spectacular Test Runner for JavaScript with multi-browser support and plugin architecture.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Karma's command-line interface provides comprehensive tools for project initialization, test execution, and server management. Designed for both interactive development and CI/CD integration.
Karma provides several commands for different aspects of test management.
// Available CLI commands
karma init [configFile] // Initialize new configuration file
karma start [configFile] // Start server and/or run tests
karma run [configFile] // Trigger test run on existing server
karma stop [configFile] // Stop running server
karma completion // Generate shell completion scriptInteractive configuration file generator that detects project setup and installs required plugins.
karma init [configFile]Options:
configFile - Optional path for config file (default: karma.conf.js)Usage Examples:
# Initialize with default name
karma init
# Initialize with custom name
karma init my-karma.conf.js
# Initialize in TypeScript
karma init karma.conf.tsThe init command will interactively ask about:
Start Karma server and optionally run tests. Primary command for both development and CI scenarios.
karma start [configFile] [options]Key Options:
--port <number> // Server port (default: 9876)
--auto-watch / --no-auto-watch // Enable/disable file watching
--single-run / --no-single-run // Run once and exit vs continuous
--browsers <list> // Comma-separated browser list
--reporters <list> // Comma-separated reporter list
--log-level <level> // disable|error|warn|info|debug
--colors / --no-colors // Enable/disable colored output
--fail-on-empty-test-suite // Fail if no tests found
--fail-on-failing-test-suite // Fail on any test failures
--grep <pattern> // Filter tests by pattern
--coverage // Enable coverage reporting
--watch // Force enable file watching
--singleRun // Force single run modeUsage Examples:
# Start with default config
karma start
# Start with custom config
karma start my.karma.conf.js
# Single run for CI
karma start --single-run --browsers Chrome
# Development mode with watching
karma start --auto-watch --browsers Chrome,Firefox
# With specific reporters
karma start --reporters progress,coverage --single-run
# Debug mode
karma start --log-level debug --browsers Chrome
# Custom port
karma start --port 8080Trigger test execution on an already running Karma server. Useful for external build tools and IDEs.
karma run [configFile] [options]Options:
--port <number> // Server port to connect to
--hostname <string> // Server hostname
--help // Show help
--removed-files <list> // Files that were removed
--added-files <list> // Files that were added
--changed-files <list> // Files that were changed
--refresh // Force refresh file listUsage Examples:
# Run tests on default server
karma run
# Run on custom port
karma run --port 8080
# Run with file change information
karma run --changed-files src/app.js,src/util.js
# Force file list refresh
karma run --refreshStop a running Karma server gracefully.
karma stop [configFile] [options]Options:
--port <number> // Server port to stop
--hostname <string> // Server hostname
--log-level <level> // Log level for stop commandUsage Examples:
# Stop default server
karma stop
# Stop server on custom port
karma stop --port 8080
# Stop with specific config
karma stop my.karma.conf.jsGenerate shell completion scripts for bash and zsh.
karma completionUsage Examples:
# Generate bash completion
karma completion >> ~/.bashrc
# Generate zsh completion
karma completion >> ~/.zshrc
# Or save to completion directory
karma completion > /usr/local/etc/bash_completion.d/karmaOptions available across all commands:
--help // Show command help
--version // Show Karma version
--config <file> // Configuration file path
--colors / --no-colors // Enable/disable colored output
--log-level <level> // Set logging levelKarma supports multiple configuration file formats:
// Supported configuration files
karma.conf.js // JavaScript (most common)
karma.conf.ts // TypeScript (requires ts-node)
karma.conf.coffee // CoffeeScript (requires coffeescript)
karma.conf.ls // LiveScript (requires LiveScript)
.karmarc // JSON formatUsage Examples:
# JavaScript config
karma start karma.conf.js
# TypeScript config
karma start karma.conf.ts
# CoffeeScript config
karma start karma.conf.coffee
# JSON config
karma start .karmarcKarma respects several environment variables for default configuration:
PORT // Default server port
IP // Default hostname
LISTEN_ADDR // Default listen addressUsage Examples:
# Set default port
export PORT=8080
karma start
# Set default hostname
export IP=0.0.0.0
karma start
# Use in CI
PORT=9999 karma start --single-runKarma CLI commands return specific exit codes for scripting and CI integration:
0 // Success - all tests passed
1 // Failure - tests failed or error occurred
2 // Configuration errorUsage Examples:
# Check exit code in scripts
karma start --single-run
if [ $? -eq 0 ]; then
echo "Tests passed"
else
echo "Tests failed"
exit 1
fi
# Use in CI pipelines
karma start --single-run --browsers ChromeHeadless || exit 1# Initial setup
karma init
npm install --save-dev karma-chrome-launcher karma-jasmine
# Start development server with watching
karma start --auto-watch --browsers Chrome
# In another terminal, trigger runs
karma run# Headless browser testing
karma start --single-run --browsers ChromeHeadless
# With coverage
karma start --single-run --browsers ChromeHeadless --reporters progress,coverage
# Multiple browsers
karma start --single-run --browsers Chrome,Firefox,Safari# Debug mode with detailed logging
karma start --log-level debug --browsers Chrome
# Keep browser open for debugging
karma start --single-run=false --auto-watch=false --browsers Chrome