Skip to content

Commit

Permalink
use typescript@2.0.0
Browse files Browse the repository at this point in the history
use @types as typing dependency
refined tests
  • Loading branch information
joesonw committed Jul 21, 2016
1 parent 3966f83 commit defbbfc
Show file tree
Hide file tree
Showing 34 changed files with 123 additions and 22,146 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules/
builds/
dist/
npm-debug.log
coverage/
.DS_Storage
test-dist
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- 4
- 6
sudo: false
before_script: "alias gulp='node --harmony `which gulp`'"
script: "npm install; npm test"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
before_script: npm i istanbul mocha typescript@next -g
script: npm install; npm test
after_script: npm run coverage && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls
74 changes: 0 additions & 74 deletions gulpfile.js

This file was deleted.

40 changes: 21 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
{
"name": "ts-router",
"version": "0.1.3",
"version": "0.2.0",
"description": "koa router middleware, typescript fully supported, jersey like coding",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "node --harmony `which gulp` test",
"install": "gulp build;gulp install"
"test": "rm -rf test-dist;tsc -p tsconfig.test.json;mocha test-dist/test/*.js",
"coverage": "rm -rf test-dist;tsc -p tsconfig.test.json;istanbul cover _mocha test-dist/test/*.js",
"install": "./node_modules/.bin/tsc -p tsconfig.json"
},
"dependencies": {
"co-body": "^4.0.0",
"@types/chai": "^3.4.29",
"@types/koa": "^2.0.29",
"@types/lodash": "0.0.28",
"@types/mocha": "^2.2.28",
"@types/path-to-regexp": "^1.0.28",
"@types/supertest": "^1.1.27",
"co-body": "^4.2.0",
"formidable": "^1.0.17",
"koa": "^2.0.0-alpha.3",
"lodash": "^4.5.1",
"path-to-regexp": "^1.2.1",
"koa": "^2.0.0",
"lodash": "^4.13.1",
"path-to-regexp": "^1.5.3",
"reflect-metadata": "^0.1.3"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-preset-es2015": "^6.5.0",
"fs-extra": "^0.26.5",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-istanbul": "^0.10.3",
"gulp-mocha": "^2.2.0",
"gulp-typescript": "^2.12.0",
"merge2": "^1.0.1",
"mocha": "^2.4.5",
"supertest": "^1.2.0"
"chai": "^3.5.0",
"istanbul": "^0.4.4",
"mocha": "^2.5.3",
"supertest": "^1.2.0",
"typescript": "^2.1.0-dev.20160721"
},
"engines": {
"node": ">=4.0.0"
"node": ">=6.0.0"
},
"repository": {
"type": "git",
Expand Down
3 changes: 1 addition & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Cookie from './cookie';
/// <reference path="../typings/koa/koa.d.ts"/>
import * as Koa from 'koa';

interface Context extends Koa.IContext{
interface Context extends Koa.Context{
cookie?: Cookie;
params?: Object;
requestBody?: any;
Expand Down
6 changes: 2 additions & 4 deletions src/response.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/// <reference path="../typings/koa/koa.d.ts"/>
import * as Koa from 'koa';
import Cookie from './cookie';
import {Charset, HttpMethod, MediaType, mediaTypeToString} from './util';
import Context from './context';



class Response {
static status(status: number | Response.Status):ResponseBuilder {
let ret = new ResponseBuilder();
Expand Down Expand Up @@ -70,6 +68,8 @@ namespace Response {
};
}

export default Response;

export class ResponseBuilder {
private _status: number = 404;
private _headers: { [key:string] : string} = {};
Expand Down Expand Up @@ -155,5 +155,3 @@ export class ResponseBuilder {
return ret;
}
}

export default Response;
10 changes: 3 additions & 7 deletions src/router.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/// <reference path="../typings/koa/koa.d.ts"/>
/// <reference path="../typings/path-to-regexp/path-to-regexp.d.ts"/>
/// <reference path="../typings/lodash/lodash.d.ts"/>

import * as Koa from 'koa';
import * as pathToRegexp from 'path-to-regexp';
import * as _ from 'lodash';
Expand Down Expand Up @@ -38,9 +34,9 @@ class Router {
constructor() {
}

routes(): (ctx:Koa.IContext, next:Promise<void>) => Promise<void> {
routes(): (ctx:Koa.Context, next:Function) => Promise<void> {
let self = this;
return async function (context:Koa.IContext, next:Promise<void>):Promise<void> {
return async function (context:Koa.Context, next:Function):Promise<void> {
let matchedRoute;
let params = {};
let afters = [];
Expand Down Expand Up @@ -189,7 +185,7 @@ class Router {
}
await router[after.route](...p);
}
await next;
await next();
router = null;
klass = null;
response = null;
Expand Down
5 changes: 2 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Cookie from './cookie';
/// <reference path="../typings/koa/koa.d.ts"/>
import * as Koa from 'koa';
const formy:any = require('formidable');
export enum MediaType {
Expand Down Expand Up @@ -29,7 +28,7 @@ export function mediaTypeToString(type: MediaType):string {
return 'multipart/form-data';
}
}
export interface Context extends Koa.IContext{
export interface Context extends Koa.Context{
cookie: Cookie;
}

Expand All @@ -42,7 +41,7 @@ export class ReflectType {
}


export function parseMulti(ctx: Koa.IContext, opts?: any):Promise<any> {
export function parseMulti(ctx: Koa.Context, opts?: any):Promise<any> {
opts = opts || {};
return new Promise<any>((resolve, reject) => {
var fields = {};
Expand Down
14 changes: 6 additions & 8 deletions test/after.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
/// <reference path="../typings/chai/chai.d.ts"/>
/// <reference path="../typings/supertest/supertest.d.ts"/>
/// <reference path="../typings/koa/koa.d.ts"/>

import * as tsRouter from '../src';
import * as chai from 'chai';
import * as request from 'supertest';
Expand Down Expand Up @@ -38,13 +33,16 @@ const app = new Koa();
const router = new tsRouter.Router();
router.use(TestController);
app.use(router.routes());
let server = app.listen();
let server;
describe('GET with path paramters with afterwares', () => {
before(() => {
server = app.listen(3000)
})
after(() => {
server.close();
})
it('response paramters in back in json', function (done) {
request(app.listen())
it('should respond paramters in back in json', function (done) {
request(server)
.get('/test/hello/world')
.expect('Content-Type', 'application/json')
.expect({
Expand Down
14 changes: 6 additions & 8 deletions test/before.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
/// <reference path="../typings/chai/chai.d.ts"/>
/// <reference path="../typings/supertest/supertest.d.ts"/>
/// <reference path="../typings/koa/koa.d.ts"/>

import * as tsRouter from '../src';
import * as chai from 'chai';
import * as request from 'supertest';
Expand Down Expand Up @@ -36,13 +31,16 @@ const app = new Koa();
const router = new tsRouter.Router();
router.use(TestController);
app.use(router.routes());
let server = app.listen();
let server;
describe('GET with path paramters with beforewares', () => {
before(() => {
server = app.listen(3000)
})
after(() => {
server.close();
})
it('response paramters in back in json', function (done) {
request(app.listen())
it('should respond paramters in back in json', function (done) {
request(server)
.get('/test/hello/world')
.expect('Content-Type', 'application/json')
.expect({
Expand Down
18 changes: 8 additions & 10 deletions test/body.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
/// <reference path="../typings/chai/chai.d.ts"/>
/// <reference path="../typings/supertest/supertest.d.ts"/>
/// <reference path="../typings/koa/koa.d.ts"/>

import * as tsRouter from '../src';
import * as chai from 'chai';
import * as request from 'supertest';
Expand Down Expand Up @@ -51,13 +46,16 @@ const app = new Koa();
const router = new tsRouter.Router();
router.use(TestController);
app.use(router.routes());
let server = app.listen();
let server;
describe('POST with body', () => {
before(() => {
server = app.listen(3000)
})
after(() => {
server.close();
});
it('response body back in json', function (done) {
request(app.listen())
it('should respond body back in json', function (done) {
request(server)
.post('/test')
.send({
v1: 'hello',
Expand All @@ -75,8 +73,8 @@ describe('POST with body', () => {
})
.expect(200, done);
});
it('response body back in json', function (done) {
request(app.listen())
it('should route to correct subroute and respond body back in json', function (done) {
request(server)
.post('/test/2')
.send({
v1: 'hello',
Expand Down
14 changes: 6 additions & 8 deletions test/delete.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
/// <reference path="../typings/chai/chai.d.ts"/>
/// <reference path="../typings/supertest/supertest.d.ts"/>
/// <reference path="../typings/koa/koa.d.ts"/>

import * as tsRouter from '../src';
import * as chai from 'chai';
import * as request from 'supertest';
Expand All @@ -21,13 +16,16 @@ const app = new Koa();
const router = new tsRouter.Router();
router.use(TestController);
app.use(router.routes());
let server = app.listen();
let server;
describe('DELETE plain text', () => {
before(() => {
server = app.listen(3000)
})
after(() => {
server.close();
})
it('response plain text', function (done) {
request(app.listen())
it('should respond plain text', function (done) {
request(server)
.del('/test')
.expect('Content-Type', 'text/plain')
.expect('hello')
Expand Down
Loading

0 comments on commit defbbfc

Please sign in to comment.