Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How do I get mocha to run "exports"-style tests on Windows?

How do I get mocha to run "exports"-style tests on Windows?

Problem

I have NodeJS and Mocha installed and working on Windows 7 x64 - so far, so good - but I can't get Mocha to recognise any tests defined using the exports interface (as described at http://visionmedia.github.com/mocha/)

If I create test/bdd.js containing the following code:

var should = require('should');

describe('TestDemo - BDD interface', function(){
  describe('#foo', function(){
    it('1 should equal 1', function(){ (1).should.equal(1);  });
  });
});

I can run mocha and get the expected output:

D:\Projects\NodeDemo>mocha -R spec

  TestDemo - BDD interface
    #foo
      ✓ 1 should equal 1

  ✔ 1 tests complete (7ms)

D:\Projects\NodeDemo>

BUT if I create test/exports.js containing this code (based on the 'exports' interface example provided on the Mocha site)

var should = require('should');

module.exports = {
  'TestDemo - exports interface': {
    '#foo': {
      '1 should equal 1': function(){ (1).should.equal(1); }
    }
  }
};

when I run Mocha it doesn't find any tests:

D:\Projects\NodeDemo>mocha -R spec

✔ 0 tests complete (1ms)

D:\Projects\NodeDemo>

I suspect I've either missed a switch or something for specifying which interface mocha should be using for test definitions, or I've found something that isn't supported on Windows (yet). Any ideas?

Problem courtesy of: Dylan Beattie

Solution

Of course, the second you post it to StackOverflow you notice a line of documentation that I'd swear wasn't there before... :)

mocha(1)

Usage: mocha [options] [files]

Options:

-u, --ui         specify user-interface (bdd|tdd|exports)

and sure enough, running

D:\Projects\NodeDemo>mocha -ui exports -R spec

does exactly what I expected. D'OH.

Solution courtesy of: Dylan Beattie

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How do I get mocha to run "exports"-style tests on Windows?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×