Skip to content

Commit

Permalink
test: change deprecated method to recommended
Browse files Browse the repository at this point in the history
In non-buffer tests, change usage of the Buffer constructor to one of
the recommended alternatives.

PR-URL: #13649
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Brian White <mscdex@mscdex.net>
  • Loading branch information
Trott authored and addaleax committed Jun 21, 2017
1 parent f28dd8e commit 6920d5c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stream2-decode-partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream3-cork-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream3-cork-uncork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-basic-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({}),
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-zlib-bytes-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-zlib-sync-no-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6920d5c

Please sign in to comment.