How to use the mocha.reporters 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 kieranelby / KingOfTheEtherThrone / tests / test-example.js View on Github external
/* jslint node:true, mocha:true */
'use strict';

/*
 * Intended to be run against the testnet via the web3 RPC API.
 * e.g. might start geth like:
 * geth --testnet --port 31313 --datadir e:/ethereum -rpc -rpcport 8646 -rpcapi "eth,web3,personal"
*/

var DAppTestRunner = require('./dapp-test-runner');
var tests = new DAppTestRunner('King of the Ether Throne Core');
tests.setWeb3MasterAccount('0xb028d69032b7ca02056d684e6086030aecbf6eb0');

var mocha = require('mocha');
var reporter = new mocha.reporters.Spec(tests);

// maybe some way to register contracts with the runner would be nice
var kingOfTheEtherThroneInterface = [{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"sweepCommission","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"},{"name":"compensationAddress","type":"address"}],"name":"claimThroneFor","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"currentClaimPrice","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"pastMonarchs","outputs":[{"name":"compensationAddress","type":"address"},{"name":"originAddress","type":"address"},{"name":"name","type":"string"},{"name":"claimPrice","type":"uint256"},{"name":"coronationTimestamp","type":"uint256"},{"name":"compensationStatus","type":"uint8"},{"name":"compensationPaid","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"}],"name":"claimThrone","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"numberOfMonarchs","outputs":[{"name":"n","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"monarchNumber","type":"uint256"},{"name":"sendToOriginalOrigin","type":"bool"}],"name":"resendFailedPayment","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"currentMonarch","outputs":[{"name":"compensationAddress","type":"address"},{"name":"originAddress","type":"address"},{"name":"name","type":"string"},{"name":"claimPrice","type":"uint256"},{"name":"coronationTimestamp","type":"uint256"},{"name":"compensationStatus","type":"uint8"},{"name":"compensationPaid","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"usurperOriginAddress","type":"address"},{"indexed":false,"name":"usurperName","type":"string"},{"indexed":false,"name":"newClaimPrice","type":"uint256"}],"name":"ThroneClaimed","type":"event"}];
var kingOfTheEtherThroneBytecode = "60606040525b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555067016345785d8a000060016000508190555060e060405190810160405280600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168152602001600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168152602001604060405190810160405280600881526020017f5b566163616e745d000000000000000000000000000000000000000000000000815260200150815260200160008152602001428152602001600081526020016000815260200150600260005060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555060208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055506040820151816002016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101b557805160ff19168380011785556101e6565b828001600101855582156101e6579182015b828111156101e55782518260005055916020019190600101906101c7565b5b50905061021191906101f3565b8082111561020d57600081815060009055506001016101f3565b5090565b5050606082015181600301600050556080820151816004016000505560a08201518160050160006101000a81548160ff0219169083021790555060c082015181600601600050559050505b61132d8061026a6000396000f360606040523615610095576000357c0100000000000000000000000000000000000000000000000000000000900480630eb3f5a0146100da5780631d935a6b146100f257806364325ddb146101515780637842c52d14610174578063b66a323c14610278578063c8fdc891146102ce578063e32ee3c5146102f1578063e40d0ac314610312578063f2fde38b1461040d57610095565b6100d85b6100d56000368080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505061119f565b5b565b005b6100f06004808035906020019091905050611029565b005b61014f6004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091908035906020019091905050610425565b005b61015e60048050506111ad565b6040518082815260200191505060405180910390f35b61018a6004808035906020019091905050611241565b604051808873ffffffffffffffffffffffffffffffffffffffff1681526020018773ffffffffffffffffffffffffffffffffffffffff168152602001806020018681526020018581526020018481526020018381526020018281038252878181546001816001161561010002031660029004815260200191508054600181600116156101000203166002900480156102635780601f1061023857610100808354040283529160200191610263565b820191906000526020600020905b81548152906001019060200180831161024657829003601f168201915b50509850505050505050505060405180910390f35b6102cc6004808035906020019082018035906020019191908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505090909190505061119f565b005b6102db600480505061118a565b6040518082815260200191505060405180910390f35b6103106004808035906020019091908035906020019091905050610d0a565b005b61031f60048050506111b6565b604051808873ffffffffffffffffffffffffffffffffffffffff1681526020018773ffffffffffffffffffffffffffffffffffffffff168152602001806020018681526020018581526020018481526020018381526020018281038252878181546001816001161561010002031660029004815260200191508054600181600116156101000203166002900480156103f85780601f106103cd576101008083540402835291602001916103f8565b820191906000526020600020905b8154815290600101906020018083116103db57829003601f168201915b50509850505050505050505060405180910390f35b6104236004808035906020019091905050611104565b005b60006000600060006000600034955060016000505486101561044657610002565b60016000505486111561045857610002565b6064600187020494508486039350600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600260005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415610519576000600260005060050160006101000a81548160ff0219169083021790555060006002600050600601600050819055506105c0565b6127109250610551600260005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1685856112eb565b9150811561057d576001600260005060050160006101000a81548160ff021916908302179055506105af565b6002600260005060050160006101000a81548160ff0219169083021790555083600a6000828282505401925050819055505b836002600050600601600050819055505b600960005080548060010182818154818355818115116106fe576007028160070283600052602060002091820191016106fd91906105f9565b808211156106f95760006000820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905560028201600050805460018160011615610100020316600290046000825580601f1061067d57506106ba565b601f0160209004906000526020600020908101906106b9919061069b565b808211156106b5576000818150600090555060010161069b565b5090565b5b50600382016000506000905560048201600050600090556005820160006101000a81549060ff02191690556006820160005060009055506001016105f9565b5090565b5b5050509190906000526020600020906007020160005b600260005090919091506000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055506001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555060028201600050816002016000509080546001816001161561010002031660029004828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061081b5780548555610858565b8280016001018555821561085857600052602060002091601f016020900482015b8281111561085757825482559160010191906001019061083c565b5b5090506108839190610865565b8082111561087f5760008181506000905550600101610865565b5090565b505060038201600050548160030160005055600482016000505481600401600050556005820160009054906101000a900460ff168160050160006101000a81548160ff021916908302179055506006820160005054816006016000505550505060e060405190810160405280888152602001328152602001898152602001878152602001428152602001600081526020016000815260200150600260005060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555060208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055506040820151816002016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106109d857805160ff1916838001178555610a09565b82800160010185558215610a09579182015b82811115610a085782518260005055916020019190600101906109ea565b5b509050610a349190610a16565b80821115610a305760008181506000905550600101610a16565b5090565b5050606082015181600301600050556080820151816004016000505560a08201518160050160006101000a81548160ff0219169083021790555060c082015181600601600050559050506002600360016000505402049050662386f26fc10000811015610aaa5780600160005081905550610be9565b67016345785d8a0000811015610ad957655af3107a40008104655af3107a400002600160005081905550610be8565b670de0b6b3a7640000811015610b0a5766038d7ea4c68000810466038d7ea4c6800002600160005081905550610be7565b678ac7230489e80000811015610b3b57662386f26fc100008104662386f26fc1000002600160005081905550610be6565b68056bc75e2d63100000811015610b6f5767016345785d8a0000810467016345785d8a000002600160005081905550610be5565b683635c9adc5dea00000811015610ba357670de0b6b3a76400008104670de0b6b3a764000002600160005081905550610be4565b69021e19e0c9bab2400000811015610bd857678ac7230489e800008104678ac7230489e8000002600160005081905550610be3565b806001600050819055505b5b5b5b5b5b5b7f66dd2fa17295ffce5da0fb78b9a7146bc2c19cfbab9752e98fd016cfde14e0de600260005060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166002600050600201600050600160005054604051808473ffffffffffffffffffffffffffffffffffffffff16815260200180602001838152602001828103825284818154600181600116156101000203166002900481526020019150805460018160011615610100020316600290048015610cef5780601f10610cc457610100808354040283529160200191610cef565b820191906000526020600020905b815481529060010190602001808311610cd257829003601f168201915b505094505050505060405180910390a15b5050505050505050565b6000600060006000600060006000600260096000508a815481101561000257906000526020600020906007020160005b5060050160009054906101000a900460ff16141515610d5857610002565b60009650600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610dbd57600196508650610ec1565b600960005089815481101561000257906000526020600020906007020160005b5060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610e4057600196508650610ec0565b600960005089815481101561000257906000526020600020906007020160005b5060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163273ffffffffffffffffffffffffffffffffffffffff161415610ebf576001965086505b5b5b861515610ecd57610002565b600960005089815481101561000257906000526020600020906007020160005b506006016000505494508715610f5157600960005089815481101561000257906000526020600020906007020160005b5060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1695508550600093508350610fb7565b600960005089815481101561000257906000526020600020906007020160005b5060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16955085506161a892505a915082821015610faf57610002565b828203935083505b610fc28686866112eb565b9050801515610fd057610002565b600160096000508a815481101561000257906000526020600020906007020160005b5060050160006101000a81548160ff0219169083021790555084600a6000828282505403925050819055505b505050505050505050565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415611100573073ffffffffffffffffffffffffffffffffffffffff1631600a60005054820111156110aa57610002565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600082604051809050600060405180830381858888f19350505050505b5b50565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156111865780600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b5b50565b6000600960005080549050905061119c565b90565b6111a98133610425565b5b50565b60016000505481565b60026000508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169080600201600050908060030160005054908060040160005054908060050160009054906101000a900460ff16908060060160005054905087565b600960005081815481101561000257906000526020600020906007020160005b915090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169080600201600050908060030160005054908060040160005054908060050160009054906101000a900460ff16908060060160005054905087565b60008373ffffffffffffffffffffffffffffffffffffffff16838390604051809050600060405180830381858888f193505050509050611326565b939250505056";
tests.registerContract('KingOfTheEtherThrone', kingOfTheEtherThroneInterface, kingOfTheEtherThroneBytecode);

tests.add({
  title: 'Claim Throne at Starting Price should Increase Claim Price',
  steps: [
    function(helper) {
      this.throne = helper.createContractInstance('KingOfTheEtherThrone');
      // throne costs 100, but need a bit extra to cover gas:
      this.playerOneAccount = helper.createAccountWith(helper.toWei('120', 'finney'));
    },
    function(helper) {
      if (!this.throne.address) {
github dotnetprofessional / LiveDoc / packages / livedoc-mocha / _src / app / reporter.ts View on Github external
import * as model from "livedoc-model"
import * as fs from "fs-extra";

/**
 * Module dependencies.
 */

var Base = require('mocha').reporters.Base;

/**
 * Expose `JSON`.
 */

exports = module.exports = JSONReporter;

var uniqueId = 0;
// Add a unique identifier to each test
function getUniqueId() {
    uniqueId++;
    return uniqueId;
}

/**
 * Initialize a new `JSON` reporter.
github LimeChain / etherlime / packages / etherlime / cli-commands / etherlime-test / gas-logger / gas-reporter.js View on Github external
const mocha = require('mocha');
const Base = mocha.reporters.Base;
const color = Base.color;
const GasLogger = require('./gas-logger');
const inherits = require('util').inherits;

function CustomReporter(runner, options) {
	Base.call(this, runner);
	const self = this;
	let port = options.reporterOptions.port;
	let indents = 0;
	let n = 0;
	let failed = false;
	let gasLogger = new GasLogger(port);
	const indent = () => Array(indents).join('  ');

	runner.on('start', () => {
github microsoft / vscode-js-debug / src / int-chrome / testSupport / loggingReporter.ts View on Github external
/*---------------------------------------------------------
 * Copyright (C) Microsoft Corporation. All rights reserved.
 *--------------------------------------------------------*/

import * as mocha from 'mocha';
import * as events from 'events';

class LoggingReporter extends mocha.reporters.Spec {
  static alwaysDumpLogs = false;
  static logEE = new events.EventEmitter();

  private testLogs: string[] = [];
  private inTest = false;

  constructor(runner: any) {
    super(runner);

    LoggingReporter.logEE.on('log', msg => {
      if (this.inTest) {
        this.testLogs.push(msg);
      }
    });

    runner.on('test', () => {
github qlik-oss / after-work.js / commands / protractor / src / plugins / reporter / index.js View on Github external
let pending = 0;
  let failures = 0;
  let passes = 0;
  let config;

  Base.call(this, runner);
  (async () => {
    config = await browser.getProcessedConfig();
  })();
  if (reporterOptions) {
    if (reporterOptions.xunit) {
      reporterOptions.output = path.resolve(
        browser.reporterInfo.artifactsPath,
        `${browser.reporterInfo.reportName}.xml`,
      );
      new mocha.reporters.XUnit(runner, options);
    }
  }
  runner.on('pass', test => {
    console.log(
      '\u001b[32m √ PASSED: %s ( %sms )\u001b[0m',
      test.fullTitle(),
      test.duration,
    );
    tests.push(test);
    passes++;
  });

  runner.on('pending', test => {
    tests.push(test);
    pending++;
  });
github cgewecke / eth-gas-reporter / index.js View on Github external
const mocha = require("mocha");
const inherits = require("util").inherits;
const Base = mocha.reporters.Base;
const color = Base.color;
const log = console.log;
const utils = require("./lib/utils");
const Config = require("./lib/config");
const TransactionWatcher = require("./lib/transactionWatcher");
const GasTable = require("./lib/gasTable");
const SyncRequest = require("./lib/syncRequest");

/**
 * Based on the Mocha 'Spec' reporter. Watches an Ethereum test suite run
 * and collects data about method & deployments gas usage. Mocha executes the hooks
 * in this reporter synchronously so any client calls here should be executed
 * via low-level RPC interface using sync-request. (see /lib/syncRequest)
 * An exception is made for fetching gas & currency price data from coinmarketcap and
 * ethgasstation (we hope that single call will complete by the time the tests finish running)
 *
github glacejs / glace-js / lib / reporter / base.js View on Github external
"use strict";
/**
 * `GlaceJS` common reporter.
 *
 * @class
 * @name GlaceReporter
 * @arg {object} runner - `MochaJS` runner.
 */

var _ = require("lodash");
var util = require("util");

var MochaReporter = require("mocha").reporters.base;
var U = require("glacejs-utils");
var LOG = U.logger;

var CONF = require("../config");
/**
 * Registered reporters.
 *
 * @type {object[]}
 */
var reporters = [];

var GlaceReporter = function (runner) {
    MochaReporter.call(this, runner);

    runner.on("start", () => {
        for (var reporter of reporters) {
github sweet-js / sweet-core / build.js View on Github external
target.test = function() {
    echo("\nrunning tests...");
    if(process.env.NODE_DISABLE_COLORS === "1") {
        Mocha.reporters.Base.useColors = false;
    }
    var mocha = new Mocha();
    mocha.useColors = false;

    fs.readdirSync('build/').filter(function(file) {
        return file.substr(-3) === '.js';
    }).forEach(function(file) {
        mocha.addFile(path.join("build/", file));
    });
    mocha.run();
};
github sapo / Ink / src / js / serverUtils / xunit2.js View on Github external
(function(global) {

var Base   = require('mocha').reporters.Base,
    utils  = require('mocha').utils,
    escape = utils.escape;



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

var Date          = global.Date,
    setTimeout    = global.setTimeout,
    setInterval   = global.setInterval,
    clearTimeout  = global.clearTimeout,
    clearInterval = global.clearInterval;
github hash-bang / mocha-logger / index.js View on Github external
var mcoloring = require('mocha').reporters.Base.color;

/**
* Convert a JavaScript arguments object into an array and optionally surround it with the given values
* @param arguments arguments A JavaScript arguments object
* @param string prefix Optional prefix to apply
* @param string suffix Optional suffix to apply
* @return array A standard array of the extracted arguments
*/
function _argArray(argObj, prefix, suffix) {
	var args = Array.prototype.slice.call(argObj);
	if (prefix) args.unshift(prefix);
	if (suffix) args.push(suffix);
	return args;
}