Skip to content

Commit 4d66578

Browse files
GreenPioneeraddaleax
authored andcommitted
test: use ES6 to update let & const
Also updating assertStrict and moving the assert required. PR-URL: #9917 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent bb91747 commit 4d66578

4 files changed

+44
-44
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
3+
const assert = require('assert');
44

55
// if child process output to console and exit
66
if (process.argv[2] === 'child') {
77
console.log('hello');
8-
for (var i = 0; i < 200; i++) {
8+
for (let i = 0; i < 200; i++) {
99
console.log('filler');
1010
}
1111
console.log('goodbye');
1212
process.exit(0);
1313
} else {
1414
// parent process
15-
var spawn = require('child_process').spawn;
15+
const spawn = require('child_process').spawn;
1616

1717
// spawn self as child
18-
var child = spawn(process.argv[0], [process.argv[1], 'child']);
18+
const child = spawn(process.argv[0], [process.argv[1], 'child']);
1919

20-
var stdout = '';
20+
let stdout = '';
2121

2222
child.stderr.setEncoding('utf8');
2323
child.stderr.on('data', function(data) {
@@ -32,7 +32,7 @@ if (process.argv[2] === 'child') {
3232
});
3333

3434
child.on('close', common.mustCall(function() {
35-
assert.equal(stdout.slice(0, 6), 'hello\n');
36-
assert.equal(stdout.slice(stdout.length - 8), 'goodbye\n');
35+
assert.strictEqual(stdout.slice(0, 6), 'hello\n');
36+
assert.strictEqual(stdout.slice(stdout.length - 8), 'goodbye\n');
3737
}));
3838
}

test/parallel/test-crypto-cipher-decipher.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
43

54
if (!common.hasCrypto) {
65
common.skip('missing crypto');
@@ -10,21 +9,22 @@ if (common.hasFipsCrypto) {
109
common.skip('not supported in FIPS mode');
1110
return;
1211
}
13-
var crypto = require('crypto');
12+
const crypto = require('crypto');
13+
const assert = require('assert');
1414

1515
function testCipher1(key) {
1616
// Test encryption and decryption
17-
var plaintext = 'Keep this a secret? No! Tell everyone about node.js!';
18-
var cipher = crypto.createCipher('aes192', key);
17+
const plaintext = 'Keep this a secret? No! Tell everyone about node.js!';
18+
const cipher = crypto.createCipher('aes192', key);
1919

2020
// encrypt plaintext which is in utf8 format
2121
// to a ciphertext which will be in hex
22-
var ciph = cipher.update(plaintext, 'utf8', 'hex');
22+
let ciph = cipher.update(plaintext, 'utf8', 'hex');
2323
// Only use binary or hex, not base64.
2424
ciph += cipher.final('hex');
2525

26-
var decipher = crypto.createDecipher('aes192', key);
27-
var txt = decipher.update(ciph, 'hex', 'utf8');
26+
const decipher = crypto.createDecipher('aes192', key);
27+
let txt = decipher.update(ciph, 'hex', 'utf8');
2828
txt += decipher.final('utf8');
2929

3030
assert.strictEqual(txt, plaintext, 'encryption and decryption');
@@ -33,11 +33,11 @@ function testCipher1(key) {
3333
// NB: In real life, it's not guaranteed that you can get all of it
3434
// in a single read() like this. But in this case, we know it's
3535
// quite small, so there's no harm.
36-
var cStream = crypto.createCipher('aes192', key);
36+
const cStream = crypto.createCipher('aes192', key);
3737
cStream.end(plaintext);
3838
ciph = cStream.read();
3939

40-
var dStream = crypto.createDecipher('aes192', key);
40+
const dStream = crypto.createDecipher('aes192', key);
4141
dStream.end(ciph);
4242
txt = dStream.read().toString('utf8');
4343

@@ -48,19 +48,19 @@ function testCipher1(key) {
4848
function testCipher2(key) {
4949
// encryption and decryption with Base64
5050
// reported in https://github.com/joyent/node/issues/738
51-
var plaintext =
51+
const plaintext =
5252
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
5353
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
5454
'jAfaFg**';
55-
var cipher = crypto.createCipher('aes256', key);
55+
const cipher = crypto.createCipher('aes256', key);
5656

5757
// encrypt plaintext which is in utf8 format
5858
// to a ciphertext which will be in Base64
59-
var ciph = cipher.update(plaintext, 'utf8', 'base64');
59+
let ciph = cipher.update(plaintext, 'utf8', 'base64');
6060
ciph += cipher.final('base64');
6161

62-
var decipher = crypto.createDecipher('aes256', key);
63-
var txt = decipher.update(ciph, 'base64', 'utf8');
62+
const decipher = crypto.createDecipher('aes256', key);
63+
let txt = decipher.update(ciph, 'base64', 'utf8');
6464
txt += decipher.final('utf8');
6565

6666
assert.strictEqual(txt, plaintext, 'encryption and decryption with Base64');
@@ -119,12 +119,12 @@ testCipher2(Buffer.from('0123456789abcdef'));
119119
const key = '0123456789abcdef';
120120
const plaintext = 'Top secret!!!';
121121
const c = crypto.createCipher('aes192', key);
122-
var ciph = c.update(plaintext, 'utf16le', 'base64');
122+
let ciph = c.update(plaintext, 'utf16le', 'base64');
123123
ciph += c.final('base64');
124124

125-
var decipher = crypto.createDecipher('aes192', key);
125+
let decipher = crypto.createDecipher('aes192', key);
126126

127-
var txt;
127+
let txt;
128128
assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs2'));
129129
assert.doesNotThrow(() => txt += decipher.final('ucs2'));
130130
assert.strictEqual(txt, plaintext, 'decrypted result in ucs2');

test/parallel/test-https-timeout-server.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
43

54
if (!common.hasCrypto) {
65
common.skip('missing crypto');
76
return;
87
}
9-
var https = require('https');
8+
const assert = require('assert');
9+
const https = require('https');
1010

11-
var net = require('net');
12-
var fs = require('fs');
11+
const net = require('net');
12+
const fs = require('fs');
1313

14-
var options = {
14+
const options = {
1515
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
1616
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
1717
handshakeTimeout: 50
1818
};
1919

20-
var server = https.createServer(options, common.fail);
20+
const server = https.createServer(options, common.fail);
2121

2222
server.on('clientError', common.mustCall(function(err, conn) {
2323
// Don't hesitate to update the asserts if the internal structure of
2424
// the cleartext object ever changes. We're checking that the https.Server
2525
// has closed the client connection.
26-
assert.equal(conn._secureEstablished, false);
26+
assert.strictEqual(conn._secureEstablished, false);
2727
server.close();
2828
conn.destroy();
2929
}));
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
43

54
if (!common.hasCrypto) {
65
common.skip('missing crypto');
76
return;
87
}
9-
var tls = require('tls');
8+
const assert = require('assert');
9+
const tls = require('tls');
1010

11-
var fs = require('fs');
12-
var net = require('net');
11+
const fs = require('fs');
12+
const net = require('net');
1313

14-
var out = '';
14+
let out = '';
1515

16-
var server = tls.createServer({
16+
const server = tls.createServer({
1717
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
1818
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
1919
}, function(c) {
2020
c.end('hello');
2121
}).listen(0, function() {
22-
var socket = new net.Socket();
22+
const socket = new net.Socket();
2323

24-
var s = tls.connect({
24+
const s = tls.connect({
2525
socket: socket,
2626
rejectUnauthorized: false
2727
}, function() {
@@ -38,5 +38,5 @@ var server = tls.createServer({
3838
});
3939

4040
process.on('exit', function() {
41-
assert.equal(out, 'hello');
41+
assert.strictEqual(out, 'hello');
4242
});

0 commit comments

Comments
 (0)