{"id":13681808,"url":"https://github.com/danielstjules/mocha.parallel","last_synced_at":"2025-04-04T14:09:41.749Z","repository":{"id":57299984,"uuid":"41269634","full_name":"danielstjules/mocha.parallel","owner":"danielstjules","description":"Run async mocha specs in parallel","archived":false,"fork":false,"pushed_at":"2023-06-06T15:11:11.000Z","size":86,"stargazers_count":196,"open_issues_count":10,"forks_count":20,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T13:10:05.957Z","etag":null,"topics":["javascript","mocha","nodejs","parallel","test"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielstjules.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-08-23T22:15:29.000Z","updated_at":"2024-12-04T20:08:15.000Z","dependencies_parsed_at":"2024-02-21T02:45:14.251Z","dependency_job_id":null,"html_url":"https://github.com/danielstjules/mocha.parallel","commit_stats":{"total_commits":112,"total_committers":11,"mean_commits":"10.181818181818182","dds":0.125,"last_synced_commit":"7d097eb5146472384227ce78e08f1a8954517196"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fmocha.parallel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fmocha.parallel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fmocha.parallel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fmocha.parallel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielstjules","download_url":"https://codeload.github.com/danielstjules/mocha.parallel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190254,"owners_count":20898702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","mocha","nodejs","parallel","test"],"created_at":"2024-08-02T13:01:36.118Z","updated_at":"2025-04-04T14:09:41.682Z","avatar_url":"https://github.com/danielstjules.png","language":"JavaScript","readme":"# mocha.parallel\n\nSpeed up your IO bound async specs by running them at the same time. Compatible\nwith node 0.10+, and Mocha 2.3.5 - 5.2.x.\n\n[![Build Status](https://travis-ci.org/danielstjules/mocha.parallel.svg?branch=master)](https://travis-ci.org/danielstjules/mocha.parallel)\n\n## Installation\n\n```\nnpm install --save-dev mocha.parallel\n```\n\n## Overview\n\n``` javascript\n/**\n * Generates a suite for parallel execution of individual specs. While each\n * spec is ran in parallel, specs resolve in series, leading to deterministic\n * output. Compatible with both callbacks and promises. Supports hooks, pending\n * or skipped specs/suites via parallel.skip() and it.skip(), but not nested\n * suites.  parallel.only() and it.only() may be used to only wait on the\n * specified specs and suites. Runnable contexts are bound, so this.skip()\n * and this.timeout() may be used from within a spec. parallel.disable()\n * may be invoked to use mocha's default test behavior, and parallel.enable()\n * will re-enable the module. parallel.limit(n) can be used to limit the number\n * of specs running simultaneously.\n *\n * @example\n * parallel('setTimeout', function() {\n *   it('test1', function(done) {\n *     setTimeout(done, 500);\n *   });\n *   it('test2', function(done) {\n *     setTimeout(done, 500);\n *   });\n * });\n *\n * @param {string}   name Name of the function\n * @param {function} fn   The test suite's body\n */\n```\n\n## Examples\n\nIn the examples below, imagine that `setTimeout` is a function that performs\nsome async IO with the specified delay. This could include requests to your\nhttp server using a module like `supertest` or `request`. Or maybe a headless\nbrowser using `zombie` or `nightmare`.\n\n#### Simple\n\nRather than taking 1.5s, the specs below run in parallel, completing in just\nover 500ms.\n\n``` javascript\nvar parallel = require('mocha.parallel');\nvar Promise  = require('bluebird');\n\nparallel('delays', function() {\n  it('test1', function(done) {\n    setTimeout(done, 500);\n  });\n\n  it('test2', function(done) {\n    setTimeout(done, 500);\n  });\n\n  it('test3', function() {\n    return Promise.delay(500);\n  });\n});\n```\n\n```\n  delays\n    ✓ test1 (500ms)\n    ✓ test2\n    ✓ test3\n\n\n  3 passing (512ms)\n```\n\n#### Isolation\n\nIndividual parallel suites run in series and in isolation from each other.\nIn the example below, the two specs in suite1 run in parallel, followed by\nthose in suite2.\n\n``` javascript\nvar parallel = require('mocha.parallel');\n\nparallel('suite1', function() {\n  it('test1', function(done) {\n    setTimeout(done, 500);\n  });\n\n  it('test2', function(done) {\n    setTimeout(done, 500);\n  });\n});\n\nparallel('suite2', function() {\n  it('test1', function(done) {\n    setTimeout(done, 500);\n  });\n\n  it('test2', function(done) {\n    setTimeout(done, 500);\n  });\n});\n```\n\n```\n  suite1\n    ✓ test1 (503ms)\n    ✓ test2\n\n  suite2\n    ✓ test1 (505ms)\n    ✓ test2\n\n\n  4 passing (1s)\n```\n\n#### Error handling\n\nUncaught exceptions are associated with the spec that threw them, despite them\nall running at the same time. So debugging doesn't need to be too difficult!\n\n``` javascript\nvar parallel = require('mocha.parallel');\n\nparallel('uncaught', function() {\n  it('test1', function(done) {\n    setTimeout(done, 500);\n  });\n\n  it('test2', function(done) {\n    setTimeout(function() {\n      // Thrown while test1 is executing\n      throw new Error('test');\n    }, 100);\n  });\n\n  it('test3', function(done) {\n    setTimeout(done, 500);\n  });\n});\n```\n\n```\n  uncaught\n    ✓ test1 (501ms)\n    1) test2\n    ✓ test3\n\n\n  2 passing (519ms)\n  1 failing\n\n  1) uncaught test2:\n     Error: test\n      at null._onTimeout (fixtures/uncaughtException.js:11:13)\n```\n\n#### Hooks\n\nHook behavior may not be as intuitive when ran using this library.\n\n``` javascript\nvar parallel = require('mocha.parallel');\nvar assert   = require('assert');\n\ndescribe('suite', function() {\n  var i = 0;\n\n  beforeEach(function(done) {\n    // Invoked twice, before either spec starts\n    i++;\n    done();\n  });\n\n  parallel('hooks', function() {\n    beforeEach(function(done) {\n      // Invoked twice, before either spec starts\n      i++;\n      done();\n    });\n\n    it('test1', function(done) {\n      // Incremented by 4x beforeEach\n      setTimeout(function() {\n        assert.equal(i, 4);\n        done();\n      }, 1000);\n    });\n\n    it('test2', function(done) {\n      // Incremented by 4x beforeEach\n      setTimeout(function() {\n        assert.equal(i, 4);\n        done();\n      }, 1000);\n    });\n  });\n});\n```\n\n## Notes\n\nDebugging parallel execution can be more difficult as exceptions may be thrown\nfrom any of the running specs. Also, the use of the word \"parallel\" is in the\nsame spirit as other nodejs async control flow libraries, such as\nhttps://github.com/caolan/async#parallel, https://github.com/creationix/step\nand https://github.com/tj/co#yieldables This library does not offer true\nparallelism using multiple threads/workers/fibers, or by spawning multiple\nprocesses.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielstjules%2Fmocha.parallel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielstjules%2Fmocha.parallel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielstjules%2Fmocha.parallel/lists"}