From a55a403f379bb0f59bbe92280b498a19ac64eb51 Mon Sep 17 00:00:00 2001 From: remojansen Date: Thu, 2 Nov 2017 02:56:27 +0000 Subject: [PATCH 1/2] Upgraded dependencies --- .gitignore | 1 + .npmignore | 3 +- package.json | 48 +++++++++++++-------------- src/decorators.ts | 7 ++-- src/interfaces.ts | 2 +- src/server.ts | 9 +++-- test/framework.test.ts | 75 ++++++++++++++++++++++++------------------ test/server.test.ts | 23 +++++++------ tslint.json | 2 +- 9 files changed, 96 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index 1f5821d..05afade 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ test/**/*.js type_definitions/**/*.js type_definitions/*.js +package-lock.json \ No newline at end of file diff --git a/.npmignore b/.npmignore index b0eede3..1a75997 100644 --- a/.npmignore +++ b/.npmignore @@ -19,4 +19,5 @@ wallaby.js .travis.yml .gitignore .vscode -type_definitions \ No newline at end of file +type_definitions +package-lock.json \ No newline at end of file diff --git a/package.json b/package.json index 38fb9a6..86ac6e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "inversify-restify-utils", - "version": "3.2.0", + "version": "3.3.0", "description": "Some utilities for the development of restify applications with Inversify", "main": "lib/index.js", "jsnext:main": "es/index.js", @@ -27,30 +27,30 @@ }, "homepage": "https://github.com/inversify/inversify-restify-utils#readme", "devDependencies": { - "@types/chai": "^4.0.2", - "@types/mocha": "^2.2.31", - "@types/node": "^8.0.9", - "@types/restify": "^5.0.2", - "@types/sinon": "^2.1.0", - "@types/supertest": "^2.0.0", - "chai": "^4.1.0", - "gulp": "^3.9.1", - "gulp-istanbul": "^1.0.0", - "gulp-mocha": "^4.0.1", - "gulp-tslint": "^7.0.0", - "gulp-typescript": "^3.0.2", - "inversify": "^4.0.0", - "mocha": "^3.1.1", - "publish-please": "^2.1.4", - "reflect-metadata": "^0.1.3", - "run-sequence": "^1.2.0", - "sinon": "^3.0.0", - "source-map-support": "^0.4.14", - "supertest": "^3.0.0", - "tslint": "^5.0.0", - "typescript": "^2.2.0" + "@types/chai": "4.0.4", + "@types/mocha": "2.2.44", + "@types/node": "8.0.47", + "@types/restify": "5.0.6", + "@types/sinon": "2.3.7", + "@types/supertest": "2.0.3", + "chai": "4.1.2", + "gulp": "3.9.1", + "gulp-istanbul": "1.1.2", + "gulp-mocha": "3.0.1", + "gulp-tslint": "8.1.2", + "gulp-typescript": "3.2.3", + "inversify": "4.5.0", + "mocha": "4.0.1", + "publish-please": "2.3.1", + "reflect-metadata": "0.1.10", + "run-sequence": "2.2.0", + "sinon": "4.0.2", + "source-map-support": "0.5.0", + "supertest": "3.0.0", + "tslint": "5.8.0", + "typescript": "2.6.1" }, "dependencies": { - "restify": "^6.0.0" + "restify": "6.2.3" } } diff --git a/src/decorators.ts b/src/decorators.ts index 4b7f234..d9b43c1 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -37,8 +37,11 @@ export function Options(options: interfaces.RouteOptions, ...middleware: interfa } export function Method( - method: string, options: interfaces.RouteOptions, ...middleware: interfaces.Middleware[]): interfaces.HandlerDecorator { - return function (target: any, key: string, value: any) { + method: string, + options: interfaces.RouteOptions, + ...middleware: interfaces.Middleware[] +): interfaces.HandlerDecorator { + return function (target: any, key: string) { let metadata: interfaces.ControllerMethodMetadata = {options, middleware, method, target, key}; let metadataList: interfaces.ControllerMethodMetadata[] = []; diff --git a/src/interfaces.ts b/src/interfaces.ts index eac7c15..50c2b02 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -4,7 +4,7 @@ import { interfaces as inversifyInterfaces } from "inversify"; namespace interfaces { export type Middleware = (inversifyInterfaces.ServiceIdentifier | restify.RequestHandler); - + export interface ControllerMetadata { path: string; middleware: Middleware[]; diff --git a/src/server.ts b/src/server.ts index 99f3714..8f2974e 100644 --- a/src/server.ts +++ b/src/server.ts @@ -17,11 +17,14 @@ export class InversifyRestifyServer { * * @param container Container loaded with all controllers and their dependencies. */ - constructor(container: inversify.interfaces.Container, opts?: restify.ServerOptions | interfaces.ServerOptions) { + constructor(container: inversify.interfaces.Container, opts?: (restify.ServerOptions & interfaces.ServerOptions)) { this.container = container; this.app = restify.createServer(opts as restify.ServerOptions); - if (opts && opts.hasOwnProperty("defaultRoot") && - typeof (opts as interfaces.ServerOptions).defaultRoot === "string") { + if ( + opts && + opts.hasOwnProperty("defaultRoot") && + typeof (opts as interfaces.ServerOptions).defaultRoot === "string" + ) { this.defaultRoot = (opts as interfaces.ServerOptions).defaultRoot as string; } } diff --git a/test/framework.test.ts b/test/framework.test.ts index 62294a0..e7ed3af 100644 --- a/test/framework.test.ts +++ b/test/framework.test.ts @@ -27,7 +27,7 @@ describe("Integration Tests:", () => { @injectable() @Controller("/") class TestController { - @Get("/") public getTest(req: restify.Request, res: restify.Response) { + @Get("/") public getTest() { return new Promise(((resolve) => { setTimeout(resolve, 100, "GET"); })); @@ -46,7 +46,7 @@ describe("Integration Tests:", () => { @injectable() @Controller("/") class TestController { - @Get("/") public getTest(req: restify.Request, res: restify.Response) { + @Get("/") public getTest() { return new Promise(((resolve, reject) => { setTimeout(reject, 100, "GET"); })); @@ -132,18 +132,23 @@ describe("Integration Tests:", () => { } container.bind(TYPE.Controller).to(TestController).whenTargetNamed("TestController"); - server = new InversifyRestifyServer(container, { formatters: { - "application/json": function formatFoo(req: restify.Request, res: restify.Response, body: any, cb: any) { - res.setHeader(customHeaderName, customHeaderValue); - return cb(); + server = new InversifyRestifyServer( + container, + { + formatters: { + "application/json": (req: restify.Request, res: restify.Response, body: any) => { + res.setHeader(customHeaderName, customHeaderValue); + return null; + } + } } - } }); + ); request(server.build()) .get("/") .expect(customHeaderName, customHeaderValue) .expect(200, done); }); - + it("should allow server options with defaultRoot", (done) => { let result = {"hello": "world"}; let customHeaderName = "custom-header-name"; @@ -156,12 +161,18 @@ describe("Integration Tests:", () => { } container.bind(TYPE.Controller).to(TestController).whenTargetNamed("TestController"); - server = new InversifyRestifyServer(container, { formatters: { - "application/json": function formatFoo(req: restify.Request, res: restify.Response, body: any, cb: any) { - res.setHeader(customHeaderName, customHeaderValue); - return cb(); + server = new InversifyRestifyServer( + container, + { + defaultRoot: "/v1", + formatters: { + "application/json": (req: restify.Request, res: restify.Response, body: any) => { + res.setHeader(customHeaderName, customHeaderValue); + return null; + } + } } - }, defaultRoot: "/v1" }); + ); request(server.build()) .get("/v1") .expect(customHeaderName, customHeaderValue) @@ -210,9 +221,9 @@ describe("Integration Tests:", () => { request(server.build()) .get("/") .expect(200, "GET", function () { - expect(spyA.calledOnce).to.be.true; - expect(spyB.calledOnce).to.be.true; - expect(spyC.calledOnce).to.be.true; + expect(spyA.calledOnce).to.eq(true); + expect(spyB.calledOnce).to.eq(true); + expect(spyC.calledOnce).to.eq(true); expect(result).to.equal("abc"); done(); }); @@ -231,9 +242,9 @@ describe("Integration Tests:", () => { request(server.build()) .get("/") .expect(200, "GET", function () { - expect(spyA.calledOnce).to.be.true; - expect(spyB.calledOnce).to.be.true; - expect(spyC.calledOnce).to.be.true; + expect(spyA.calledOnce).to.eq(true); + expect(spyB.calledOnce).to.eq(true); + expect(spyC.calledOnce).to.eq(true); expect(result).to.equal("abc"); done(); }); @@ -259,9 +270,9 @@ describe("Integration Tests:", () => { request(server.build()) .get("/") .expect(200, "GET", function () { - expect(spyA.calledOnce).to.be.true; - expect(spyB.calledOnce).to.be.true; - expect(spyC.calledOnce).to.be.true; + expect(spyA.calledOnce).to.eq(true); + expect(spyB.calledOnce).to.eq(true); + expect(spyC.calledOnce).to.eq(true); expect(result).to.equal("abc"); done(); }); @@ -285,9 +296,9 @@ describe("Integration Tests:", () => { request(server.build()) .get("/") .expect(200, "GET", function () { - expect(spyA.calledOnce).to.be.true; - expect(spyB.calledOnce).to.be.true; - expect(spyC.calledOnce).to.be.true; + expect(spyA.calledOnce).to.eq(true); + expect(spyB.calledOnce).to.eq(true); + expect(spyC.calledOnce).to.eq(true); expect(result).to.equal("abc"); done(); }); @@ -311,9 +322,9 @@ describe("Integration Tests:", () => { request(server.build()) .get("/") - .expect(200, "GET", function() { - expect(spyA.calledOnce).to.be.true; - expect(spyB.calledOnce).to.be.true; + .expect(200, "GET", function() { + expect(spyA.calledOnce).to.eq(true); + expect(spyB.calledOnce).to.eq(true); expect(result).to.equal("ab"); done(); }); @@ -339,8 +350,8 @@ describe("Integration Tests:", () => { request(server.build()) .get("/") .expect(200, "GET", function() { - expect(spyA.calledOnce).to.be.true; - expect(spyB.calledOnce).to.be.true; + expect(spyA.calledOnce).to.eq(true); + expect(spyB.calledOnce).to.eq(true); expect(result).to.equal("ab"); done(); }); @@ -366,8 +377,8 @@ describe("Integration Tests:", () => { request(server.build()) .get("/") .expect(200, "GET", function() { - expect(spyA.calledOnce).to.be.true; - expect(spyB.calledOnce).to.be.true; + expect(spyA.calledOnce).to.eq(true); + expect(spyB.calledOnce).to.eq(true); expect(result).to.equal("ab"); done(); }); diff --git a/test/server.test.ts b/test/server.test.ts index 3d7c908..c197b60 100644 --- a/test/server.test.ts +++ b/test/server.test.ts @@ -21,11 +21,11 @@ describe("Unit Test: InversifyRestifyServer", () => { server.setConfig(configFn); - expect(configFn.called).to.be.false; + expect(configFn.called).to.eq(false); server.build(); - expect(configFn.calledOnce).to.be.true; + expect(configFn.calledOnce).to.eq(true); }); it("should generate routes for controller methods", () => { @@ -49,17 +49,17 @@ describe("Unit Test: InversifyRestifyServer", () => { let app = server.build(); let routeOne = app.router.routes.GET.find(route => route.spec.path === "/root/routeOne"); - expect(routeOne).not.to.be.undefined; + expect(routeOne).not.to.eq(undefined); let routeTwo = app.router.routes.GET.find(route => route.spec.path === "/root/routeTwo"); - expect(routeTwo).not.to.be.undefined; + expect(routeTwo).not.to.eq(undefined); expect((routeTwo).spec.options).to.eq("test"); let routeThree = app.router.routes.GET.find(route => route.spec.path === "/root/routeThree"); - expect(routeThree).not.to.be.undefined; + expect(routeThree).not.to.eq(undefined); }); - + it("should generate routes for controller methods using defaultRoot", () => { @injectable() @@ -77,20 +77,23 @@ describe("Unit Test: InversifyRestifyServer", () => { let container = new Container(); container.bind(TYPE.Controller).to(TestController); + let server = new InversifyRestifyServer(container, { defaultRoot: "/v1" }); + let app = server.build(); let routeOne = app.router.routes.GET.find(route => route.spec.path === "/v1/root/routeOne"); - expect(routeOne).not.to.be.undefined; + expect(routeOne).not.to.eq(undefined); let routeTwo = app.router.routes.GET.find(route => route.spec.path === "/v1/root/routeTwo"); - expect(routeTwo).not.to.be.undefined; + expect(routeTwo).not.to.eq(undefined); expect((routeTwo).spec.options).to.eq("test"); - let routeThree = app.router.routes.GET.find(route => route.spec.path === "/v1/root/routeThree"); - expect(routeThree).not.to.be.undefined; + let routeThree = app.router.routes.GET.find(route => route.spec.path === "/v1/root/routeThree"); + expect(routeThree).not.eq(undefined); }); + }); diff --git a/tslint.json b/tslint.json index fdb9b00..736615f 100644 --- a/tslint.json +++ b/tslint.json @@ -1,3 +1,4 @@ + { "rules": { "class-name": true, @@ -34,7 +35,6 @@ "no-switch-case-fall-through": false, "no-trailing-whitespace": true, "no-unused-expression": true, - "no-use-before-declare": true, "no-var-keyword": true, "object-literal-sort-keys": true, "one-line": [true, From f0f7e7c13be80288a37b5da68c1144ac51e5a66b Mon Sep 17 00:00:00 2001 From: remojansen Date: Thu, 2 Nov 2017 03:17:29 +0000 Subject: [PATCH 2/2] Upgraded node version in CI --- .travis.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8417859..a077aa1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,8 @@ language: node_js node_js: - stable -- 5.4.1 -- 5.4.0 -- 5.3.0 -- 5.2.0 -- 5.1.1 -- 4.4.6 +- 8.8.1 +- 7.10.1 before_install: - npm install -g codeclimate-test-reporter after_success: