express-router-api
Advanced tools
Comparing version 1.1.1 to 1.2.0
{ | ||
"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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29743
2
8
693
9
1
+ Addedrxjs@^6.3.3
+ Addedrxjs@6.6.7(transitive)
+ Addedtslib@1.14.1(transitive)
- Removedbluebird@^3.4.6
- Removedpromise-resolve-deep@^1.0.0
- Removedbluebird@3.7.2(transitive)
- Removedpromise-resolve-deep@1.1.1(transitive)