Skip to content

Commit e2d9c23

Browse files
JacksonTianitaloacasas
authored andcommitted
test: use repeat() instead of new Array().join()
The usage of `new Array(length + 1).join(str)` is strange. Change to `str.repeat(length)` is more clearly. PR-URL: nodejs#11071 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Italo A. Casas <[email protected]>
1 parent ea5bef5 commit e2d9c23

10 files changed

+10
-10
lines changed

test/parallel/test-buffer-concat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const flatLongLen = Buffer.concat(long, 40);
1515
assert.strictEqual(flatZero.length, 0);
1616
assert.strictEqual(flatOne.toString(), 'asdf');
1717

18-
const check = new Array(10 + 1).join('asdf');
18+
const check = 'asdf'.repeat(10);
1919

2020
// A special case where concat used to return the first item,
2121
// if the length is one. This check is to make sure that we don't do that.

test/parallel/test-fs-long-path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (!common.isWindows) {
1111

1212
// make a path that will be at least 260 chars long.
1313
const fileNameLen = Math.max(260 - common.tmpDir.length - 1, 1);
14-
const fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x'));
14+
const fileName = path.join(common.tmpDir, 'x'.repeat(fileNameLen));
1515
const fullPath = path.resolve(fileName);
1616

1717
common.refreshTmpDir();

test/parallel/test-fs-readfile-pipe-large.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if (process.argv[2] === 'child') {
2121
}
2222

2323
const filename = path.join(common.tmpDir, '/readfile_pipe_large_test.txt');
24-
const dataExpected = new Array(1000000).join('a');
24+
const dataExpected = 'a'.repeat(999999);
2525
common.refreshTmpDir();
2626
fs.writeFileSync(filename, dataExpected);
2727

test/parallel/test-fs-readfilesync-pipe-large.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (process.argv[2] === 'child') {
1818
}
1919

2020
const filename = path.join(common.tmpDir, '/readfilesync_pipe_large_test.txt');
21-
const dataExpected = new Array(1000000).join('a');
21+
const dataExpected = 'a'.repeat(999999);
2222
common.refreshTmpDir();
2323
fs.writeFileSync(filename, dataExpected);
2424

test/parallel/test-http-byteswritten.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const httpServer = http.createServer(common.mustCall(function(req, res) {
1616

1717
// Write 1.5mb to cause some requests to buffer
1818
// Also, mix up the encodings a bit.
19-
const chunk = new Array(1024 + 1).join('7');
19+
const chunk = '7'.repeat(1024);
2020
const bchunk = Buffer.from(chunk);
2121
for (let i = 0; i < 1024; i++) {
2222
res.write(chunk);

test/parallel/test-http-pipeline-flood.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function child() {
7070

7171
let req = `GET / HTTP/1.1\r\nHost: localhost:${port}\r\nAccept: */*\r\n\r\n`;
7272

73-
req = new Array(10241).join(req);
73+
req = req.repeat(10240);
7474

7575
conn.on('connect', write);
7676

test/parallel/test-http-pipeline-regr-3332.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const server = http.createServer(function(req, res) {
1919
}
2020
});
2121
}).listen(0, function() {
22-
const req = new Array(COUNT + 1).join('GET / HTTP/1.1\r\n\r\n');
22+
const req = 'GET / HTTP/1.1\r\n\r\n'.repeat(COUNT);
2323
client = net.connect(this.address().port, function() {
2424
client.write(req);
2525
});

test/parallel/test-stream2-writable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TestWriter.prototype._write = function(chunk, encoding, cb) {
2424

2525
const chunks = new Array(50);
2626
for (let i = 0; i < chunks.length; i++) {
27-
chunks[i] = new Array(i + 1).join('x');
27+
chunks[i] = 'x'.repeat(i);
2828
}
2929

3030
// tiny node-tap lookalike.

test/parallel/test-string-decoder-end.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const bufs = [ '☃💩', 'asdf' ].map((b) => Buffer.from(b));
1212

1313
// also test just arbitrary bytes from 0-15.
1414
for (let i = 1; i <= 16; i++) {
15-
const bytes = new Array(i).join('.').split('.').map((_, j) => j + 0x78);
15+
const bytes = '.'.repeat(i - 1).split('.').map((_, j) => j + 0x78);
1616
bufs.push(Buffer.from(bytes));
1717
}
1818

test/pummel/test-tls-server-large-request.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const fs = require('fs');
1212
const stream = require('stream');
1313
const util = require('util');
1414

15-
const request = Buffer.from(new Array(1024 * 256).join('ABCD')); // 1mb
15+
const request = Buffer.from('ABCD'.repeat(1024 * 256 - 1)); // 1mb
1616

1717
const options = {
1818
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),

0 commit comments

Comments
 (0)