All Projects → danielstjules → Mocha.parallel

danielstjules / Mocha.parallel

Licence: mit
Run async mocha specs in parallel

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mocha.parallel

xv
❌ ✔️ zero-config test runner for simple projects
Stars: ✭ 588 (+203.09%)
Mutual labels:  mocha, test
Mocha
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Stars: ✭ 20,986 (+10717.53%)
Mutual labels:  test, mocha
node-bogota
🚀 Run tape tests concurrently with tap-spec output
Stars: ✭ 15 (-92.27%)
Mutual labels:  test, parallel
alexa-skill-test-framework
Framework for easy offline black-box testing of Alexa skills.
Stars: ✭ 64 (-67.01%)
Mutual labels:  mocha, test
Suman
🌇 🌆 🌉 Advanced, user-friendly, language-agnostic, super-high-performance test runner. http://sumanjs.org
Stars: ✭ 57 (-70.62%)
Mutual labels:  parallel, mocha
Telegraf-Test
Telegraf Test - Simple Test ToolKit of Telegram Bots
Stars: ✭ 22 (-88.66%)
Mutual labels:  mocha, test
Enzyme
JavaScript Testing utilities for React
Stars: ✭ 19,781 (+10096.39%)
Mutual labels:  test, mocha
Bluepill
Bluepill is a reliable iOS testing tool that runs UI tests using multiple simulators on a single machine
Stars: ✭ 3,080 (+1487.63%)
Mutual labels:  parallel, test
Should Enzyme
Useful functions for testing React Components with Enzyme.
Stars: ✭ 41 (-78.87%)
Mutual labels:  test, mocha
Chakram
REST API test framework. BDD and exploits promises
Stars: ✭ 912 (+370.1%)
Mutual labels:  test, mocha
titef
🌠 A tiny, lightning-fast, zero-dependecies JavaScript test framework 🌠
Stars: ✭ 19 (-90.21%)
Mutual labels:  mocha, test
Snap Shot It
Smarter snapshot utility for Mocha and BDD test runners + data-driven testing!
Stars: ✭ 138 (-28.87%)
Mutual labels:  test, mocha
playwright-test
Run unit tests with several runners or benchmark inside real browsers with playwright.
Stars: ✭ 81 (-58.25%)
Mutual labels:  mocha, test
fixturez
Easily create and maintain test fixtures in the file system
Stars: ✭ 57 (-70.62%)
Mutual labels:  mocha, test
Ocaramba
C# Framework to automate tests using Selenium WebDriver
Stars: ✭ 234 (+20.62%)
Mutual labels:  parallel, test
Webdriverio
Next-gen browser and mobile automation test framework for Node.js
Stars: ✭ 7,214 (+3618.56%)
Mutual labels:  test, mocha
Javascript Testing Best Practices
📗🌐 🚢 Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)
Stars: ✭ 13,976 (+7104.12%)
Mutual labels:  test, mocha
Snap Shot
Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
Stars: ✭ 170 (-12.37%)
Mutual labels:  test, mocha
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (-8.76%)
Mutual labels:  mocha
Buildbuddy
BuildBuddy is an open source Bazel build event viewer, result store, and remote cache.
Stars: ✭ 182 (-6.19%)
Mutual labels:  test

mocha.parallel

Speed up your IO bound async specs by running them at the same time. Compatible with node 0.10+, and Mocha 2.3.5 - 5.2.x.

Build Status

Installation

npm install --save-dev mocha.parallel

Overview

/**
 * Generates a suite for parallel execution of individual specs. While each
 * spec is ran in parallel, specs resolve in series, leading to deterministic
 * output. Compatible with both callbacks and promises. Supports hooks, pending
 * or skipped specs/suites via parallel.skip() and it.skip(), but not nested
 * suites.  parallel.only() and it.only() may be used to only wait on the
 * specified specs and suites. Runnable contexts are bound, so this.skip()
 * and this.timeout() may be used from within a spec. parallel.disable()
 * may be invoked to use mocha's default test behavior, and parallel.enable()
 * will re-enable the module. parallel.limit(n) can be used to limit the number
 * of specs running simultaneously.
 *
 * @example
 * parallel('setTimeout', function() {
 *   it('test1', function(done) {
 *     setTimeout(done, 500);
 *   });
 *   it('test2', function(done) {
 *     setTimeout(done, 500);
 *   });
 * });
 *
 * @param {string}   name Name of the function
 * @param {function} fn   The test suite's body
 */

Examples

In the examples below, imagine that setTimeout is a function that performs some async IO with the specified delay. This could include requests to your http server using a module like supertest or request. Or maybe a headless browser using zombie or nightmare.

Simple

Rather than taking 1.5s, the specs below run in parallel, completing in just over 500ms.

var parallel = require('mocha.parallel');
var Promise  = require('bluebird');

parallel('delays', function() {
  it('test1', function(done) {
    setTimeout(done, 500);
  });

  it('test2', function(done) {
    setTimeout(done, 500);
  });

  it('test3', function() {
    return Promise.delay(500);
  });
});
  delays
    ✓ test1 (500ms)
    ✓ test2
    ✓ test3


  3 passing (512ms)

Isolation

Individual parallel suites run in series and in isolation from each other. In the example below, the two specs in suite1 run in parallel, followed by those in suite2.

var parallel = require('mocha.parallel');

parallel('suite1', function() {
  it('test1', function(done) {
    setTimeout(done, 500);
  });

  it('test2', function(done) {
    setTimeout(done, 500);
  });
});

parallel('suite2', function() {
  it('test1', function(done) {
    setTimeout(done, 500);
  });

  it('test2', function(done) {
    setTimeout(done, 500);
  });
});
  suite1
    ✓ test1 (503ms)
    ✓ test2

  suite2
    ✓ test1 (505ms)
    ✓ test2


  4 passing (1s)

Error handling

Uncaught exceptions are associated with the spec that threw them, despite them all running at the same time. So debugging doesn't need to be too difficult!

var parallel = require('mocha.parallel');

parallel('uncaught', function() {
  it('test1', function(done) {
    setTimeout(done, 500);
  });

  it('test2', function(done) {
    setTimeout(function() {
      // Thrown while test1 is executing
      throw new Error('test');
    }, 100);
  });

  it('test3', function(done) {
    setTimeout(done, 500);
  });
});
  uncaught
    ✓ test1 (501ms)
    1) test2
    ✓ test3


  2 passing (519ms)
  1 failing

  1) uncaught test2:
     Error: test
      at null._onTimeout (fixtures/uncaughtException.js:11:13)

Hooks

Hook behavior may not be as intuitive when ran using this library.

var parallel = require('mocha.parallel');
var assert   = require('assert');

describe('suite', function() {
  var i = 0;

  beforeEach(function(done) {
    // Invoked twice, before either spec starts
    i++;
    done();
  });

  parallel('hooks', function() {
    beforeEach(function(done) {
      // Invoked twice, before either spec starts
      i++;
      done();
    });

    it('test1', function(done) {
      // Incremented by 4x beforeEach
      setTimeout(function() {
        assert.equal(i, 4);
        done();
      }, 1000);
    });

    it('test2', function(done) {
      // Incremented by 4x beforeEach
      setTimeout(function() {
        assert.equal(i, 4);
        done();
      }, 1000);
    });
  });
});

Notes

Debugging parallel execution can be more difficult as exceptions may be thrown from any of the running specs. Also, the use of the word "parallel" is in the same spirit as other nodejs async control flow libraries, such as https://github.com/caolan/async#parallel, https://github.com/creationix/step and https://github.com/tj/co#yieldables This library does not offer true parallelism using multiple threads/workers/fibers, or by spawning multiple processes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].