Last active
February 25, 2017 17:56
-
-
Save PlasmaPower/57d361a6d0a90c7a5a6aac890cd2322d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const setupRequests = require('../helpers/setup-requests.js'); | |
const assert = require('assert'); | |
const Koa = require('../..'); | |
describe('app.context', () => { | |
const app1 = new Koa(); | |
app1.context.msg = 'hello'; | |
const app2 = new Koa(); | |
it('should merge properties', async () => { | |
app1.use((ctx, next) => { | |
assert.equal(ctx.msg, 'hello'); | |
ctx.status = 204; | |
}); | |
const request = setupRequests(app1); | |
let res = await request('/'); | |
expect(res.status).toBe(204); | |
}); | |
it('should not affect the original prototype', async () => { | |
app2.use((ctx, next) => { | |
assert.equal(ctx.msg, undefined); | |
ctx.status = 204; | |
}); | |
const request = setupRequests(app2); | |
let res = await request('/'); | |
expect(res.status).toBe(204); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const path = require('path'); | |
const fetch = require('node-fetch'); | |
module.exports = (koa) => { | |
let urlBase = new Promise((resolve, reject) => { | |
const server = koa.listen(0, () => { | |
resolve('127.0.0.1:' + server.address().port); | |
}); | |
}); | |
return async (url, options) => { | |
url = 'http://' + path.join(await urlBase, url); | |
return fetch(url, options); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment