diff --git a/benchmarks/middleware.js b/benchmarks/middleware.js index e6bc6a7..bfa854f 100644 --- a/benchmarks/middleware.js +++ b/benchmarks/middleware.js @@ -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)); diff --git a/test/application/respond.js b/test/application/respond.js index a2a6861..b8f9211 100644 --- a/test/application/respond.js +++ b/test/application/respond.js @@ -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')); }); }); diff --git a/test/response/body.js b/test/response/body.js index 29254e3..d4fd2df 100644 --- a/test/response/body.js +++ b/test/response/body.js @@ -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']); }); }); diff --git a/test/response/length.js b/test/response/length.js index aaf538f..f473b2a 100644 --- a/test/response/length.js +++ b/test/response/length.js @@ -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' }; diff --git a/test/response/writeable.js b/test/response/writeable.js index c1816e6..ff1f89d 100644 --- a/test/response/writeable.js +++ b/test/response/writeable.js @@ -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);