Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

docs: modernize DEVELOPMENT.md for new contributors (#5865)

Mostafa Nazari5122ad74d717
diff --git a/.github/DEVELOPMENT.md b/.github/DEVELOPMENT.md
index 2a79a392..74d93a12 100644
--- a/.github/DEVELOPMENT.md
+++ b/.github/DEVELOPMENT.md
@@ -5,43 +5,66 @@ If you are having trouble, don't be afraid to [ask for help](./CONTRIBUTING.md#
## Prerequisites
-- [Install Node.js 14 LTS or newer with npm@7+](https://nodejs.org/en/download).
+- [Node.js](https://nodejs.org/en/download) `^20.19.0 || >=22.12.0` (Node >=22 LTS recommended).
- If you're new to installing Node, a tool like [nvm](https://github.com/nvm-sh/nvm#install-script) can help you manage multiple version installations.
-- You will need [Google Chrome](https://www.google.com/chrome) to run browser-based tests locally.
+- npm (do not use yarn or pnpm for this repository).
+- [Google Chrome](https://www.google.com/chrome) is required to run browser tests locally.
## Setup
-1. Follow [Github's documentation](https://help.github.com/articles/fork-a-repo) on setting up Git, forking, and cloning.
-1. Execute `npm install` to install the development dependencies.
- - Do not use `yarn install` or `pnpm install`.
+1. Follow [GitHub's documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) on setting up Git, forking, and cloning.
+1. Run `npm install` from the repository root to install dependencies.
- Some optional dependencies may fail; you can safely ignore these unless you are trying to build the documentation.
- If you're sick of seeing the failures, run `npm install --ignore-scripts`.
-## Developing Mocha
+## Running Tests
-When you contribute to Mocha, you will probably want to try to run your changes on the test suite of another project. You can (and should) run the test suite of Mocha itself before committing, but also confirming that your changes give the expected result on another project.
+You can (and should) run the test suite of Mocha itself before committing, and ideally confirm that your changes give the expected result on another project's test suite too.
-For example, [WebSocket.io](https://github.com/LearnBoost/websocket.io/):
+To run all code validations (linting, testing in both Node.js and browsers), run:
- $ git clone https://github.com/LearnBoost/websocket.io.git
+```sh
+npm test
+```
-Retrieve websocket.io's dependencies, which will include the stable version of Mocha:
+For faster feedback during development, you can directly use targeted commands:
- $ cd websocket.io/
- $ npm install
+| Command | What it runs |
+| ------------------------------- | ------------------------------------------------- |
+| `npm run test-smoke` | Quick smoke test to confirm Mocha boots |
+| `npm run test-node:unit` | Unit tests |
+| `npm run test-node:integration` | Integration tests (includes build) |
+| `npm run test-node:interfaces` | Interface tests (BDD, TDD, QUnit, exports) |
+| `npm run test-node:reporters` | Reporter tests |
+| `npm run test-browser` | Browser tests via Karma + Chrome (includes build) |
+| `npm run tsc` | TypeScript type checking |
+| `npm run lint` | Linting and formatting checks |
-Replace the Mocha dependency by the current git repository:
+A typical edit-test cycle uses `--watch` to re-run tests automatically as you change files:
- $ cd node_modules/
- $ mv mocha/ mocha.save
- $ git clone https://github.com/mochajs/mocha.git
+```sh
+npx mocha --watch test/unit/
+```
-Install Mocha's dependencies for the development version:
+If your change touches browser code or reporters, also run:
- $ cd mocha
- $ npm install
+```sh
+npm run test-browser
+```
-Run websocket.io's test suite using the development version you just installed:
+## Building
- $ cd ../..
- $ ./node_modules/.bin/mocha
+Mocha's browser bundle (`mocha.js`) is generated by Rollup. You normally don't need to build manually — `npm run test-browser` handles it. If you do need to build:
+
+```sh
+npm run clean
+npm run build
+```
+
+> **Note:** Do not edit `mocha.js` or `mocha.js.map` directly — they are generated files.
+
+## Troubleshooting
+
+- **`npm test` fails right away with lint errors:** Run `npm run format:fix` to auto-fix formatting, then re-run.
+- **Browser tests fail with "Cannot find module 'mocha'":** Run `npm run build` first. Browser tests require the generated bundle.
+- **Chrome not found during browser tests:** Install [Google Chrome](https://www.google.com/chrome). Karma looks for it automatically.