mocha1
Simple, flexible, fun test framework
Overview
mocha [spec..]
Run tests with Mocha
Commands
mocha inspect [spec..]
|
Run tests with Mocha [default] |
|---|---|
mocha init <path>
|
create a client-side Mocha setup at <path> |
Rules & Behavior
-
--allow-uncaught -
Allow uncaught errors to propagate [boolean]
-
-A, --async-only -
Require all tests to use a callback (async) or return a Promise [boolean]
-
-b, --bail -
Abort ("bail") after first test failure [boolean]
-
--check-leaks -
Check for global variable leaks [boolean]
-
--delay -
Delay initial execution of root suite [boolean]
-
--dry-run -
Report tests without executing them[boolean]
-
--exit -
Force Mocha to quit after tests complete [boolean]
-
--pass-on-failing-test-suite -
Not fail test run if tests were failed [boolean] [default: false]
-
--fail-zero -
Fail test run if no test(s) encountered [boolean]
-
--forbid-only -
Fail if exclusive test(s) encountered [boolean]
-
--forbid-pending -
Fail if pending test(s) encountered[boolean]
-
--global, --globals -
List of allowed global variables [array]
-
-j, --jobs -
Number of concurrent jobs for
--parallel; use 1 to run in serial
-
[number] [default: (number of CPU cores - 1)]
-
-p, --parallel -
Run tests in parallel [boolean]
-
--retries -
Retry failed tests this many times [number]
-
-s, --slow -
Specify "slow" test threshold (in milliseconds) [string] [default: 75]
-
-t, --timeout, --timeouts -
Specify test timeout threshold (in milliseconds) [string] [default: 2000]
-
-u, --ui -
Specify user interface [string] [default: "bdd"]
Reporting & Output
-
-c, --color, --colors -
Force-enable color output [boolean]
-
--diff -
Show diff on failure [boolean] [default: true]
-
--full-trace -
Display full stack traces [boolean]
-
--inline-diffs -
Display actual/expected differences inline within each string [boolean]
-
-R, --reporter -
Specify reporter to use [string] [default: "spec"]
-O,--reporter-option,-
Reporter-specific options
-
--reporter-options -
(<k=v,[k1=v1,..]>) [array]
Configuration
-
--config -
Path to config file [string] [default: (nearest rc file)]
-
-n, --node-option -
Node or V8 option (no leading "--") [array]
-
--package -
Path to package.json for config [string]
File Handling
-
--extension -
File extension(s) to load [array] [default: ["js","cjs","mjs"]]
-
--file -
Specify file(s) to be loaded prior to root suite execution [array] [default: (none)]
-
--ignore, --exclude -
Ignore file(s) or glob pattern(s) [array] [default: (none)]
-
--recursive -
Look for tests in subdirectories [boolean]
-
-r, --require -
Require module [array] [default: (none)]
-
-S, --sort -
Sort test files [boolean]
-
-w, --watch -
Watch files in the current working directory for changes [boolean]
-
--watch-files -
List of paths or globs to watch [array]
-
--watch-ignore -
List of paths or globs to exclude from watching [array] [default: ["node_modules",".git"]]
Test Filters
-
-f, --fgrep -
Only run tests containing this string [string]
-
-g, --grep -
Only run tests matching this string or regexp [string]
-
-i, --invert -
Inverts
--grepand--fgrepmatches [boolean]
Positional Arguments
spec
|
One or more files, directories, or globs to test |
|---|---|
|
[array] [default: ["test"]] |
Other Options
-
-h, --help -
Show usage information & exit [boolean]
-
-V, --version -
Show version number & exit [boolean]
-
--list-interfaces -
List built-in user interfaces & exit [boolean]
-
--list-reporters -
List built-in reporters & exit [boolean]
Mocha Resources
|
Chat: [35mhttps://discord.gg/KeDn2uXhER[39m |
|
|
GitHub: [34mhttps://github.com/mochajs/mocha.git[39m |
|
|
Docs: [33mhttps://mochajs.org/[39m |
Releases
6 releases since Debian 8 (Jessie); the text changed 5 times.
--allow-uncaught since Debian 11 (Bullseye);
--color since Debian 11 (Bullseye);
--config since Debian 11 (Bullseye);
--delay since Debian 11 (Bullseye);
--diff since Debian 11 (Bullseye);
--dry-run since Debian 12 (Bookworm);
--exclude since Debian 11 (Bullseye);
--exit since Debian 11 (Bullseye);
--extension since Debian 11 (Bullseye);
--fail-zero since Debian 12 (Bookworm);
--fgrep since Debian 11 (Bullseye);
--file since Debian 11 (Bullseye);
--forbid-only since Debian 11 (Bullseye);
--forbid-pending since Debian 11 (Bullseye);
--full-trace since Debian 11 (Bullseye);
--global since Debian 11 (Bullseye);
--ignore since Debian 11 (Bullseye);
--jobs since Debian 11 (Bullseye);
--list-interfaces since Debian 11 (Bullseye);
--list-reporters since Debian 11 (Bullseye);
--node-option since Debian 12 (Bookworm);
--package since Debian 11 (Bullseye);
--parallel since Debian 11 (Bullseye);
--pass-on-failing-test-suite since Debian 13 (Trixie);
--reporter-options since Debian 12 (Bookworm);
--retries since Debian 11 (Bullseye);
--timeouts since Debian 11 (Bullseye);
--watch-files since Debian 11 (Bullseye);
--watch-ignore since Debian 11 (Bullseye);
-f since Debian 11 (Bullseye);
-j since Debian 11 (Bullseye);
-n since Debian 12 (Bookworm);
-p since Debian 11 (Bullseye).
--compilers until Debian 10 (Buster);
--debug until Debian 10 (Buster);
--debug-brk until Debian 10 (Buster);
--growl until Debian 11 (Bullseye);
--interfaces until Debian 10 (Buster);
--no-colors until Debian 10 (Buster);
--no-exit until Debian 10 (Buster);
--reporters until Debian 10 (Buster);
-C until Debian 10 (Buster);
-G until Debian 11 (Bullseye);
-O until Debian 11 (Bullseye);
-d until Debian 10 (Buster).