mocha

The classic, battle-tested JavaScript test framework for Node.js and the browser, built around flexible async testing and pluggable reporters.

Tool
npm
v12.0.3
22,910 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
95 /100 Excellent
Development Activity 100
Maintenance 96
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
81 /100 Excellent
Architecture 88
Code Quality 92
Innovation 62
Learning Curve 80

Mocha is one of the longest-running and most-depended-upon JavaScript test frameworks, running tests serially or in parallel in Node.js and in real browsers. Rather than bundling assertions, it hands developers a minimal but complete test-running core — suite/test registration, hooks, timeouts, and a reporter pipeline — and lets teams bring their own assertion library (Chai, Node’s built-in assert, or anything else) and mocking tools.

Its defining trait is interface pluggability: BDD (describe/it), TDD (suite/test), QUnit-style, and exports-style test authoring are all first-class, selectable per run via --ui. A large built-in reporter set (spec, dot, nyan, tap, xunit, JSON, markdown, and more) covers CI and terminal output needs without extra dependencies, and a documented reporter API lets teams write their own.

Mocha is used both as a globally-invoked CLI (mocha) and as a programmatic API (require('mocha')), and it explicitly supports being loaded in-browser via a bundled mocha.js/mocha.css pair for running the same suites against real DOM environments. Its own test suite doubles as a live demonstration of the framework, since Mocha tests itself using its own binary.

What You Get

  • A test runner CLI (mocha) plus a programmatic Mocha class API for embedding test runs in custom tooling
  • Four built-in test interfaces (BDD, TDD, QUnit, exports) selectable per run, each mapping to familiar describe/it, suite/test, or plain-object registration styles
  • before/after/beforeEach/afterEach hooks at both suite and root level, including async hook support with configurable timeouts
  • A dozen-plus built-in reporters (spec, dot, nyan, tap, xunit, json, json-stream, markdown, html, landing, progress, min, doc, github-actions) selectable via --reporter
  • Parallel test execution across worker processes (--parallel) with a buffered runner and serializer for cross-process reporting
  • Native file watching (--watch) built on chokidar, glob-based test file discovery, and a .mocharc configuration file convention
  • First-class browser support: a bundled mocha.js/mocha.css pair and browser-entry.js build target for running suites directly in a browser page

Common Use Cases

  • Node.js unit and integration testing - teams pair Mocha’s runner with an assertion library like Chai to unit-test backend code and CLIs, driven by npm test
  • CI pipelines needing machine-readable output - --reporter xunit or --reporter json feeds JUnit-style or JSON results into CI dashboards and coverage tools like nyc
  • Browser-based test suites - libraries and frontend code load mocha.js directly in a test HTML page (or via Playwright/webpack-driven browser tests) to validate DOM-dependent behavior
  • Large test suites needing wall-clock speedups - --parallel distributes spec files across a worker pool instead of running everything in one process
  • Teams migrating between BDD/TDD styles - the pluggable interface system lets a codebase mix or transition between describe/it and suite/test conventions without switching test runners

Under The Hood

Architecture

Execution starts at bin/mocha.js, a thin wrapper that separates Node engine flags from Mocha’s own options before handing off to lib/cli/cli.js’s main(), which constructs a Mocha instance (lib/mocha.cjs) modeled as an explicit finite-state machine (init → running → referencesCleaned → disposed). Test files register suites and tests onto a Suite tree (lib/suite.js); the selected interface module (lib/interfaces/{bdd,tdd,qunit,exports}.js) is what actually binds the global describe/it-style functions to that tree. The Runner (lib/runner.js, the largest file in the codebase) walks the suite tree and drives execution of Runnable subclasses (Hook, Test), emitting a stream of lifecycle events that every reporter (lib/reporters/*, all extending a shared Base class) subscribes to independently. Parallel mode layers lib/nodejs/parallel-buffered-runner.cjs, buffered-worker-pool.cjs, and a serializer.js on top of this to fan test files out across workerpool-managed child processes and reassemble a single ordered reporter stream in the main process.

Tech Stack

Mocha ships as a native ESM package ("type": "module") with a deliberately small runtime dependency set: chokidar for file watching, glob/minimatch for test-file discovery, workerpool for parallel execution, js-yaml for .mocharc parsing, plus debug, picocolors, and serialize-javascript for cross-process result serialization. The browser build (mocha.js/mocha.mjs/mocha.css) is produced via Rollup from the same core library. TypeScript is present only as a type-checking layer over plain JavaScript (tsconfig.json with allowJs/noEmit, backed by types.d.ts JSDoc typedefs) — there is no compiled TypeScript source. Its own test suite is exercised through itself (bin/mocha.js), plus Playwright and webpack for browser-compatibility runs, with nyc handling coverage.

Code Quality

The repository carries an extensive test suite — 135+ .spec.cjs/.spec.js files spanning unit, integration, interface, reporter, and edge-case (test/only/) coverage. Errors are raised through explicit factory functions in lib/errors.js and a dedicated error-constants.js rather than ad hoc throws, giving consistent, typed-shaped error objects across the codebase. Linting runs via ESLint (eslint-plugin-n plus the recommended JS ruleset) with zero tolerance for warnings (--max-warnings 0), Prettier formatting is enforced as a separate CI job, and GitHub Actions runs the full lint/unit/browser matrix on every change — a mature, CI-gated quality bar for a project of this age.

API Design The defining developer-experience choice is pluggability at every layer: four interchangeable test interfaces (BDD, TDD, QUnit, exports-style) select how tests are authored, while Mocha deliberately ships no assertion library, letting Chai, Node’s built-in assert, or anything else plug in unmodified. The same core suite/runner logic powers both a Node CLI and a browser bundle without a separate codebase, and reporters are a well-documented, uniformly-structured extension point (a shared Base class every built-in reporter extends). None of this is radical by today’s standards — it’s the convention this generation of test runners has largely converged on — but Mocha’s own long-standing pluggable design is one of the reasons that convention exists.

Used by 30 apps in this directory

Rust
68%
Other

GitButler

AI Development · Developer Tools · Devops

21,841

Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.

View details
89
Repo Health
84
Technical
66
Dependency
Built with
Rust 68%
TypeScript 20%
Updated today
TypeScript
83%
Apache 2.0

Grist

Databases · No Code Platforms

11,991

A modern relational spreadsheet that combines Python-powered formulas, drag-and-drop dashboards, and granular access controls in a self-hostable, SQLite-backed data platform.

View details
91
Repo Health
93
Technical
63
Dependency
Built with
TypeScript 83%
Python 11%
Updated yesterday
TypeScript
68%
MIT

Hoppscotch

Developer Tools

80,676

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
62
Dependency
Built with
TypeScript 68%
Vue 24%
Updated yesterday
TypeScript
73%
Apache 2.0

Jitsi Meet

Collaboration · Team Chat · Video Conferencing

30,130

Open-source, end-to-end encrypted video conferencing you can self-host or embed into any web or mobile app.

View details
96
Repo Health
85
Technical
67
Dependency
Built with
TypeScript 73%
Lua 11%
JavaScript 10%
Updated yesterday
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,338

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 98%
Updated today
PHP
78%
GPL 3.0

matomo

Analytics

21,976

Open-source, privacy-first web and app analytics that puts you in complete control of your data.

View details
95
Repo Health
82
Technical
62
Dependency
Built with
PHP 78%
Updated yesterday
TypeScript
51%
Other

Mattermost

Collaboration · Devops · Team Chat

39,418

Open core, self-hosted team collaboration with chat, AI agents, voice calling, and deep DevOps integrations — all under your control.

View details
96
Repo Health
87
Technical
65
Dependency
Built with
TypeScript 51%
Go 40%
Updated today
TypeScript
95%
MIT

melty

AI Code Assistants · Code Editors · Developer Tools

5,462

The AI code editor where every chat message is a git commit you can revert, branch, or squash

View details
35
Repo Health
75
Technical
67
Dependency
Built with
TypeScript 95%
Updated 1 years ago
Clojure
57%
Other

Metabase

Analytics

49,827

The open-source BI platform that lets anyone ask questions and build dashboards without writing SQL — with an embedded analytics SDK and AI-powered query assistant included.

View details
95
Repo Health
84
Technical
62
Dependency
Built with
Clojure 57%
TypeScript 38%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers