Skip to content

Commit 6920d5c

Browse files
Trottaddaleax
authored andcommitted
test: change deprecated method to recommended
In non-buffer tests, change usage of the Buffer constructor to one of the recommended alternatives. PR-URL: #13649 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent f28dd8e commit 6920d5c

8 files changed

+16
-16
lines changed

test/parallel/test-stream-pipe-await-drain-push-while-write.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const writable = new stream.Writable({
1717
write: common.mustCall(function(chunk, encoding, cb) {
1818
if (chunk.length === 32 * 1024) { // first chunk
1919
const beforePush = readable._readableState.awaitDrain;
20-
readable.push(new Buffer(34 * 1024)); // above hwm
20+
readable.push(Buffer.alloc(34 * 1024)); // above hwm
2121
// We should check if awaitDrain counter is increased.
2222
const afterPush = readable._readableState.awaitDrain;
2323
assert.strictEqual(afterPush - beforePush, 1,
@@ -34,7 +34,7 @@ const writable = new stream.Writable({
3434
});
3535

3636
// A readable stream which produces two buffers.
37-
const bufs = [new Buffer(32 * 1024), new Buffer(33 * 1024)]; // above hwm
37+
const bufs = [Buffer.alloc(32 * 1024), Buffer.alloc(33 * 1024)]; // above hwm
3838
const readable = new stream.Readable({
3939
read: function() {
4040
while (bufs.length > 0) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const Readable = require('_stream_readable');
44
const assert = require('assert');
55

66
let buf = '';
7-
const euro = new Buffer([0xE2, 0x82, 0xAC]);
8-
const cent = new Buffer([0xC2, 0xA2]);
7+
const euro = Buffer.from([0xE2, 0x82, 0xAC]);
8+
const cent = Buffer.from([0xC2, 0xA2]);
99
const source = Buffer.concat([euro, cent]);
1010

1111
const readable = Readable({ encoding: 'utf8' });

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ writeChunks(inputChunks, () => {
7979
// there was a chunk
8080
assert.ok(seen);
8181

82-
const expected = new Buffer(expectedChunks[i]);
82+
const expected = Buffer.from(expectedChunks[i]);
8383
// it was what we expected
8484
assert.ok(seen.equals(expected));
8585
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ writeChunks(inputChunks, () => {
7474
// there was a chunk
7575
assert.ok(seen);
7676

77-
const expected = new Buffer(expectedChunks[i]);
77+
const expected = Buffer.from(expectedChunks[i]);
7878
// it was what we expected
7979
assert.ok(seen.equals(expected));
8080
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ assert.throws(() => tls.createServer({sessionTimeout: 'abcd'}),
3333
assert.throws(() => tls.createServer({ticketKeys: 'abcd'}),
3434
/TypeError: Ticket keys must be a buffer/);
3535

36-
assert.throws(() => tls.createServer({ticketKeys: new Buffer(0)}),
36+
assert.throws(() => tls.createServer({ticketKeys: Buffer.alloc(0)}),
3737
/TypeError: Ticket keys length must be 48 bytes/);
3838

3939
assert.throws(() => tls.createSecurePair({}),

test/parallel/test-zlib-bytes-read.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ for (const method of [
2828
['createDeflateRaw', 'createInflateRaw', true]
2929
]) {
3030
let compWriter;
31-
let compData = new Buffer(0);
31+
let compData = Buffer.alloc(0);
3232

3333
const comp = zlib[method[0]]();
3434
comp.on('data', function(d) {
@@ -44,7 +44,7 @@ for (const method of [
4444

4545
{
4646
let decompWriter;
47-
let decompData = new Buffer(0);
47+
let decompData = Buffer.alloc(0);
4848

4949
const decomp = zlib[method[1]]();
5050
decomp.on('data', function(d) {
@@ -66,10 +66,10 @@ for (const method of [
6666

6767
// Some methods should allow extra data after the compressed data
6868
if (method[2]) {
69-
const compDataExtra = Buffer.concat([compData, new Buffer('extra')]);
69+
const compDataExtra = Buffer.concat([compData, Buffer.from('extra')]);
7070

7171
let decompWriter;
72-
let decompData = new Buffer(0);
72+
let decompData = Buffer.alloc(0);
7373

7474
const decomp = zlib[method[1]]();
7575
decomp.on('data', function(d) {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const zlib = require('zlib');
99
let data = Buffer.concat([
1010
zlib.gzipSync('abc'),
1111
zlib.gzipSync('def'),
12-
Buffer(10).fill(0)
12+
Buffer.alloc(10)
1313
]);
1414

1515
assert.strictEqual(zlib.gunzipSync(data).toString(), 'abcdef');
@@ -28,8 +28,8 @@ zlib.gunzip(data, common.mustCall((err, result) => {
2828
data = Buffer.concat([
2929
zlib.gzipSync('abc'),
3030
zlib.gzipSync('def'),
31-
Buffer([0x1f, 0x8b, 0xff, 0xff]),
32-
Buffer(10).fill(0)
31+
Buffer.from([0x1f, 0x8b, 0xff, 0xff]),
32+
Buffer.alloc(10)
3333
]);
3434

3535
assert.throws(
@@ -49,7 +49,7 @@ zlib.gunzip(data, common.mustCall((err, result) => {
4949
data = Buffer.concat([
5050
zlib.gzipSync('abc'),
5151
zlib.gzipSync('def'),
52-
Buffer([0x1f, 0x8b, 0xff, 0xff])
52+
Buffer.from([0x1f, 0x8b, 0xff, 0xff])
5353
]);
5454

5555
assert.throws(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const message = 'Come on, Fhqwhgads.';
1010
const zipper = new zlib.Gzip();
1111
zipper.on('close', shouldNotBeCalled);
1212

13-
const buffer = new Buffer(message);
13+
const buffer = Buffer.from(message);
1414
const zipped = zipper._processChunk(buffer, zlib.constants.Z_FINISH);
1515

1616
const unzipper = new zlib.Gunzip();

0 commit comments

Comments
 (0)