How to use the mocha 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 luckymarmot / API-Flow / testing / mocha-runner.js View on Github external
function runSuite() {
  Object.keys(require.cache).forEach(key => delete require.cache[key])
  const mocha = new Mocha({ reporter: 'spec' })
  fileList.forEach(filepath => mocha.addFile(filepath))
  try {
    mocha.run()
    if (global.gc) {
      global.gc()
    }
    else {
      /* eslint-disable no-console */
      console.log('Garbage collection unavailable')
      /* eslint-enable no-console */
    }
  }
  catch (e) {
    /* eslint-disable no-console */
    console.log('------------')
    console.log('Failed with Error', e.stack)
github mocha-parallel / mocha-parallel-tests / src / subprocess / runner.ts View on Github external
export function runMocha(file: string, options: ThreadOptions, debugSubprocess: boolean) {
  const channel = new MessageChannel();
  const Reporter = getReporterFactory(channel, debugSubprocess);

  const mocha = new Mocha();
  mocha.addFile(file);

  // --compilers
  applyCompilers(options.compilers);

  // --delay
  applyDelay(mocha, options.delay);

  // --grep
  applyGrepPattern(mocha, options.grep);

  // --enableTimeouts
  applyNoTimeouts(mocha, options.enableTimeouts);

  // --exit
  const onComplete = applyExit(channel, options.exitImmediately);
github oliviertassinari / react-event-listener / test / unit.js View on Github external
jsdom,
} from 'jsdom';

global.document = jsdom('');
global.window = document.defaultView;
global.navigator = global.window.navigator;
global.Node = global.window.Node;

const argv = minimist(process.argv.slice(2), {
  alias: {
    c: 'component',
    g: 'grep',
  },
});

const mocha = new Mocha({
  grep: argv.grep ? argv.grep : undefined,
});

glob(`src/**/${argv.component ? argv.component : '*'}.spec.js`, {}, (err, files) => {
  files.forEach((file) => mocha.addFile(file));

  mocha.run((failures) => {
    process.on('exit', () => {
      /* eslint-disable no-process-exit */
      process.exit(failures);
    });
  });
});
github oliviertassinari / babel-plugin-react-remove-properties / test / index.js View on Github external
import minimist from 'minimist';
import Mocha from 'mocha';
import glob from 'glob';

const argv = minimist(process.argv.slice(2), {
  alias: {
    m: 'module',
    g: 'grep',
  },
});

const globPatterns = [
  `test/**/${argv.module ? argv.module : '*'}.spec.js`,
];

const mocha = new Mocha({
  grep: argv.grep ? argv.grep : undefined,
});

glob(
  globPatterns.length > 1 ? `{${globPatterns.join(',')}}` : globPatterns[0],
  {},
  (err, files) => {
    files.forEach((file) => mocha.addFile(file));
    mocha.run((failures) => {
      process.on('exit', () => {
        process.exit(failures); // eslint-disable-line no-process-exit
      });
    });
  }
);
github oliviertassinari / react-swipeable-views / test / unit.js View on Github external
global[property] = document.defaultView[property];
  }
});

global.navigator = {
  userAgent: 'node.js',
};

const argv = minimist(process.argv.slice(2), {
  alias: {
    c: 'component',
    g: 'grep',
  },
});

const mocha = new Mocha({
  grep: argv.grep ? argv.grep : undefined,
  reporter: 'dot',
});

glob(`packages/**/src/**/${argv.component ? argv.component : '*'}.spec.js`, {}, (err, files) => {
  files.forEach((file) => mocha.addFile(file));

  mocha.run((failures) => {
    process.on('exit', () => {
      process.exit(failures); // eslint-disable-line no-process-exit
    });
  });
});
github onfido / onfido-sdk-ui / test / main.js View on Github external
const createMocha = (driver, testCase) => {
  // Create our Mocha instance
  const mocha = new Mocha({
    reporter: 'mochawesome',
    reporterOptions: {
      overwrite: false,
      reportTitle: 'UI Tests',
      reportFilename: 'UITestReport',
      reportDir: './dist/reports/UITestsReport',
      assetsDir: './dist/reports/UITestsReport',
    },
    timeout: testCase.timeout
  });
  // By default `require` caches files, making it impossible to require the same file multiple times.
  // Since we want to execute the same tests against many browsers we need to prevent this behaviour by
  // clearing the require cache.
  mocha.suite.on('require', (global, file) => {
    delete require.cache[file];
  });
github go2sh / cmake-integration-vscode / test / index.ts View on Github external
export function run(): Promise {
  // Create the mocha test
  const mocha = new Mocha({
    ui: 'tdd'
  });
  mocha.useColors(true);

  const testsRoot = path.resolve(__dirname, '..');

  return new Promise((c, e) => {
    glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
      if (err) {
        return e(err);
      }

      // Add files to the test suite
      files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));

      try {
github onfido / onfido-sdk-ui / test / main.js View on Github external
const createMocha = (driver, testCase) => {
  // Create our Mocha instance
  const mocha = new Mocha({
    timeout: testCase.timeout,
    fullTrace: true
  });
  // By default `require` caches files, making it impossible to require the same file multiple times.
  // Since we want to execute the same tests against many browsers we need to prevent this behaviour by
  // clearing the require cache.
  mocha.suite.on('require', (global, file) => {
    delete require.cache[file];
  });

  mocha.addFile(`${testCase.file}`);
  mocha.suite.ctx.driver = driver

  mocha.runP = () => new Promise((resolve) => {
    mocha.run(resolve)
  })
github sevenleaps / chat-template / test / unit.js View on Github external
global[property] = document.defaultView[property];
  }
});

global.navigator = {
  userAgent: 'node.js'
};

const argv = Minimist(process.argv.slice(2), {
  alias: {
    c: 'component',
    g: 'grep',
  },
});

const mocha = new Mocha({
  grep: argv.grep ? argv.grep : undefined,
});

Glob(`src/**/${argv.component ? argv.component : '*'}.spec.js`, {}, (err, files) => {
  files.forEach((file) => mocha.addFile(file));

  mocha.run((failures) => {
    process.on('exit', () => {
      process.exit(failures);
    });
  });
});
github dnd1 / stronger-loop / src / lib / runner.js View on Github external
exercise.addSetup(function(mode, callback) {
        const mocha = new Mocha({timeout: 20000});
        mocha.addFile(path.join(this.dir, 'spec.js'));

        runFunction(global.submission);

        mocha.run((failures) => {
            this.failures = failures;
            callback(null, true);
        });
    });