How to use the mocha.utils 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 electron / electron / spec / static / index.html View on Github external
if (process.env.MOCHA_REPORTER) {
    mochaOptions.reporter = process.env.MOCHA_REPORTER
  }
  if (process.env.MOCHA_MULTI_REPORTERS) {
    mochaOptions.reporterOptions = {
      reporterEnabled: process.env.MOCHA_MULTI_REPORTERS
    }
  }
  const mocha = new Mocha(mochaOptions)

  if (!process.env.MOCHA_REPORTER) {
    mocha.ui('bdd').reporter('tap')
  }
  mocha.timeout(30000)

  const query = Mocha.utils.parseQuery(window.location.search || '')
  if (query.grep) mocha.grep(query.grep)
  if (query.invert) mocha.invert()

  const files = query.files ? query.files.split(',') : undefined

  // Read all test files.
  const walker = require('walkdir').walk(path.dirname(__dirname), {
    no_recurse: true
  })

  // This allows you to run specific modules only:
  // npm run test -match=menu
  const moduleMatch = process.env.npm_config_match
    ? new RegExp(process.env.npm_config_match, 'g')
    : null
github centrehq / centre-tokens / verification / verification_reporter.js View on Github external
const mocha = require('mocha');
const spec_reporter = mocha.reporters.Spec;
const base_reporter = mocha.reporters.Base;
const color = base_reporter.color;
const inherits = mocha.utils.inherits;
const sheets = require('./GoogleSheets/index');
const _ = require('lodash');
const jsdiff = require('diff');
const colors = require('colors');

// Global variables for text output.
const green_x = color('bright pass', base_reporter.symbols.err);
const red_x = color('bright fail', base_reporter.symbols.err);
const green_ok = color('bright pass', base_reporter.symbols.ok);
const red_ok = color('bright fail', base_reporter.symbols.ok);
const indent = '    ';

module.exports = verification_reporter;

// Extends default Mocha reporter, 'Spec'.
inherits(verification_reporter, spec_reporter);
github mosaicdao / mosaic.js / test_integration / integration_tests.js View on Github external
const runTests = async () => {
  const mocha = new Mocha({
    enableTimeouts: false,
  });

  console.warn(
    'If this is the first time running the tests on this machine, this step might take a while, as Docker downloads a required image for the tests.',
  );
  const { originRpcEndpoint, auxiliaryRpcEndpoint } = await dockerSetup();
  shared.origin.web3 = new Web3(originRpcEndpoint);
  shared.auxiliary.web3 = new Web3(auxiliaryRpcEndpoint);

  Mocha.utils
    .lookupFiles(__dirname, ['js'], true)
    .filter(file => file.substr(-20) !== 'integration_tests.js')
    .forEach((file) => {
      mocha.addFile(file);
    });

  mocha.run((failures) => {
    dockerTeardown();
    process.exitCode = failures ? 1 : 0;
  });
};
github itchio / itch / test / chrome / static / index.html View on Github external
var runner = mocha.run(function() {
      Mocha.utils.highlightTags('code');
      if (isCi) {
        ipc.send('process.exit', runner.failures);
      }
    });
  });
github DonJayamanne / pythonVSCode / .mocha-reporter / mocha-vsts-reporter.js View on Github external
console.log('%s- %s', indenter, test.title);
    console.log('##vso[task.logissue type=warning;sourcepath=%s;]SKIPPED TEST %s :: %s', test.file, test.parent.title, test.title);
  });

  runner.on('fail', function(test, err){
    failures++;
    console.log('%s✖ %s -- error: %s', indenter, test.title, err.message);
    console.log('##vso[task.logissue type=error;sourcepath=%s;]FAILED %s :: %s', test.file, test.parent.title, test.title);
  });

  runner.on('end', function(){
    console.log('SUMMARY: %d/%d passed, %d skipped', passes, passes + failures, skipped);
  });
}

mocha.utils.inherits(MochaVstsReporter, MochaJUnitReporter);
github DonJayamanne / pythonVSCode / build / ci / mocha-vsts-reporter.js View on Github external
skipped++;
      console.log('%s- %s', indenter, test.title);
  });

  runner.on('fail', function(test, err){
    failures++;
    console.log('%s✖ %s -- error: %s', indenter, test.title, err.message);
    console.log('##vso[task.logissue type=error;sourcepath=%s;]FAILED %s :: %s', test.file, test.parent.title, test.title);
  });

  runner.on('end', function(){
    console.log('SUMMARY: %d/%d passed, %d skipped', passes, passes + failures, skipped);
  });
}

mocha.utils.inherits(MochaVstsReporter, MochaJUnitReporter);
github peerigon / xunit-file / lib / xunit-file.js View on Github external
/**
 * Module dependencies.
 */

var mocha = require("mocha")
  , Base = mocha.reporters.Base
  , utils = mocha.utils
  , escape = utils.escape
  , config = require("../config.json")
  , fs = require("fs")
  , path = require("path")
  , mkdirp = require("mkdirp")
  , dateFormat = require('dateformat')
  , filePathParser = require('./file-path-parser')(process, global.Date, dateFormat)
  , filePath = filePathParser(process.env.XUNIT_FILE || config.file || "${cwd}/xunit.xml")
  , consoleOutput = process.env.XUNIT_SILENT ? {} : config.consoleOutput || {};

/**
 * Save timer references to avoid Sinon interfering (see GH-237).
 */

var Date = global.Date
  , setTimeout = global.setTimeout
github macacajs / torchjs / lib / runMocha.js View on Github external
module.exports = (args, callback) => {
  const utils = Mocha.utils;
  const mocha = new Mocha();

  mocha.reporter(args.reporter, args.reporterOptions);
  mocha.ui(args.ui);
  if (args.inlineDiffs) {
    mocha.useInlineDiffs(true);
  }
  if (args.slow) {
    mocha.suite.slow(args.slow);
  }
  if (!args.timeouts) {
    mocha.enableTimeouts(false);
  }
  if (args.timeout) {
    mocha.suite.timeout(args.timeout);
  }
github compulim / vscode-mocha / worker / customreporter.js View on Github external
'use strict';

const Mocha = require('mocha');

const
  reporters = Mocha.reporters,
  utils = Mocha.utils,
  Base = reporters.Base,
  Spec = reporters.Spec,
  trimArray = require('../utils').trimArray;

function Reporter(runner) {
  this._spec = new Spec(runner);

  const
    suitePath = [],
    failed = [],
    passed = [];

  runner
    .on('suite', suite => {
      suitePath.push(suite.fullTitle());
    })
github ampproject / amphtml / build-system / tasks / mocha-ci-reporter.js View on Github external
* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
'use strict';

const {Base} = require('mocha').reporters;
const {inherits} = require('mocha').utils;
const {reportTestFinished} = require('./report-test-status');
const {symbols} = require('./karma.conf').mochaReporter;

/**
 * Custom Mocha reporter for CI builds.
 * Mimics the style of the Karma reporter on Travis.
 * @param {*} runner
 */
function ciReporter(runner) {
  Base.call(this, runner);
  const self = this;

  runner.on('pass', function() {
    process.stdout.write(Base.color('green', symbols.success));
  });