Socket
Socket
Sign inDemoInstall

middleware-flow

Package Overview
Dependencies
6
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.6.0 to 0.6.1

8

index.js

@@ -48,5 +48,9 @@ var createCount = require('callback-count');

if (conditional.else[0].length === 4) {
conditional.else[0] = conditional.else[0].bind(null, err);
var newElse = conditional.else.slice(); // shallow clone
newElse[0] = newElse[0].bind(null, err);
flow.series.apply(null, newElse)(req, res, next);
}
flow.series.apply(null, conditional.else)(req, res, next);
else {
flow.series.apply(null, conditional.else)(req, res, next);
}
} else {

@@ -53,0 +57,0 @@ next();

{
"name": "middleware-flow",
"version": "0.6.0",
"version": "0.6.1",
"description": "Middleware control flow library: series, parallel, or, and",

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

@@ -8,2 +8,3 @@ var express = require('express');

middlewares.forEach(function (mw) {
app.use(express.bodyParser());
app.use(mw);

@@ -10,0 +11,0 @@ });

@@ -98,2 +98,24 @@ var createCount = require('callback-count');

});
it('should run middleware passed to else if the mw next(err) (and pass correct error message - shared scope test)', function(done) {
var app = createAppWithMiddleware(
mwIf(function (req, res, next) {
next(new Error(req.body.message));
})
.then(res.send('skip success'))
.else(function (err, req, res, next) {
res.send(err.message);
})
);
var count = createCount(done);
request(app)
.post('/')
.send({message:'one'})
.expect('one')
.end(count.inc().next);
request(app)
.post('/')
.send({message:'two'})
.expect('two')
.end(count.inc().next);
});
});

@@ -17,2 +17,3 @@ var createCount = require('callback-count');

var extendErrMessage = errMw.extendErrMessage;
var createCount = require('callback-count');

@@ -113,3 +114,3 @@ var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');

.end(done);
});
});
it('should pass error to first mw catch', function (done) {

@@ -134,2 +135,34 @@ var app = createAppWithMiddleware(

});
it('should pass error to first mw catch (and pass correct error message - shared scope test)', function (done) {
var app = createAppWithMiddleware(
flow.each([1],
flow
.try(
function (eachReq, res, next) {
var err = new Error(eachReq.body.message);
next(err); // next the error
}
)
.catch(
function(err, eachReq, res, next) {
res.send(err.message);
}
)),
res.send('nocaught')
);
var countZ = createCount(done);
var num;
num = 100;
request(app)
.post('/')
.send({ message: 'foo' })
.expect('foo')
.end(countZ.inc().next);
num = 90;
request(app)
.post('/')
.send({ message: 'bar' })
.expect('bar')
.end(countZ.inc().next);
});
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc