Skip to content

👁️ Interactive watch mode support for the Mocha test framework.

Notifications You must be signed in to change notification settings

m-sureshraj/mocha-watch-typeahead

Repository files navigation

mocha-watch-typeahead

npm

The mocha-watch-typeahead is an attempt to add interactive watch mode support for the Mocha test framework. Besides rerunning tests on file changes, it provides a feature to filter tests by file name.

mocha-watch-typeahead in action

Install

npm install [email protected] mocha-watch-typeahead -D --save-exact

The mocha-watch-typeahead uses some internal methods from [email protected], So at the moment it directly depends on [email protected] (the latest version at the time of writing).

Usage

First, you have to configure the mocha. For that, please refer to the getting start guide. Then add the following npm script to the package.json.

{
  "scripts": {
    "test-watch": "mocha-watch"
  }
}

Think mocha-watch as an alias for command mocha. You can pass all valid mocha options to the mocha-watch as well. The only difference is, it always runs in watch mode.

npm run test-watch

Based on your mocha configuration, it collects all the matched test files and prompts autocomplete to filter tests by file name. You can filter tests by glob pattern as well.

filter mode

Note, the above list won't display files that are loaded through the --file option.

Temporary limitations

The mocha-watch-typeahead has a few known temporary limitations at the moment.

  • It is only tested with the latest version of mocha v8.1.3. Probably it won't work with the older versions of mocha.
  • It only supports serial run, although mocha's built-in watch mode has support for parallel run.
  • It doesn't validate the passed options.

If you encounter the following warning message in watch mode, you can safely ignore it. It's a known mocha issue.

MaxListenersExceededWarning: Possible EventEmitter memory leak detected.
11 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit

Future improvements

  • Watch mode feedback speed can be increased by not watching non-filter test files.
  • Resolve the temporary limitations.

Credits

License

MIT © Sureshraj