From 14f5a9becc81db270e5b1696de5a4f5e70344be0 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 12 Jun 2017 22:18:11 -0700 Subject: [PATCH] test: change deprecated method to recommended MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In non-buffer tests, change usage of the Buffer constructor to one of the recommended alternatives. PR-URL: https://github.com/nodejs/node/pull/13649 Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Tobias Nießen Reviewed-By: Brian White --- .../test-stream-pipe-await-drain-push-while-write.js | 4 ++-- test/parallel/test-stream2-decode-partial.js | 4 ++-- test/parallel/test-stream3-cork-end.js | 2 +- test/parallel/test-stream3-cork-uncork.js | 2 +- test/parallel/test-tls-basic-validations.js | 2 +- test/parallel/test-zlib-bytes-read.js | 8 ++++---- .../parallel/test-zlib-from-gzip-with-trailing-garbage.js | 8 ++++---- test/parallel/test-zlib-sync-no-event.js | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/parallel/test-stream-pipe-await-drain-push-while-write.js b/test/parallel/test-stream-pipe-await-drain-push-while-write.js index 67a8f304c31614..adefad70adc20c 100644 --- a/test/parallel/test-stream-pipe-await-drain-push-while-write.js +++ b/test/parallel/test-stream-pipe-await-drain-push-while-write.js @@ -17,7 +17,7 @@ const writable = new stream.Writable({ write: common.mustCall(function(chunk, encoding, cb) { if (chunk.length === 32 * 1024) { // first chunk const beforePush = readable._readableState.awaitDrain; - readable.push(new Buffer(34 * 1024)); // above hwm + readable.push(Buffer.alloc(34 * 1024)); // above hwm // We should check if awaitDrain counter is increased. const afterPush = readable._readableState.awaitDrain; assert.strictEqual(afterPush - beforePush, 1, @@ -34,7 +34,7 @@ const writable = new stream.Writable({ }); // A readable stream which produces two buffers. -const bufs = [new Buffer(32 * 1024), new Buffer(33 * 1024)]; // above hwm +const bufs = [Buffer.alloc(32 * 1024), Buffer.alloc(33 * 1024)]; // above hwm const readable = new stream.Readable({ read: function() { while (bufs.length > 0) { diff --git a/test/parallel/test-stream2-decode-partial.js b/test/parallel/test-stream2-decode-partial.js index b43101dbc84c3a..9b1baf7fd677f4 100644 --- a/test/parallel/test-stream2-decode-partial.js +++ b/test/parallel/test-stream2-decode-partial.js @@ -4,8 +4,8 @@ const Readable = require('_stream_readable'); const assert = require('assert'); let buf = ''; -const euro = new Buffer([0xE2, 0x82, 0xAC]); -const cent = new Buffer([0xC2, 0xA2]); +const euro = Buffer.from([0xE2, 0x82, 0xAC]); +const cent = Buffer.from([0xC2, 0xA2]); const source = Buffer.concat([euro, cent]); const readable = Readable({ encoding: 'utf8' }); diff --git a/test/parallel/test-stream3-cork-end.js b/test/parallel/test-stream3-cork-end.js index 7227f87ada7fa1..85781cdf7187f2 100644 --- a/test/parallel/test-stream3-cork-end.js +++ b/test/parallel/test-stream3-cork-end.js @@ -79,7 +79,7 @@ writeChunks(inputChunks, () => { // there was a chunk assert.ok(seen); - const expected = new Buffer(expectedChunks[i]); + const expected = Buffer.from(expectedChunks[i]); // it was what we expected assert.ok(seen.equals(expected)); } diff --git a/test/parallel/test-stream3-cork-uncork.js b/test/parallel/test-stream3-cork-uncork.js index 98f74a45c6624e..2e8e86be1ef058 100644 --- a/test/parallel/test-stream3-cork-uncork.js +++ b/test/parallel/test-stream3-cork-uncork.js @@ -74,7 +74,7 @@ writeChunks(inputChunks, () => { // there was a chunk assert.ok(seen); - const expected = new Buffer(expectedChunks[i]); + const expected = Buffer.from(expectedChunks[i]); // it was what we expected assert.ok(seen.equals(expected)); } diff --git a/test/parallel/test-tls-basic-validations.js b/test/parallel/test-tls-basic-validations.js index 0b5d87ddc88ff2..a6775c06033a2c 100644 --- a/test/parallel/test-tls-basic-validations.js +++ b/test/parallel/test-tls-basic-validations.js @@ -33,7 +33,7 @@ assert.throws(() => tls.createServer({sessionTimeout: 'abcd'}), assert.throws(() => tls.createServer({ticketKeys: 'abcd'}), /TypeError: Ticket keys must be a buffer/); -assert.throws(() => tls.createServer({ticketKeys: new Buffer(0)}), +assert.throws(() => tls.createServer({ticketKeys: Buffer.alloc(0)}), /TypeError: Ticket keys length must be 48 bytes/); assert.throws(() => tls.createSecurePair({}), diff --git a/test/parallel/test-zlib-bytes-read.js b/test/parallel/test-zlib-bytes-read.js index 701d286817a267..6262c2514954d0 100644 --- a/test/parallel/test-zlib-bytes-read.js +++ b/test/parallel/test-zlib-bytes-read.js @@ -28,7 +28,7 @@ for (const method of [ ['createDeflateRaw', 'createInflateRaw', true] ]) { let compWriter; - let compData = new Buffer(0); + let compData = Buffer.alloc(0); const comp = zlib[method[0]](); comp.on('data', function(d) { @@ -44,7 +44,7 @@ for (const method of [ { let decompWriter; - let decompData = new Buffer(0); + let decompData = Buffer.alloc(0); const decomp = zlib[method[1]](); decomp.on('data', function(d) { @@ -66,10 +66,10 @@ for (const method of [ // Some methods should allow extra data after the compressed data if (method[2]) { - const compDataExtra = Buffer.concat([compData, new Buffer('extra')]); + const compDataExtra = Buffer.concat([compData, Buffer.from('extra')]); let decompWriter; - let decompData = new Buffer(0); + let decompData = Buffer.alloc(0); const decomp = zlib[method[1]](); decomp.on('data', function(d) { diff --git a/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js b/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js index 872c2581c53b90..0cc4953d41c514 100644 --- a/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js +++ b/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js @@ -9,7 +9,7 @@ const zlib = require('zlib'); let data = Buffer.concat([ zlib.gzipSync('abc'), zlib.gzipSync('def'), - Buffer(10).fill(0) + Buffer.alloc(10) ]); assert.strictEqual(zlib.gunzipSync(data).toString(), 'abcdef'); @@ -28,8 +28,8 @@ zlib.gunzip(data, common.mustCall((err, result) => { data = Buffer.concat([ zlib.gzipSync('abc'), zlib.gzipSync('def'), - Buffer([0x1f, 0x8b, 0xff, 0xff]), - Buffer(10).fill(0) + Buffer.from([0x1f, 0x8b, 0xff, 0xff]), + Buffer.alloc(10) ]); assert.throws( @@ -49,7 +49,7 @@ zlib.gunzip(data, common.mustCall((err, result) => { data = Buffer.concat([ zlib.gzipSync('abc'), zlib.gzipSync('def'), - Buffer([0x1f, 0x8b, 0xff, 0xff]) + Buffer.from([0x1f, 0x8b, 0xff, 0xff]) ]); assert.throws( diff --git a/test/parallel/test-zlib-sync-no-event.js b/test/parallel/test-zlib-sync-no-event.js index d6eb1f3c9df6a3..c6584b43d9ba1c 100644 --- a/test/parallel/test-zlib-sync-no-event.js +++ b/test/parallel/test-zlib-sync-no-event.js @@ -10,7 +10,7 @@ const message = 'Come on, Fhqwhgads.'; const zipper = new zlib.Gzip(); zipper.on('close', shouldNotBeCalled); -const buffer = new Buffer(message); +const buffer = Buffer.from(message); const zipped = zipper._processChunk(buffer, zlib.constants.Z_FINISH); const unzipper = new zlib.Gunzip();