Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
add test for migration snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
gyson committed Nov 1, 2015
1 parent 1ee4700 commit 87fc958
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
"koa-compose": "^3.0.0"
},
"devDependencies": {
"koa": "^2.0.0-alpha.2",
"mocha": "^2.3.3",
"standard": "^5.3.1"
"standard": "^5.3.1",
"supertest": "^1.1.0"
},
"engines": {
"node": ">= 4"
Expand Down
47 changes: 47 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
'use strict'

const co = require('co')
const Koa = require('koa')
const assert = require('assert')
const convert = require('./index')
const request = require('supertest')

describe('convert()', () => {
it('should work', () => {
Expand Down Expand Up @@ -140,3 +142,48 @@ describe('convert.compose()', () => {
})
})
})

describe('migration snippet', () => {
let app = new Koa()

// snippet
const _use = app.use
app.use = x => _use.call(app, convert(x))
// end

app.use((ctx, next) => {
ctx.body = [1]
return next().then(() => {
ctx.body.push(9)
})
})

app.use(function * (next) {
this.body.push(2)
yield next
this.body.push(8)
})

app.use(function * (next) {
this.body.push(3)
yield* next
this.body.push(7)
})

app.use(co.wrap(function * (ctx, next) {
ctx.body.push(4)
yield next()
ctx.body.push(6)
}))

app.use(ctx => {
ctx.body.push(5)
})

it('should work', done => {
request(app.callback())
.get('/')
.expect(200, [1, 2, 3, 4, 5, 6, 7, 8, 9])
.end(done)
})
})

0 comments on commit 87fc958

Please sign in to comment.