use Buffer.from instead (#946)

This commit is contained in:
Fangdun Cai 2017-03-20 14:48:37 +08:00 committed by Yiyu He
parent 682d7b484a
commit 18d753ca2d
5 changed files with 11 additions and 11 deletions

View file

@ -13,7 +13,7 @@ while (n--) {
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));

View file

@ -124,7 +124,7 @@ describe('app.respond', () => {
const app = new Koa();
app.use(ctx => {
ctx.body = new Buffer('hello world');
ctx.body = Buffer.from('hello world');
});
const server = app.listen();
@ -513,7 +513,7 @@ describe('app.respond', () => {
const app = new Koa();
app.use(ctx => {
ctx.body = new Buffer('Hello');
ctx.body = Buffer.from('Hello');
});
const server = app.listen();
@ -521,7 +521,7 @@ describe('app.respond', () => {
return request(server)
.get('/')
.expect(200)
.expect(new Buffer('Hello'));
.expect(Buffer.from('Hello'));
});
});

View file

@ -10,7 +10,7 @@ describe('res.body=', () => {
it('should not override', () => {
const res = response();
res.type = 'png';
res.body = new Buffer('something');
res.body = Buffer.from('something');
assert('image/png' == res.header['content-type']);
});
@ -113,13 +113,13 @@ describe('res.body=', () => {
describe('when a buffer is given', () => {
it('should default to an octet stream', () => {
const res = response();
res.body = new Buffer('hey');
res.body = Buffer.from('hey');
assert('application/octet-stream' == res.header['content-type']);
});
it('should set length', () => {
const res = response();
res.body = new Buffer('Tobi');
res.body = Buffer.from('Tobi');
assert('4' == res.header['content-length']);
});
});

View file

@ -37,11 +37,11 @@ describe('res.length', () => {
res.body = 'foo';
res.length.should.equal(3);
res.body = new Buffer('foo bar');
res.body = Buffer.from('foo bar');
res.remove('Content-Length');
res.length.should.equal(7);
res.body = new Buffer('foo bar');
res.body = Buffer.from('foo bar');
res.length.should.equal(7);
res.body = { hello: 'world' };

View file

@ -41,7 +41,7 @@ describe('res.writable', () => {
describe('when socket closed before response sent', () => {
function requsetClosed(server){
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);
setImmediate(() => {
client.write(buf);
@ -66,7 +66,7 @@ describe('res.writable', () => {
describe('when response finished', () => {
function request(server){
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);
setImmediate(() => {
client.write(buf);