CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-karma

Spectacular Test Runner for JavaScript with multi-browser support and plugin architecture.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

cli-interface.mddocs/

CLI Interface

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.

Capabilities

Commands

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 script

Init Command

Interactive 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.ts

The init command will interactively ask about:

  • Testing framework (Jasmine, Mocha, QUnit, etc.)
  • Use of RequireJS
  • Browser selection
  • Source file patterns
  • Test file patterns
  • File watching preferences

Start Command

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 mode

Usage 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 8080

Run Command

Trigger 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 list

Usage 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 --refresh

Stop Command

Stop 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 command

Usage Examples:

# Stop default server
karma stop

# Stop server on custom port
karma stop --port 8080

# Stop with specific config
karma stop my.karma.conf.js

Completion Command

Generate shell completion scripts for bash and zsh.

karma completion

Usage 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/karma

Global Options

Options 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 level

Configuration File Formats

Karma 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 format

Usage 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 .karmarc

Environment Variables

Karma respects several environment variables for default configuration:

PORT                              // Default server port
IP                                // Default hostname
LISTEN_ADDR                       // Default listen address

Usage 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-run

Exit Codes

Karma 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 error

Usage 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

Common Workflows

Development Workflow

# 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

CI/CD Workflow

# 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

Debugging Workflow

# 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

docs

cli-interface.md

configuration.md

index.md

plugin-system.md

programmatic-api.md

tile.json