Emacs mode for running mocha tests
Emacs Lisp Gherkin JavaScript Makefile
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
features update cucumber tests for error from mocha-walk-up-to-it Jul 10, 2017
sample-project Use regexp special char in testcase description Oct 13, 2017
test [feat] add support for indium debugger Nov 22, 2017
.gitignore Ignore sandbox May 23, 2016
.travis.yml [tests] update travis to run on 25.1 and 25.2 with node 8.9 Nov 22, 2017
Cask Add s package to test environment May 23, 2016
LICENSE Initial commit Jan 24, 2016
Makefile Add an integration test for testing a mocha project. May 15, 2016
README.md [docs] update realgud link Nov 22, 2017
mocha.el [cleanup] Don't kill buffer explicitly in mocha-run Jan 13, 2018
mocha.png

README.md

Melpa Status Melpa Stable Status Build Status

mocha.el

Emacs helpers for running mocha tests. It lets you test an entire project, a particular file, or a particular test in that file.

Mocha.el in Action

Contents

Installation

The package can be installed via MELPA. The package name is mocha.

Configuration

Everything is set up right now to be configured via customize or per project in a .dir-locals.el file. You can find all options by looking at the mocha group in the customize interface. Below is an example configuration:

((nil . (
            (mocha-which-node . "/Users/ajs/.nvm/versions/node/v4.2.2/bin/node")
            (mocha-command . "node_modules/.bin/mocha")
            (mocha-environment-variables . "NODE_ENV=test")
            (mocha-options . "--recursive --reporter dot -t 5000")
            (mocha-project-test-directory . "test")
            (mocha-reporter . "spec")
            )))

Running tests

In order to run tests there are three functions exposed:

  1. mocha-test-project will run all the tests in your project.
  2. mocha-test-file will test just the current file you are visiting.
  3. mocha-test-at-point will try and semantically find the nearest enclosing it or describe from your cursor, and just run that.

You can run any of these functions via M-x, or assign them to hotkeys.

Stack traces for failing tests have clickable links to the file and line that failed.

Running Test at Point

mocha-test-at-point uses js2-mode to find the nearest describe or it and extract the description string from it. As such, it only works in JavaScript files that have js2-mode set as the major mode.

Mocha includes an imenu function that builds an index matching the describe and it tree. You can enable this index function by setting imenu-create-index-function to mocha-make-imenu-alist or using (mocha-toggle-imenu-function).

Debugging Tests

Each of the test functions has a debug analog: mocha-debug-project, mocha-debug-file, and mocha-debug-at-point. Using these functions depends on having a javascript debugger installed and loaded. The debuggers with built-in support are:

The realgud debugging buffer takes the same commands as the standard node CLI debugger. Some useful ones are:

  • s to step in
  • o to step out
  • n to step over
  • c to continue execution
  • repl use interactive REPL at point

Additionally C-c C-c will send a BREAK signal, and M-p will cycle through previous inputs.

Contribution

Be sure to!

Install Cask if you haven't already.

Install the dependencies:

$ make install

Run the tests with:

$ make test