A test runner that combines Mocha testing framework with webpack bundling capabilities for modern JavaScript applications
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The mocha-webpack CLI provides a command-line interface for running tests with webpack precompilation. It maintains compatibility with mocha's CLI options while adding webpack-specific functionality.
mocha-webpack [options] [files...]If no files are specified, defaults to ./test.
Core functionality for test execution and configuration.
# Show help information
--help, -h, -?
# Show version number
--version
# Specify test UI interface (default: bdd)
--ui, -u <interface>
# Valid interfaces: bdd, tdd, exports, qunit
# Watch files for changes and rerun tests
--watch, -w
# Set number of times to retry failed test cases
--retries <count>
# Path to webpack configuration file (default: webpack.config.js)
--webpack-config <path>
# Environment passed to webpack config when it's a function
--webpack-env <env>
# Path to mocha-webpack options file
--opts <path>Control test output formatting and verbosity.
# Force enabling of colors
--colors, -c
# Suppress informational messages
--quiet, -q
# Force interactive mode (default: enabled in terminal)
--interactive
# Enable growl notification support
--growl, -G
# Specify the reporter to use (default: spec)
--reporter, -R <name>
# Reporter-specific options (format: k=v,k2=v2,...)
--reporter-options, -O <options>Detailed test configuration and filtering options.
# Force all tests to take a callback (async) or return a promise
--async-only, -A
# Bail after first test failure
--bail, -b
# Only test files matching pattern (for directory entries)
--glob <pattern>
# Only run tests matching pattern
--grep, -g <pattern>
# Only run tests containing string
--fgrep, -f <string>
# Invert --grep and --fgrep matches
--invert, -i
# Require the given module before running tests
--require, -r <module>
# Can be used multiple times
# Include the given module in test bundle
--include <module>
# Can be used multiple times
# "Slow" test threshold in milliseconds (default: 75ms)
--slow, -s <ms>
# Set test-case timeout in milliseconds (default: 2000ms)
--timeout, -t <ms>
# Check for global variable leaks
--check-leaks
# Display the full stack trace
--full-trace
# Display actual/expected differences inline within each string
--inline-diffs
# Require a clean shutdown of the event loop
--exit
# Wait for async suite definition
--delay
# Include subdirectories when using directory as test entry
--recursive# Run a single test file
mocha-webpack simple.test.js
# Run all tests matching a glob pattern
mocha-webpack "test/**/*.js"
# Run tests in a directory with specific pattern
mocha-webpack --glob "*.test.js" test
# Include subdirectories
mocha-webpack --recursive --glob "*.test.js" test# Watch for changes and rerun tests
mocha-webpack --watch test
# Watch with specific webpack config
mocha-webpack --watch --webpack-config webpack.test.js test
# Watch with custom reporter
mocha-webpack --watch --reporter json test# Run only tests matching a pattern
mocha-webpack --grep "user.*login" test
# Run only tests containing specific string
mocha-webpack --fgrep "authentication" test
# Invert the filter (run tests NOT matching pattern)
mocha-webpack --grep "integration" --invert test# Use custom webpack config
mocha-webpack --webpack-config webpack.test.js test
# Pass environment to webpack config function
mocha-webpack --webpack-config webpack.config.js --webpack-env test test
# Use options file
mocha-webpack --opts test/mocha-webpack.opts
# Require setup modules
mocha-webpack --require babel-register --require ./test/setup.js test
# Include modules in test bundle
mocha-webpack --include ./src/polyfills.js test# Use specific reporter
mocha-webpack --reporter json test
# Reporter with options
mocha-webpack --reporter xunit --reporter-options output=results.xml test
# Quiet mode (suppress info messages)
mocha-webpack --quiet test
# Force colors even when not in TTY
mocha-webpack --colors test
# Enable growl notifications
mocha-webpack --growl test# Set timeout for slow tests
mocha-webpack --timeout 10000 test
# Set slow test threshold
mocha-webpack --slow 200 test
# Retry failed tests
mocha-webpack --retries 3 test
# Bail on first failure
mocha-webpack --bail test
# Force async tests only
mocha-webpack --async-only test
# Use TDD interface instead of BDD
mocha-webpack --ui tdd test
# Enable full stack traces
mocha-webpack --full-trace test
# Check for global leaks
mocha-webpack --check-leaks testBy default, mocha-webpack looks for webpack.config.js in the current directory. You can specify a different file:
mocha-webpack --webpack-config custom-webpack.config.js testIf your webpack config is a function, you can pass an environment:
mocha-webpack --webpack-config webpack.config.js --webpack-env test testUse an options file to avoid repeating command-line arguments:
mocha-webpack --opts test/mocha-webpack.optsExample options file content:
--webpack-config webpack.test.js
--require babel-register
--recursive
--timeout 5000
--reporter spec
test--exit)Mocha-webpack respects standard environment variables:
NODE_ENV: Node.js environmentFORCE_COLOR: Force color outputNO_COLOR: Disable color outputWhen using glob patterns, remember to quote them to prevent shell expansion:
# Correct - quoted pattern
mocha-webpack "test/**/*.test.js"
# Incorrect - shell will expand the pattern
mocha-webpack test/**/*.test.js{
"scripts": {
"test": "mocha-webpack --webpack-config webpack.test.js test",
"test:watch": "npm run test -- --watch",
"test:coverage": "nyc npm run test"
}
}# Basic CI test command
mocha-webpack --reporter json --bail test > test-results.json
# With coverage and JUnit output
nyc --reporter lcov mocha-webpack --reporter xunit --reporter-options output=test-results.xml test