Browse Source

test: change deprecated method to recommended

In non-buffer tests, change usage of the Buffer constructor to one of
the recommended alternatives.

Backport-PR-URL: https://github.com/nodejs/node/pull/14339
PR-URL: https://github.com/nodejs/node/pull/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>
v6.x
Rich Trott 8 years ago
committed by Myles Borins
parent
commit
34fc7a03d2
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 4
      test/parallel/test-stream-pipe-await-drain-push-while-write.js
  2. 4
      test/parallel/test-stream2-decode-partial.js
  3. 2
      test/parallel/test-stream3-cork-end.js
  4. 2
      test/parallel/test-stream3-cork-uncork.js
  5. 2
      test/parallel/test-tls-basic-validations.js
  6. 8
      test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
  7. 2
      test/parallel/test-zlib-sync-no-event.js

4
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) { write: common.mustCall(function(chunk, encoding, cb) {
if (chunk.length === 32 * 1024) { // first chunk if (chunk.length === 32 * 1024) { // first chunk
const beforePush = readable._readableState.awaitDrain; 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. // We should check if awaitDrain counter is increased.
const afterPush = readable._readableState.awaitDrain; const afterPush = readable._readableState.awaitDrain;
assert.strictEqual(afterPush - beforePush, 1, assert.strictEqual(afterPush - beforePush, 1,
@ -34,7 +34,7 @@ const writable = new stream.Writable({
}); });
// A readable stream which produces two buffers. // 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({ const readable = new stream.Readable({
read: function() { read: function() {
while (bufs.length > 0) { while (bufs.length > 0) {

4
test/parallel/test-stream2-decode-partial.js

@ -4,8 +4,8 @@ const Readable = require('_stream_readable');
const assert = require('assert'); const assert = require('assert');
let buf = ''; let buf = '';
const euro = new Buffer([0xE2, 0x82, 0xAC]); const euro = Buffer.from([0xE2, 0x82, 0xAC]);
const cent = new Buffer([0xC2, 0xA2]); const cent = Buffer.from([0xC2, 0xA2]);
const source = Buffer.concat([euro, cent]); const source = Buffer.concat([euro, cent]);
const readable = Readable({ encoding: 'utf8' }); const readable = Readable({ encoding: 'utf8' });

2
test/parallel/test-stream3-cork-end.js

@ -79,7 +79,7 @@ writeChunks(inputChunks, () => {
// there was a chunk // there was a chunk
assert.ok(seen); assert.ok(seen);
const expected = new Buffer(expectedChunks[i]); const expected = Buffer.from(expectedChunks[i]);
// it was what we expected // it was what we expected
assert.ok(seen.equals(expected)); assert.ok(seen.equals(expected));
} }

2
test/parallel/test-stream3-cork-uncork.js

@ -74,7 +74,7 @@ writeChunks(inputChunks, () => {
// there was a chunk // there was a chunk
assert.ok(seen); assert.ok(seen);
const expected = new Buffer(expectedChunks[i]); const expected = Buffer.from(expectedChunks[i]);
// it was what we expected // it was what we expected
assert.ok(seen.equals(expected)); assert.ok(seen.equals(expected));
} }

2
test/parallel/test-tls-basic-validations.js

@ -28,7 +28,7 @@ assert.throws(() => tls.createServer({sessionTimeout: 'abcd'}),
assert.throws(() => tls.createServer({ticketKeys: 'abcd'}), assert.throws(() => tls.createServer({ticketKeys: 'abcd'}),
/TypeError: Ticket keys must be a buffer/); /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/); /TypeError: Ticket keys length must be 48 bytes/);
assert.throws(() => tls.createSecurePair({}), assert.throws(() => tls.createSecurePair({}),

8
test/parallel/test-zlib-from-gzip-with-trailing-garbage.js

@ -9,7 +9,7 @@ const zlib = require('zlib');
let data = Buffer.concat([ let data = Buffer.concat([
zlib.gzipSync('abc'), zlib.gzipSync('abc'),
zlib.gzipSync('def'), zlib.gzipSync('def'),
Buffer(10).fill(0) Buffer.alloc(10)
]); ]);
assert.strictEqual(zlib.gunzipSync(data).toString(), 'abcdef'); assert.strictEqual(zlib.gunzipSync(data).toString(), 'abcdef');
@ -28,8 +28,8 @@ zlib.gunzip(data, common.mustCall((err, result) => {
data = Buffer.concat([ data = Buffer.concat([
zlib.gzipSync('abc'), zlib.gzipSync('abc'),
zlib.gzipSync('def'), zlib.gzipSync('def'),
Buffer([0x1f, 0x8b, 0xff, 0xff]), Buffer.from([0x1f, 0x8b, 0xff, 0xff]),
Buffer(10).fill(0) Buffer.alloc(10)
]); ]);
assert.throws( assert.throws(
@ -49,7 +49,7 @@ zlib.gunzip(data, common.mustCall((err, result) => {
data = Buffer.concat([ data = Buffer.concat([
zlib.gzipSync('abc'), zlib.gzipSync('abc'),
zlib.gzipSync('def'), zlib.gzipSync('def'),
Buffer([0x1f, 0x8b, 0xff, 0xff]) Buffer.from([0x1f, 0x8b, 0xff, 0xff])
]); ]);
assert.throws( assert.throws(

2
test/parallel/test-zlib-sync-no-event.js

@ -10,7 +10,7 @@ const message = 'Come on, Fhqwhgads.';
const zipper = new zlib.Gzip(); const zipper = new zlib.Gzip();
zipper.on('close', shouldNotBeCalled); zipper.on('close', shouldNotBeCalled);
const buffer = new Buffer(message); const buffer = Buffer.from(message);
const zipped = zipper._processChunk(buffer, zlib.Z_FINISH); const zipped = zipper._processChunk(buffer, zlib.Z_FINISH);
const unzipper = new zlib.Gunzip(); const unzipper = new zlib.Gunzip();

Loading…
Cancel
Save