use Buffer.from instead (#946)
This commit is contained in:
parent
682d7b484a
commit
18d753ca2d
5 changed files with 11 additions and 11 deletions
|
@ -13,7 +13,7 @@ while (n--) {
|
||||||
app.use((ctx, next) => next());
|
app.use((ctx, next) => next());
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = new Buffer('Hello World');
|
const body = Buffer.from('Hello World');
|
||||||
|
|
||||||
app.use((ctx, next) => next().then(() => ctx.body = body));
|
app.use((ctx, next) => next().then(() => ctx.body = body));
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ describe('app.respond', () => {
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(ctx => {
|
app.use(ctx => {
|
||||||
ctx.body = new Buffer('hello world');
|
ctx.body = Buffer.from('hello world');
|
||||||
});
|
});
|
||||||
|
|
||||||
const server = app.listen();
|
const server = app.listen();
|
||||||
|
@ -513,7 +513,7 @@ describe('app.respond', () => {
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(ctx => {
|
app.use(ctx => {
|
||||||
ctx.body = new Buffer('Hello');
|
ctx.body = Buffer.from('Hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
const server = app.listen();
|
const server = app.listen();
|
||||||
|
@ -521,7 +521,7 @@ describe('app.respond', () => {
|
||||||
return request(server)
|
return request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect(new Buffer('Hello'));
|
.expect(Buffer.from('Hello'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe('res.body=', () => {
|
||||||
it('should not override', () => {
|
it('should not override', () => {
|
||||||
const res = response();
|
const res = response();
|
||||||
res.type = 'png';
|
res.type = 'png';
|
||||||
res.body = new Buffer('something');
|
res.body = Buffer.from('something');
|
||||||
assert('image/png' == res.header['content-type']);
|
assert('image/png' == res.header['content-type']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -113,13 +113,13 @@ describe('res.body=', () => {
|
||||||
describe('when a buffer is given', () => {
|
describe('when a buffer is given', () => {
|
||||||
it('should default to an octet stream', () => {
|
it('should default to an octet stream', () => {
|
||||||
const res = response();
|
const res = response();
|
||||||
res.body = new Buffer('hey');
|
res.body = Buffer.from('hey');
|
||||||
assert('application/octet-stream' == res.header['content-type']);
|
assert('application/octet-stream' == res.header['content-type']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set length', () => {
|
it('should set length', () => {
|
||||||
const res = response();
|
const res = response();
|
||||||
res.body = new Buffer('Tobi');
|
res.body = Buffer.from('Tobi');
|
||||||
assert('4' == res.header['content-length']);
|
assert('4' == res.header['content-length']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,11 +37,11 @@ describe('res.length', () => {
|
||||||
res.body = 'foo';
|
res.body = 'foo';
|
||||||
res.length.should.equal(3);
|
res.length.should.equal(3);
|
||||||
|
|
||||||
res.body = new Buffer('foo bar');
|
res.body = Buffer.from('foo bar');
|
||||||
res.remove('Content-Length');
|
res.remove('Content-Length');
|
||||||
res.length.should.equal(7);
|
res.length.should.equal(7);
|
||||||
|
|
||||||
res.body = new Buffer('foo bar');
|
res.body = Buffer.from('foo bar');
|
||||||
res.length.should.equal(7);
|
res.length.should.equal(7);
|
||||||
|
|
||||||
res.body = { hello: 'world' };
|
res.body = { hello: 'world' };
|
||||||
|
|
|
@ -41,7 +41,7 @@ describe('res.writable', () => {
|
||||||
describe('when socket closed before response sent', () => {
|
describe('when socket closed before response sent', () => {
|
||||||
function requsetClosed(server){
|
function requsetClosed(server){
|
||||||
const port = server.address().port;
|
const port = server.address().port;
|
||||||
const buf = new Buffer('GET / HTTP/1.1\r\nHost: localhost:' + port + '\r\nConnection: keep-alive\r\n\r\n');
|
const buf = Buffer.from('GET / HTTP/1.1\r\nHost: localhost:' + port + '\r\nConnection: keep-alive\r\n\r\n');
|
||||||
const client = net.connect(port);
|
const client = net.connect(port);
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
client.write(buf);
|
client.write(buf);
|
||||||
|
@ -66,7 +66,7 @@ describe('res.writable', () => {
|
||||||
describe('when response finished', () => {
|
describe('when response finished', () => {
|
||||||
function request(server){
|
function request(server){
|
||||||
const port = server.address().port;
|
const port = server.address().port;
|
||||||
const buf = new Buffer('GET / HTTP/1.1\r\nHost: localhost:' + port + '\r\nConnection: keep-alive\r\n\r\n');
|
const buf = Buffer.from('GET / HTTP/1.1\r\nHost: localhost:' + port + '\r\nConnection: keep-alive\r\n\r\n');
|
||||||
const client = net.connect(port);
|
const client = net.connect(port);
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
client.write(buf);
|
client.write(buf);
|
||||||
|
|
Loading…
Reference in a new issue