Mocha 1.3.0

A relatively minor release this time but we’ve still got some cool new features!

Scrolling HTML reporter

The window will now scroll to follow along with larger test suites, and the statistics are fixed to the upper right-hand corner, a small but nice touch.

Custom reporters

Mocha has quite a few bundled reporters now, so future reporters that are not deemed important enough to provide the convenience of being in core should be published to npm. Some less important reporters may be removed from core and published to npm in the future.

This new feature also allows you to use localized private reporters. The --reporter NAME flag now behaves like require(), so for example you could do --reporter ./myreporter, or a third-party npm module such as --reporter lcov-reporter.

For details on creating and finding third-party reporters visit the wiki.

Grep inversion

The awesome --grep feature can now be inverted with the aptly named --invert flag. For example suppose you had tests tagged as @slow, and you wanted to run only slow tests you might use --grep @slow, however if you wanted to run only fast tests --grep @slow --invert would do the trick.

Along with this change --grep PATTERN is now escaped, meaning chars that used to behave as regexp special chars are now escaped.

Changelog

Here’s the full changelog:

1.3.0 / 2012-07-05

  • add window scrolling to HTML reporter
  • add v8 --trace-* option support
  • add support for custom reports via --reporter MODULE
  • add --invert switch to invert --grep matches
  • fix export of Nyan reporter. Closes #495
  • fix escaping of HTML suite titles. Closes #486
  • fix done() called multiple times with an error test
  • change --grep - regexp escape the input

commander.c - C option parser

Every time I write a C program I end up rolling my own option parsing with a loop and strcmp(), so I figured it was time to port over commander.c from the original ruby commander, and there’s also a node.js port.

Commander.c is a super simple script that makes defining options declarative and does the dirty work for you, its usage looks like this:

#include <stdio.h>
#include "commander.h"

static void
verbose(command_t *self) {
  printf("verbose: enabled\n");
}

static void
required(command_t *self) {
  printf("required: %s\n", self->arg);
}

static void
optional(command_t *self) {
  printf("optional: %s\n", self->arg);
}

int
main(int argc, const char **argv){
  command_t cmd;
  command_init(&cmd, argv[0], "0.0.1");
  command_option(&cmd, "-v", "--verbose", "enable verbose stuff", verbose);
  command_option(&cmd, "-r", "--required <arg>", "required arg", required);
  command_option(&cmd, "-o", "--optional [arg]", "optional arg", optional);
  command_parse(&cmd, argc, argv);
  printf("additional args:\n");
  for (int i = 0; i < cmd.argc; ++i) {
    printf("  - '%s'\n", cmd.argv[i]);
  }
  return 0;
}

As a bonus it generates the --help from what it already knows about your program:

Usage: example [options]

Options:

  -V, --version                 output program version
  -h, --help                    output help information
  -v, --verbose                 enable verbose stuff
  -r, --required <arg>          required arg
  -o, --optional [arg]          optional arg

Commander handles optional and required args:

$ mon --sleep
 --sleep requires an argument

Warns about unrecognized flags:

$ ./test --foo
unrecognized flag --foo

Unparsed arguments are then provided as cmd.argv and of course its companion cmd.argc, which of course includes -- support to flag subsequent args as literals:

$ ./test foo -- --foo
additional args:
  - 'foo'
  - '--bar'

If you have a struct that you want to access within each callback just assign to cmd.data, a void *.

That’s it for now, I’ll be adding a few more things in the near future so check it out on github.

Mocha 1.2.0 - now with more nyan!

Nyan

@atsuya added an awesome new nyan reporter:

Client-side test initialization

You can now initialize a client-side test setup with the mocha init <path> command. This will copy over mocha.css, mocha.js and generate a default tests.html file for you.

Working browser example

A lot of people were asking for a working browser example to reference, so I added one to the bottom of mocha’s site, you can find it here. This example test suite uses chai for assertions.

Wildcard global leaks

Global leak wildcard matching was added to flag globals such as “callback123” and “callback456” with “callback*” created by libraries like jQuery as acceptable since there’s little you can do to avoid this.

mocha 1.1.0

The Mocha javascript test framework version 1.1.0 is out. If you want a quick glance here’s the changelog:

Changelog

  • Added: check each mocha(1) arg for directories to walk
  • Added --recursive [tricknotes]
  • Added context for BDD [hokaccha]
  • Added styling for new clickable titles
  • Added clickable suite titles to HTML reporter
  • Added warning when strings are thrown as errors
  • Changed: green arrows again in HTML reporter styling
  • Changed ul/li elements instead of divs for better copy-and-pasting [joliss]
  • Fixed issue #325 - add better grep support to js api
  • Fixed: save timer references to avoid Sinon interfering.

Directory arguments

Mocha will now iterate the arguments passed and load files in any given directories (non-recursively). For example you may now use mocha spec if you have tests in ./spec instead of mocha spec/* - which is especially helpful for the unfortunate few stuck on windows.

Recursive

The new --recursive flag compliments the previous feature, but walks the directories recursively.

Filter with clickable titles

Suite titles are now clickable, auto-grepping. For example if you have the following suite:

full suite

You could use ?grep=SOMESTRING, or simply click the title to re-execute tests within that suite as shown here:

durations only

That’s it for now :)

mad(1) node.js pages

The node.js markdown documentation is now viewable in the terminal via mad(1):

node man page

Just use mad list to see which pages are available:

list of node man pages

If you already have mad(1) installed simply run mad --update to grab these new pages, and view with mad node.http etc.

Express 3.x alpha reference docs

Since I don’t have the Express 3.x site up yet I thought I would whip up a quick set of markdown docs from the source comments using dox.

To view these markdown docs in your terminal install mad(1):

$ cd /tmp && git clone --depth 1 git@github.com:visionmedia/mad.git && cd mad && make install

Update your mad-pages:

$ mad --update

Profit!

$ mad express

HINT: Press “/”, type and press enter to search. The keys u and n move to the prev / next occurrences:

HINT HINT: There are also mad(1) pages for Jade, HTTP status codes, errnos and others.