MOCHA(1)

πŸ’– MOCHA πŸ’–

okay bestie, sit DOWN, because we're talking about mocha β€” the simple, flexible, fun test framework (that's literally its whole brand, and honestly? it ate). this is the MOCHA(1) page, User Commands territory, and i'm gonna walk you through every single flag like we're texting at 2am. no cap, every option is coming with us. πŸŽ€


✨ NAME ✨

mocha β€” simple, flexible, fun test framework πŸ’…


🌸 DESCRIPTION 🌸

so the whole vibe is:

mocha [spec..]

Run tests with Mocha. that's the assignment. that's it. 😌

πŸ¦‹ Commands πŸ¦‹

  • mocha [spec..] β€” Run tests with Mocha. this one is the [default], the main character, the one everybody shows up for.
  • mocha inspect [spec..] β€” Run tests with Mocha, but in inspector mode. (yes it's also listed as [default] up there with the plain form β€” the manpage says so, we don't argue with the manpage πŸ’€)
  • mocha init <path> β€” create a client-side Mocha setup at <path>. new folder, new setup, new era. ✨

πŸ‘‘ Rules & Behavior πŸ‘‘

  • --allow-uncaught β€” allow uncaught errors to propagate. let 'em run loose. [boolean]
  • -A, --async-only β€” every test has to use a callback (async) or return a Promise. no sneaky sync tests allowed, bestie. [boolean]
  • -b, --bail β€” abort ("bail") after the first test failure. one L and we're OUT. [boolean]
  • --check-leaks β€” check for global variable leaks. who left that variable lying around?? πŸ™ˆ [boolean]
  • --delay β€” delay the initial execution of the root suite. a lil dramatic pause. [boolean]
  • --dry-run β€” report tests without actually executing them. window shopping, but for tests. [boolean]
  • --exit β€” Force Mocha to quit after tests complete. bye, we're leaving. [boolean]
  • --pass-on-failing-test-suite β€” Not fail test run if tests were failed. [boolean] [default: false]
  • --fail-hook-affected-tests β€” Report tests as failed when affected by hook failures (before/beforeEach). yep, if the hook fumbled it, the tests feel it too. [boolean]
  • --fail-zero β€” Fail test run if no test(s) encountered. zero tests = zero chill. [boolean]
  • --forbid-only β€” Fail if exclusive test(s) encountered. no only-ing your way through, diva. [boolean]
  • --forbid-pending β€” Fail if pending test(s) encountered. no ghost tests. [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)] β€” so if your laptop has 9 cores, congrats, you get 8. 🀠
  • -p, --parallel β€” Run tests in parallel. multitasking queen behavior. [boolean]
  • --posix-exit-codes β€” Use POSIX and UNIX shell exit codes as Mocha's return value. [boolean]
  • --retries β€” Retry failed tests this many times. we try again, bestie, we always try again. [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. yes we're doing rainbows, deal. 🎨 [boolean]
  • --diff β€” Show diff on failure. [boolean] [default: true]
  • --full-trace β€” Display full stack traces. the WHOLE story, no skimming. [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-options β€” Reporter-specific options, in the format <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. dig deep. [boolean]
  • -r, --require β€” Require module. [array] [default: (none)]
  • -S, --sort β€” Sort test files. alphabetize besties. [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 --grep and --fgrep matches. you said what you said, now we do the opposite. [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 πŸ’–

go be nosy, there's lore:


and that's the whole page, bestie. you now know mocha better than most people know their own phone passcode. iykyk. 🫢

~ cute sign-off ~ this was mocha version 11.8.0, dated August 2026, and yeah, it lives at MOCHA(1). mwah. πŸ’…βœ¨πŸŒΈ


πŸ“¦ where this page comes from