New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mocha.parallel

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha.parallel - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

fixtures/contextSkip.js

3

fixtures/index.js

@@ -6,3 +6,4 @@ var path = require('path');

'uncaughtException', 'parallelSkip', 'skip', 'only', 'parallelOnly',
'failure', 'assertionFailure', 'parentHooks', 'sync'];
'failure', 'assertionFailure', 'parentHooks', 'sync', 'contextSkip',
'contextTimeout'];

@@ -9,0 +10,0 @@ fixtures.forEach(function(fixture) {

@@ -11,3 +11,4 @@ var Promise = require('bluebird');

* suites. parallel.only() and it.only() may be used to only wait on the
* specified specs and suites.
* specified specs and suites. Runnable contexts are bound, so this.skip()
* may be used from within a spec, but this.timeout() is not supported.
*

@@ -94,2 +95,20 @@ * @example

specs.forEach(function(spec) {
if (spec.skip) {
return it.skip(spec.name);
}
(spec.only ? it.only : it)(spec.name, function() {
if (spec.error) throw spec.error;
return spec.promise.then(function() {
if (spec.error) throw spec.error;
});
});
});
// Retrieve spec contexts from suite
this.tests.forEach(function(test, i) {
specs[i].ctx = test.ctx;
});
before(function() {

@@ -109,15 +128,2 @@ // Before hook exceptions are handled by mocha

});
specs.forEach(function(spec) {
if (spec.skip) {
return it.skip(spec.name);
}
(spec.only ? it.only : it)(spec.name, function() {
if (spec.error) throw spec.error;
return spec.promise.then(function() {
if (spec.error) throw spec.error;
});
});
});
});

@@ -159,33 +165,30 @@ }

it = function it(name, fn) {
specs.push({
var createSpec = function(name, fn, opts) {
opts = opts || {};
var spec = {
name: name,
getPromise: createWrapper(fn),
only: null,
skip: null,
ctx: null,
getPromise: function() {
return createWrapper(fn, spec.ctx)();
},
only: opts.only || null,
skip: opts.skip || null,
error: null,
promise: null
});
};
specs.push(spec);
};
it = function it(name, fn) {
createSpec(name, fn);
};
it.skip = function skip(name, fn) {
specs.push({
name: name,
getPromise: createWrapper(fn),
only: null,
skip: true,
error: null,
promise: null
});
createSpec(name, fn, {skip: true});
};
it.only = function skip(name, fn) {
specs.push({
name: name,
getPromise: createWrapper(fn),
only: true,
skip: null,
error: null,
promise: null
});
it.only = function only(name, fn) {
createSpec(name, fn, {only: true});
};

@@ -226,14 +229,18 @@

* Returns a wrapper for a given runnable's fn, including specs or hooks.
* Optionally binds the function handler to the passed context.
*
* @param {function} fn
* @param {function} [ctx]
* @returns {function}
*/
function createWrapper(fn) {
function createWrapper(fn, ctx) {
return function() {
return new Promise(function(resolve, reject) {
var res = fn(function(err) {
var cb = function(err) {
if (err) return reject(err);
resolve();
});
};
var res = fn.call(ctx || this, cb);
// Synchronous spec, or using promises rather than callbacks

@@ -240,0 +247,0 @@ if (!fn.length || (res && res.then)) {

{
"name": "mocha.parallel",
"version": "0.8.0",
"version": "0.9.0",
"description": "Run async mocha specs in parallel",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -31,3 +31,4 @@ # mocha.parallel

* suites. parallel.only() and it.only() may be used to only wait on the
* specified specs and suites.
* specified specs and suites. Runnable contexts are bound, so this.skip()
* may be used from within a spec, but this.timeout() is not supported.
*

@@ -34,0 +35,0 @@ * @example

@@ -199,2 +199,15 @@ var exec = require('child_process').exec;

});
it('supports this.skip() from a spec', function(done) {
var cmd = './node_modules/.bin/mocha ' + fixtures.contextSkip;
exec(cmd, function(err, stdout, stderr) {
if (err) return done(err);
assert(!stderr.length);
assert(stdout.indexOf('2 passing') !== -1);
assert(stdout.indexOf('1 pending') !== -1);
done();
});
});
});

@@ -201,0 +214,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc