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

docs for extending mocha #56

Closed
tj opened this issue Nov 19, 2011 · 9 comments
Closed

docs for extending mocha #56

tj opened this issue Nov 19, 2011 · 9 comments
Labels
area: documentation anything involving docs or mochajs.org

Comments

@tj
Copy link
Contributor

tj commented Nov 19, 2011

reporters, interfaces etc

@TheLudd
Copy link

TheLudd commented Jul 11, 2014

Old issue but has there been anything done on this one? I can't manage to find any info on this and it would be really nice...

@dkushner
Copy link

Second the interest expressed by @TheLudd. Would really like to add a new interface but I'm finding it an absolute chore to trudge through the code to figure out how to do that.

@boneskull boneskull added the area: documentation anything involving docs or mochajs.org label Oct 19, 2014
@danielstjules
Copy link
Contributor

@dkushner @TheLudd I think both https://github.com/mochajs/mocha/wiki/Third-party-reporters and https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically offer good examples of extending mocha. :) For full examples, you can try taking a look at some of the interfaces/reporters listed at https://github.com/mochajs/mocha/wiki#interfaces--reporters

@TheLudd
Copy link

TheLudd commented Mar 15, 2015

@danielstjules Well, perhaps if there also had been a "Third party ui". I have written my own now anyway but it really required looking through the code for different uis and do a lot of experimentation. I would not say this is closed but perhaps "extending" is not clearly enough defined.

@danielstjules
Copy link
Contributor

Oh, sorry! I can re-open this for now. I'll write something up on third party ui's as well. Thanks! :)

@danielstjules danielstjules reopened this Mar 15, 2015
@danielstjules
Copy link
Contributor

@TheLudd While it may have been more useful a while ago, I've added a page on extending mocha with Third Party UIs, which can be found here: https://github.com/mochajs/mocha/wiki/Third-party-UIs Sorry for the wait, and thanks for mentioning it!

@TheLudd
Copy link

TheLudd commented Mar 15, 2015

Well thanks for creating it. Looks like a bit of work =)

@danielstjules
Copy link
Contributor

Yup, but only if you want the full functionality! I updated the page to include a minimal example as well, which is hopefully less daunting:

var Mocha    = require('mocha');
    Suite    = require('mocha/lib/suite'),
    Test     = require('mocha/lib/test');

/**
 * A simple UI that only exposes a single function: test
 */
module.exports = Mocha.interfaces['simple-ui'] = function(suite){
  suite.on('pre-require', function(context, file, mocha){
    var common = require('mocha/lib/interfaces/common')([suite], context);

    context.run = mocha.options.delay && common.runWithSuite(suite);

    /**
     * Describes a specification or test-case  with the given `title`
     * and callback `fn` acting as a thunk.
     */
    context.test = function(title, fn){
      var test = new Test(title, fn);
      test.file = file;
      suite.addTest(test);

      return test;
    };
  });
};

@TheLudd
Copy link

TheLudd commented Mar 15, 2015

I meant by you, creating this =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: documentation anything involving docs or mochajs.org
Projects
None yet
Development

No branches or pull requests

5 participants