Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-router-api

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-router-api - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

dist/index.d.ts

20

package.json
{
"name": "express-router-api",
"version": "1.1.1",
"version": "1.2.0",
"description": "Express router that lets you construct your API entirely on promises",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {

@@ -12,11 +13,14 @@ "test": "mocha test"

"dependencies": {
"promise-resolve-deep": "^1.0.0",
"bluebird": "^3.4.6"
"rxjs": "^6.3.3"
},
"devDependencies": {
"@types/express": "^4.16.0",
"@types/methods": "^1.1.0",
"bluebird": "^3.5.2",
"chai": "^3.5.0",
"express": "^4.13.4",
"mocha": "^2.4.5",
"request": "^2.75.0",
"request-promise": "^4.1.1"
"express": "^4.16.4",
"mocha": "^5.2.0",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"typescript": "^3.1.3"
},

@@ -23,0 +27,0 @@ "peerDependencies": {

98

test.js

@@ -6,6 +6,6 @@ 'use strict';

let rp = require('request-promise');
let ExpressApiRouter = require('./');
let ApiError = ExpressApiRouter.ApiError;
let { ExpressApiRouter, ApiError} = require('./dist');
let assert = require('chai').assert;
let Promise = require('bluebird');
const { of } = require('rxjs');

@@ -62,16 +62,8 @@ let checkFor = (val) => {

it('should support old style usage', () => {
let resolveErrorPromise;;
let errorPromise = new Promise((resolve, reject) => {
resolveErrorPromise = resolve;
});
it('should support old style usage', async () => {
routeTest((req, res) => {
res.once('expressApiRouterError', () => {
resolveErrorPromise();
});
res.send('test');
});
return Promise.all([requestTest('test'), errorPromise]);
return requestTest('test');
});

@@ -91,2 +83,22 @@

it('should support observables', () => {
routeTest((req, res) => {
return of({foo: 'bar'});
});
return requestTest({
foo: 'bar'
});
});
it('should support embedded observables', () => {
routeTest((req, res) => {
return {foo: of('bar') };
});
return requestTest({
foo: 'bar'
});
});
it('should support plain object', () => {

@@ -131,39 +143,3 @@ routeTest((req, res) => {

});
it('should support embedded promise in embedded promise', () => {
routeTest((req, res) => {
return Promise.delay(10).then(() => ({
foo: Promise.delay(20).then(() => ({
bar: {
foo: Promise.resolve('test')
}
}))
}));
});
return requestTest({
foo: {bar: {foo: 'test'}}
});
});
it('should support embedded promise array with a possible null', () => {
routeTest((req, res) => {
return Promise.resolve({
foo: Promise.resolve({
bar: [Promise.resolve('foo'),Promise.resolve({
xx: Promise.delay(10).then(()=>'ala'),
dd: null,
zz: true,
yy: false,
mm: undefined
})]
})
})
});
return requestTest({
foo: {bar: ['foo', {xx: 'ala', dd: null, zz: true, yy: false}]}
});
});
it('should support reporting JSON errors', () => {

@@ -193,3 +169,3 @@ routeTest((req, res) => {

router.setErrorFormatter(err => {
return {message: err.message};
return {data: err.message};
});

@@ -204,3 +180,19 @@

return requestTest({
message: 'foo'
data: 'foo'
}, 500)
});
it('should support custom error formatter for formatting ApiError', () => {
router.setErrorFormatter(err => {
return {data: err.message};
});
routeTest((req, res) => {
return Promise.delay(10).then(() => {
throw new ApiError('foo', 200);
});
});
return requestTest({
data: 'foo'
}, 500)

@@ -210,3 +202,3 @@

it('should support re-throwing ApiError from error formatter', () => {
it('should report internal server error when error formatter fails', () => {
router.setErrorFormatter(err => {

@@ -223,4 +215,4 @@ throw new ApiError({message: err.message}, 403);

return requestTest({
message: 'foo'
}, 403)
error: 'Internal server error'
}, 500)
});

@@ -227,0 +219,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