Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 509
Dylan Beattie Avatar asked Mar 11 '12 15:03

Dylan Beattie


1 Answers

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 <name>        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.

like image 105
Dylan Beattie Avatar answered Sep 24 '22 20:09

Dylan Beattie