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

Commit fe32dd4

Browse files
committedOct 30, 2015
more test
1 parent 26a740e commit fe32dd4

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed
 

Diff for: ‎package.json

+4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
"co": "^4.6.0"
2626
},
2727
"devDependencies": {
28+
"koa-compose": "^3.0.0",
2829
"mocha": "^2.3.3",
2930
"standard": "^5.3.1"
31+
},
32+
"engines": {
33+
"node": ">= 4"
3034
}
3135
}

Diff for: ‎test.js

+57-12
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33
'use strict'
44

5-
// const co = require('co')
5+
const co = require('co')
66
const assert = require('assert')
77
const convert = require('./index')
8+
const compose = require('koa-compose')
89

9-
describe('Koa Convert', function () {
10-
it('should works', function (done) {
10+
describe('Koa Convert', () => {
11+
it('should works', () => {
1112
let call = []
1213
let ctx = {}
1314
let mw = convert(function * (next) {
1415
assert.ok(ctx === this)
1516
call.push(1)
1617
})
1718

18-
mw(ctx, function () {
19-
done(new Error('this should not be called'))
19+
return mw(ctx, function () {
20+
call.push(2)
2021
}).then(function () {
2122
assert.deepEqual(call, [1])
22-
done()
2323
})
2424
})
2525

26-
it('should works with `yield next`', function (done) {
26+
it('should works with `yield next`', () => {
2727
let call = []
2828
let ctx = {}
2929
let mw = convert(function * (next) {
@@ -33,16 +33,15 @@ describe('Koa Convert', function () {
3333
call.push(3)
3434
})
3535

36-
mw(ctx, function () {
36+
return mw(ctx, function () {
3737
call.push(2)
3838
return Promise.resolve()
3939
}).then(function () {
4040
assert.deepEqual(call, [1, 2, 3])
41-
done()
4241
})
4342
})
4443

45-
it('should works with `yield* next`', function (done) {
44+
it('should works with `yield* next`', () => {
4645
let call = []
4746
let ctx = {}
4847
let mw = convert(function * (next) {
@@ -52,12 +51,58 @@ describe('Koa Convert', function () {
5251
call.push(3)
5352
})
5453

55-
mw(ctx, function () {
54+
return mw(ctx, function () {
5655
call.push(2)
5756
return Promise.resolve()
5857
}).then(function () {
5958
assert.deepEqual(call, [1, 2, 3])
60-
done()
59+
})
60+
})
61+
62+
it('should works with koa-compose', () => {
63+
let call = []
64+
let context = {}
65+
let _context
66+
let mw = compose([
67+
function * name (next) {
68+
call.push(1)
69+
yield next
70+
call.push(11)
71+
},
72+
(ctx, next) => {
73+
call.push(2)
74+
return next().then(() => {
75+
call.push(10)
76+
})
77+
},
78+
function * (next) {
79+
call.push(3)
80+
yield* next
81+
call.push(9)
82+
},
83+
co.wrap(function * (ctx, next) {
84+
call.push(4)
85+
yield next()
86+
call.push(8)
87+
}),
88+
function * (next) {
89+
try {
90+
call.push(5)
91+
yield next
92+
} catch (e) {
93+
call.push(7)
94+
}
95+
},
96+
(ctx, next) => {
97+
_context = ctx
98+
call.push(6)
99+
throw new Error()
100+
}
101+
].map(convert))
102+
103+
return mw(context).then(() => {
104+
assert.equal(context, _context)
105+
assert.deepEqual(call, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
61106
})
62107
})
63108
})

0 commit comments

Comments
 (0)
This repository has been archived.