@@ -14,87 +14,59 @@ npm install --save mocha.parallel
1414
1515``` javascript
1616/**
17- * Builds the test suite dynamically to allow for parallel execution of the
18- * individual specs. While each spec is ran in parallel, specs resolve in
19- * series, leading to deterministic output. Expects an array of names,
20- * arguments, and a function that returns a Promise .
17+ * Generates a suite for parallel execution of individual specs. While each
18+ * spec is ran in parallel, specs resolve in series, leading to deterministic
19+ * output. Compatible with both callbacks and promises. Supports before/after
20+ * hooks, but not afterEach/beforeEach hooks, nor nested suites .
2121 *
2222 * @example
23- * parallel ([' test1' , ' test2' ], [[1 , 2 ], [2 , 4 ]], function (x , expected ) {
24- * return Promise .delay (100 ).then (function () {
25- * assert .equal (x + x, res);
23+ * parallel (' setTimeout' , function () {
24+ * it (' test1' , function (done ) {
25+ * setTimeout (done, 500 );
26+ * });
27+ * it (' test2' , function (done ) {
28+ * setTimeout (done, 500 );
2629 * });
2730 * });
2831 *
29- * @param {string[]} names Names to assign the specs
30- * @param {*[]} args Arguments to pass to the function
31- * @param {} A function returning a promise
32+ * @param {string} name
33+ * @param {function} fn
3234 */
3335```
3436
3537## Examples
3638
37- Rather than taking 3 .5s, the specs below run in parallel, completing in just
38- over 900ms .
39+ Rather than taking 1 .5s, the specs below run in parallel, completing in just
40+ over 500ms .
3941
4042``` javascript
4143var parallel = require (' ../index.js' );
4244var Promise = require (' bluebird' );
4345
44- describe (' delays' , function () {
45- var args = [500 , 600 , 700 , 800 , 900 ];
46- parallel (args, args, function (arg ) {
47- return Promise .delay (arg);
46+ parallel (' delays' , function () {
47+ it (' test1' , function (done ) {
48+ setTimeout (done, 500 );
4849 });
49- });
50- ```
51-
52- ```
53- delays
54- ✓ 500 (497ms)
55- ✓ 600 (99ms)
56- ✓ 700 (98ms)
57- ✓ 800 (99ms)
58- ✓ 900 (99ms)
59-
60-
61- 5 passing (902ms)
62- ```
6350
64- An example of passing multiple arguments
65-
66- ``` javascript
67- var parallel = require (' ../index.js' );
68- var Promise = require (' bluebird' );
69- var assert = require (' assert' );
70-
71- describe (' multiplications' , function () {
72- var args = [
73- [1 , 1 , 1 ],
74- [2 , 2 , 4 ],
75- [3 , 3 , 9 ],
76- [4 , 4 , 16 ]
77- ];
78-
79- var names = args .map (function (val ) {
80- return val[0 ] + ' + ' + val[1 ] + ' = ' + val[2 ];
51+ it (' test2' , function (done ) {
52+ setTimeout (done, 500 );
8153 });
8254
83- parallel (names, args, function (x , y , res ) {
84- return Promise .delay (100 ).then (function () {
85- assert .equal (x * y, res)
86- });
55+ it (' test3' , function () {
56+ return Promise .delay (500 );
8757 });
8858});
8959```
9060
9161```
92- multiplications
93- ✓ 1 + 1 = 1 (101ms)
94- ✓ 2 + 2 = 4
95- ✓ 3 + 3 = 9
96- ✓ 4 + 4 = 16
62+ ✓ test1 (506ms)
63+ ✓ test2
64+ ✓ test3
9765
98-
99- 4 passing (110ms)
66+ 3 passing (516ms)
10067```
68+
69+ ## Caveats
70+
71+ Debugging parallel execution can be more difficult as exceptions may be thrown
72+ from any of the running specs.
0 commit comments