Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to tell grunt-mocha-test to use the mocha.opts file from the test folder? #7

Closed
goloroden opened this issue Feb 20, 2013 · 3 comments

Comments

@goloroden
Copy link

In mocha you can use a file called mocha.opts to provide cli arguments to the mocha process. This file needs to be in the test folder.

Anyway, if I simply put

grunt.initConfig({
  mochaTest: {
    files: ['test/**/*.js']
  }
});

into my Gruntfile.js, mocha complains about suite not being defined, although the file mocha.opts exists and contains the line:

--ui tdd

Any ideas on how to solve this?

It looks as if mocha, if run by grunt-mocha-test, does not load this file at all.

@pghalliday
Copy link
Owner

I have found in the past that calling mocha programatically is not the same as calling it from the command line and the same arguments are not necessarily supported (we had a similar issue with --require which I managed to simulate).

I believe in this case you can specify the ui option as a field in mochaTestConfig as follows:

grunt.initConfig({
    mochaTest: {
      files: ['test/**/*.js']
    },
    mochaTestConfig: {
      options: {
        ui: 'tdd'        
      }
    }
  });

As it may not be possible to support all command line arguments (or even simulate them as I did with --require) I don't think I want to open the can of worms that might come with trying to support the mocha.opts file.

To get a fuller idea of what is supported in the mochaTestConfig options you might take a look at this:

https://github.com/visionmedia/mocha/wiki/Using-mocha-programmatically

@goloroden
Copy link
Author

First of all: Thanks a lot for replying that fast :-)!

I understand the issue you have, and your suggestion of using

ui: 'tdd'

works perfectly. The downside is that if you also want to be able to run mocha from the command line, you need the additional mocha.opts file with the very same options inside.

But anyway, it works.

Thanks for your help :-)!

@pghalliday
Copy link
Owner

Your welcome.

Yeah, I can see the problem. I'm tempted to raise an issue against Mocha - it seems to me that attempting to fix that here would be very fragile if mocha ever changed its options (I think this is already a problem with the way I dealt with --require)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants