Skip to content

Commit

Permalink
fix(deps/tests): add missing koa-compose@3 dep; add tests for koa@1
Browse files Browse the repository at this point in the history
now there are tests for both `koa@1` and `koa@2`, one beer for @apiep, very thanks!

Closes tunnckoCore/koa-rest-router#10
  • Loading branch information
tunnckoCore committed Oct 22, 2016
1 parent f29ee52 commit 2508e5e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3,149 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"extend-shallow": "^2.0.1",
"is-es6-generator-function": "^1.0.0",
"koa-compose": "^3.1.0",
"koa-convert": "^1.2.0",
"lazy-cache": "^2.0.1",
"methods": "^1.1.2",
Expand All @@ -34,8 +35,9 @@
"coveralls": "^2.11.12",
"cz-conventional-changelog": "^1.2.0",
"is-es6-generator-function": "^1.0.0",
"koa": "^2.0.0-alpha.7",
"koa": "^1.2.4",
"koa-better-body": "^3.0.2",
"koa2": "^2.0.0-alpha.7",
"mukla": "^0.4.1",
"nyc": "^8.1.0",
"pre-commit": "^1.1.3",
Expand Down
31 changes: 28 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

'use strict'

var request = require('supertest')
let request = require('supertest')
let test = require('mukla')
let Koa = require('koa')
var isGen = require('is-es6-generator-function')
let koa1 = require('koa')
let Koa = require('koa2')
let isGen = require('is-es6-generator-function')
let Router = require('./index')
let router = Router()
let app = new Koa()
Expand Down Expand Up @@ -346,3 +347,27 @@ test('should `.extend` throw TypeError if `router` is not correct instance', fun
test.throws(fixture, /expect `router` to be instance of KoaBetterRouter/)
done()
})

test('should work on koa@1 with `.legacyMiddleware`', function (done) {
let router = Router().addRoute('GET /is-it-working', (ctx, next) => {
ctx.body = 'yea, confirmed'
return next()
})
let app = koa1()

app.use(router.legacyMiddleware())
request(app.callback())
.get('/is-it-working')
.expect('yea, confirmed')
.expect(200, done)
})

test('should throw error on `koa@1` using `.middleware`', function (done) {
function fixture () {
let failing = Router().addRoute('GET /foo', () => {})
koa1().use(failing.middleware())
}
test.throws(fixture, Error)
test.throws(fixture, /requires a generator function/)
done()
})
Loading

0 comments on commit 2508e5e

Please sign in to comment.