Full-featured CLI with extensive configuration options for all aspects of test execution. The command-line interface provides comprehensive control over test execution, reporting, and analysis.
Main command-line interface for executing tests with comprehensive configuration options.
/**
* Main CLI entry point that parses options and executes tests
* @returns Promise resolving to exit code information
*/
cli.run(): Promise<{ code: number }>;# Run all tests in test directory
lab
# Run specific test file
lab test/user.test.js
# Run multiple test files
lab test/user.test.js test/auth.test.js
# Run tests in specific directory
lab test/integration/Control how lab finds and loads test files:
# Run tests without recursive directory search
lab --flat
# Use custom test file pattern
lab --pattern "*.spec.js"
# Load tests from custom path
lab --path src/tests/
# Run specific test IDs (use lab -dv to see test IDs)
lab --id 1,3,5-8
# Run tests matching grep pattern
lab --grep "user authentication"# Set test timeout (individual tests)
lab --timeout 5000
# Set context timeout (setup/teardown hooks)
lab --context-timeout 10000
# Set environment variable
lab --environment production
# Dry run (show tests without executing)
lab --dry
# Enable verbose output
lab --progress 2
# Shuffle test execution order
lab --shuffle
# Use specific random seed for shuffling
lab --seed 12345
# Exit on first failure
lab --bail
# Set default plan threshold
lab --default-plan-threshold 1
# Set retry count for failing tests
lab --retries 3
# Silent skipped tests
lab --silent-skips# Enable code coverage
lab --coverage
# Set coverage threshold (percentage)
lab --threshold 90
# Set coverage path
lab --coverage-path ./src
# Exclude files from coverage
lab --coverage-exclude node_modules,test
# Include all files in coverage report
lab --coverage-all
# Flat coverage (no recursive search)
lab --coverage-flat
# Coverage file pattern
lab --coverage-pattern "*.js"
# Custom coverage predicates
lab --coverage-predicates '{"deep-equal": true, "throws": true}'# Use specific reporter
lab --reporter console
lab --reporter html
lab --reporter json
lab --reporter tap
lab --reporter lcov
lab --reporter clover
lab --reporter junit
# Use multiple reporters
lab --reporter console,html
# Output to file
lab --output test-results.html
# Multiple outputs for multiple reporters
lab --reporter console,json --output "",results.json
# Enable/disable colors
lab --colors
lab --no-colors# Enable linting
lab --lint
# Use custom linter
lab --linter eslint
# Apply linter fixes automatically
lab --lint-fix
# Set linting error threshold
lab --lint-errors-threshold 0
# Set linting warning threshold
lab --lint-warnings-threshold 5
# Pass options to linter (JSON string)
lab --lint-options '{"env": {"node": true}}'# Enable leak detection (default)
lab --leaks
# Disable leak detection
lab --no-leaks
# Ignore specific globals
lab --globals myGlobal,anotherGlobal
# Ignore symbols (use string representation)
lab --globals "Symbol(special),myVar"# Enable TypeScript support
lab --typescript
# Validate TypeScript types
lab --types
# Specify types test file
lab --types-test ./test/api-types.ts
# Use with path mapping
lab --typescript --require 'tsconfig-paths/register'
# Enable source maps
lab --sourcemaps# Use custom transformers
lab --transform babel-transformer.js
# Multiple transformers
lab --transform babel.js,typescript.js# Start with Node.js debugger
lab --inspect
# Start with debugger and break immediately
lab --inspect-brk
# Debug on custom port
lab --inspect=9229# Specify assertion library
lab --assert @hapi/code
# Disable assertion library
lab --assert falseLab supports configuration files to avoid repetitive command-line options:
// .labrc.json
{
"coverage": true,
"threshold": 90,
"reporter": "html",
"output": "coverage.html",
"lint": true,
"leaks": true,
"globals": ["myGlobal", "DEBUG_MODE"],
"timeout": 5000,
"typescript": true
}// .labrc.js
module.exports = {
coverage: true,
threshold: 90,
reporter: ['console', 'html'],
output: ['', 'coverage.html'],
lint: true,
'lint-options': JSON.stringify({
env: { node: true },
rules: { 'no-console': 'warn' }
}),
leaks: true,
globals: process.env.NODE_ENV === 'development' ? ['DEBUG'] : [],
timeout: 5000
};Full TypeScript interface definition for all CLI options:
interface CliOptions {
/** Assertion library module path */
assert?: string;
/** Exit with non-zero code on first failure */
bail?: boolean;
/** Enable/disable color output */
colors?: boolean;
/** Timeout for setup/teardown hooks (ms) */
'context-timeout'?: number;
/** Enable code coverage analysis */
coverage?: boolean;
/** Include all files in coverage report */
'coverage-all'?: boolean;
/** Exclude patterns from coverage */
'coverage-exclude'?: string[];
/** Prevent recursive coverage inclusion */
'coverage-flat'?: boolean;
/** Set coverage analysis path */
'coverage-path'?: string;
/** Coverage predicates configuration */
'coverage-predicates'?: { [key: string]: boolean };
/** File pattern for coverage analysis */
coveragePattern?: RegExp;
/** Minimum plan threshold for tests */
'default-plan-threshold'?: number;
/** Dry run mode (skip execution) */
dry?: boolean;
/** NODE_ENV value for tests */
environment?: string;
/** Number of retries for failing tests */
retries?: number;
/** Prevent recursive test file loading */
flat?: boolean;
/** Global variables to ignore in leak detection */
globals?: string[];
/** Pattern for filtering tests */
grep?: string;
/** Specific test IDs to run */
id?: number[];
/** Start Node.js debugger */
inspect?: boolean;
/** Enable global leak detection */
leaks?: boolean;
/** Enable code linting */
lint?: boolean;
/** Linter executable path */
linter?: string;
/** Apply linter fixes automatically */
'lint-fix'?: boolean;
/** JSON string of linter options */
'lint-options'?: string;
/** Maximum linting errors threshold */
'lint-errors-threshold'?: number;
/** Maximum linting warnings threshold */
'lint-warnings-threshold'?: number;
/** Output file path(s) */
output?: string | string[];
/** Test file paths */
path?: string[];
/** File pattern for test discovery */
pattern?: RegExp;
/** Output verbosity (0: none, 1: normal, 2: verbose) */
progress?: number;
/** Reporter type(s) */
reporter?: string | string[];
/** Random seed for shuffling */
seed?: string;
/** Shuffle test execution order */
shuffle?: boolean;
/** Silence skipped tests */
'silent-skips'?: boolean;
/** Enable source map support */
sourcemaps?: boolean;
/** Coverage threshold percentage */
threshold?: number;
/** Test timeout in milliseconds */
timeout?: number;
/** Source transformers */
transform?: Transformer[];
/** Enable TypeScript support */
typescript?: boolean;
/** Enable type validation */
types?: boolean;
/** TypeScript definitions test file */
'types-test'?: string;
}
interface Transformer {
/** File extension to transform */
ext: string;
/** Transform function */
transform(content: string, filename: string): string;
}Typical development commands for different scenarios:
# Quick test run during development
lab
# Run with coverage for code review
lab --coverage --threshold 80 --reporter html --output coverage.html
# Debug specific failing tests
lab --grep "user authentication" --inspect
# CI/CD pipeline command
lab --coverage --threshold 90 --reporter json --output results.json --lint --leaks
# TypeScript project testing
lab --typescript --types --coverage --threshold 85Complete CI/CD setup examples:
# GitHub Actions / Jenkins
lab --coverage --threshold 90 --reporter lcov --output coverage.lcov --lint --bail
# With multiple output formats
lab --coverage --threshold 90 --reporter console,junit,lcov --output "",junit.xml,coverage.lcov
# Full analysis pipeline
lab --coverage --threshold 90 --leaks --lint --types --typescript --reporter console,json --output "",ci-results.jsonDifferent project types and their typical lab configurations:
# API/Backend project
lab --coverage --threshold 85 --leaks --lint --reporter console,json
# Frontend/Browser project (if applicable)
lab --coverage --threshold 75 --no-leaks --lint --reporter html
# Library/Package project
lab --coverage --threshold 95 --types --typescript --lint --leaks --reporter console,lcov
# Microservice with integration tests
lab --timeout 10000 --coverage --threshold 80 --reporter tap --bailLab uses standard exit codes to indicate test results:
These exit codes enable proper CI/CD pipeline integration and automation scripting.