How to use the mocha.interfaces function in mocha

To help you get started, we’ve selected a few mocha examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ghempton / mocha-lazy-bdd / index.js View on Github external
*
 *      describe('Array', function(){
 *        lazy('lazyValue', function() {
 *          return 'i am lazy';
 *        });
 *        describe('#indexOf()', function(){
 *          it('should return -1 when not present', function(){
 *            this.lazyValue // evaluatesand caches the 'lazy block'
 *          });
 *
 *        });
 *      });
 *
 */

module.exports = Mocha.interfaces['lazy-bdd'] = function(suite){
  var suites = [suite];
  var cache = {};
  var insideTest;

  suite.on('pre-require', function(context, file, mocha){
    var common = require('mocha/lib/interfaces/common')(suites, context);

    context.before = common.before;
    context.after = common.after;
    context.beforeEach = common.beforeEach;
    context.afterEach = common.afterEach;
    context.run = mocha.options.delay && common.runWithSuite(suite);

    // clear lazy cache
    suite.beforeEach(function() {
      cache = {};
github TheBrainFamily / chimpy / dist / lib / mocha / mocha-fiberized-ui.js View on Github external
'use strict';

var _fiberize = require('../utils/fiberize');

// taken from https://github.com/tzeskimo/mocha-fibers/blob/master/lib/mocha-fibers.js

// A copy of bdd interface, but beforeEach, afterEach, before, after,
// and it methods all run within fibers.
var Mocha = require('mocha'),
    bdd = Mocha.interfaces.bdd,
    _ = require('underscore'),
    util = require('util');

// A copy of bdd interface, but wrapping everything in fibers
module.exports = Mocha.interfaces['fiberized-bdd-ui'] = function (suite) {
  bdd(suite);
  suite.on('pre-require', function (context) {
    // Wrap test related methods in fiber
    ['beforeEach', 'afterEach', 'after', 'before', 'it'].forEach(function (method) {
      var original = context[method];
      context[method] = _.wrap(original, function (fn) {
        var args = Array.prototype.slice.call(arguments, 1);
        if (_.isFunction(_.last(args))) {
          args.push((0, _fiberize.fiberize)(args.pop()));
        }
        return fn.apply(this, args);
      });
      _.extend(context[method], _(original).pick('only', 'skip'));
    });
  });
};
github TheBrainFamily / chimpy / src / lib / mocha / mocha-fiberized-ui.js View on Github external
// taken from https://github.com/tzeskimo/mocha-fibers/blob/master/lib/mocha-fibers.js

// A copy of bdd interface, but beforeEach, afterEach, before, after,
// and it methods all run within fibers.
var Mocha = require('mocha'),
  bdd = Mocha.interfaces.bdd,
  _ = require('underscore'),
  util = require('util');

import {fiberize} from '../utils/fiberize';

// A copy of bdd interface, but wrapping everything in fibers
module.exports = Mocha.interfaces['fiberized-bdd-ui'] = function (suite) {
  bdd(suite);
  suite.on('pre-require', function (context) {
    // Wrap test related methods in fiber
    ['beforeEach', 'afterEach', 'after', 'before', 'it'].forEach(function (method) {
      var original = context[method];
      context[method] = _.wrap(original, function (fn) {
        var args = Array.prototype.slice.call(arguments, 1);
        if (_.isFunction(_.last(args))) {
          args.push(fiberize(args.pop()));
        }
        return fn.apply(this, args);
      });
      _.extend(context[method], _(original).pick('only', 'skip'));
    });
  });
};
github TheBrainFamily / chimpy / dist / lib / mocha / mocha-fiberized-ui.js View on Github external
'use strict';

var _fiberize = require('../utils/fiberize');

// taken from https://github.com/tzeskimo/mocha-fibers/blob/master/lib/mocha-fibers.js

// A copy of bdd interface, but beforeEach, afterEach, before, after,
// and it methods all run within fibers.
var Mocha = require('mocha'),
    bdd = Mocha.interfaces.bdd,
    _ = require('underscore'),
    util = require('util');

// A copy of bdd interface, but wrapping everything in fibers
module.exports = Mocha.interfaces['fiberized-bdd-ui'] = function (suite) {
  bdd(suite);
  suite.on('pre-require', function (context) {
    // Wrap test related methods in fiber
    ['beforeEach', 'afterEach', 'after', 'before', 'it'].forEach(function (method) {
      var original = context[method];
      context[method] = _.wrap(original, function (fn) {
        var args = Array.prototype.slice.call(arguments, 1);
        if (_.isFunction(_.last(args))) {
          args.push((0, _fiberize.fiberize)(args.pop()));
        }
        return fn.apply(this, args);
github mongodb / node-mongodb-native / test / tools / runner / metadata_ui.js View on Github external
'use strict';

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

/**
 * This UI is identical to the BDD interface, but with the addition of
 * allowing tests and suites to contain metadata
 * https://github.com/mochajs/mocha/blob/master/lib/interfaces/bdd.js
 */
module.exports = Mocha.interfaces.metadata_ui = function(suite) {
  var suites = [suite];

  suite.on('pre-require', function(context, file, mocha) {
    var common = require('mocha/lib/interfaces/common')(suites, context, mocha);

    context.before = common.before;
    context.after = common.after;
    context.beforeEach = common.beforeEach;
    context.afterEach = common.afterEach;
    context.run = mocha.options.delay && common.runWithSuite(suite);

    /**
     * Parse arguments for suite and test functions
     */
    var _parseArgs = function(args) {
      var testData = {};
github twigjs / twig.js / node_modules / mocha / mocha.js View on Github external
mocha.setup = function(ui){
    ui = mocha.interfaces[ui];
    if (!ui) throw new Error('invalid mocha interface "' + ui + '"');
    ui(suite);
    suite.emit('pre-require', global);
  };
github HuddleEng / Muppeteer / example / launcher.js View on Github external
const Mocha = require('mocha');
const path = require('path');
const mochateerInterface = require('../lib/test-interface');
const {browserInstance} = require('../lib/test-controller');
const recursiveReadSync = require('recursive-readdir-sync');

Mocha.interfaces['mochateer'] = mochateerInterface(component => {
    return component.url;
}, component => {
    return path.join(__dirname, `./tests/screenshots/${component.name}`);
});

(async function() {
    const mocha = new Mocha({timeout: 10000, ui: 'mochateer'});

    let files = null;

    try {
        files = recursiveReadSync('./example/tests');
    } catch (err){
        if (err.errno === 34){
            console.log('Path does not exist');
        } else {
github esnext / es6-module-transpiler / tasks / options / simplemocha.js View on Github external
var Mocha = require('mocha');
Mocha.interfaces['qunit-mocha-ui'] = require('qunit-mocha-ui');

module.exports = {
  options: {
    globals: ['should'],
    timeout: 3000,
    ignoreLeaks: false,
    ui: 'qunit-mocha-ui'
  },

  all: { src: ['test/.generated/**/*.js'] }
};
github stalniy / bdd-lazy-var / lib / interface / mocha.js View on Github external
Tracker: SuiteTracker,
      inheritUi: 'bdd'
    }, options);

    Mocha.interfaces[name] = (rootSuite) => {
      Mocha.interfaces[config.inheritUi](rootSuite);
      return addInterface(rootSuite, config);
    };

    const getters = ['get', 'def', 'subject', 'its', 'it', 'is', 'sharedExamplesFor', 'includeExamplesFor', 'itBehavesLike'];
    const defs = getters.reduce((all, uiName) => {
      all[uiName] = { get: () => global[uiName] };
      return all;
    }, {});

    return Object.defineProperties(Mocha.interfaces[name], defs);
  }
};
github pact-foundation / pact-js / src / pact-mocha-interface / pact-ui.js View on Github external
'use strict'

import path from 'path'
import Mocha from 'mocha'
import Test from 'mocha/lib/test'
import Suite from 'mocha/lib/suite'

const wrapper = require('@pact-foundation/pact-node')

import Pact from '../pact-consumer-dsl/pact'

module.exports = Mocha.interfaces['pact'] = (suite) => {
  const suites = [suite]

  suite.on('pre-require', (context, file, mocha) => {
    var common = require('mocha/lib/interfaces/common')(suites, context)
    context.run = mocha.options.delay && common.runWithSuite(suite)

    const mockServer = wrapper.create({
      port: 1234,
      log: path.resolve(process.cwd(), 'logs', 'mockserver.log'),
      dir: path.resolve(process.cwd(), 'pacts'),
      spec: 2
    })

    context.Pact = (consumer, provider, providerURL, fn) => {
      const pactSuite = Suite.create(suites[0], `Pact ${consumer} <=> ${provider}`)
      pactSuite.file = file