Skip to content

Commit

Permalink
test: use ES6 to update let & const
Browse files Browse the repository at this point in the history
Also updating assertStrict and moving the assert required.

PR-URL: #9917
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
  • Loading branch information
GreenPioneer authored and jasnell committed Dec 6, 2016
1 parent a3a3937 commit a1bd070
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
16 changes: 8 additions & 8 deletions test/parallel/test-child-process-stdout-flush-exit.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');

// if child process output to console and exit
if (process.argv[2] === 'child') {
console.log('hello');
for (var i = 0; i < 200; i++) {
for (let i = 0; i < 200; i++) {
console.log('filler');
}
console.log('goodbye');
process.exit(0);
} else {
// parent process
var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;

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

var stdout = '';
let stdout = '';

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

child.on('close', common.mustCall(function() {
assert.equal(stdout.slice(0, 6), 'hello\n');
assert.equal(stdout.slice(stdout.length - 8), 'goodbye\n');
assert.strictEqual(stdout.slice(0, 6), 'hello\n');
assert.strictEqual(stdout.slice(stdout.length - 8), 'goodbye\n');
}));
}
36 changes: 18 additions & 18 deletions test/parallel/test-crypto-cipher-decipher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');

if (!common.hasCrypto) {
common.skip('missing crypto');
Expand All @@ -10,21 +9,22 @@ if (common.hasFipsCrypto) {
common.skip('not supported in FIPS mode');
return;
}
var crypto = require('crypto');
const crypto = require('crypto');
const assert = require('assert');

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

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

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

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

var dStream = crypto.createDecipher('aes192', key);
const dStream = crypto.createDecipher('aes192', key);
dStream.end(ciph);
txt = dStream.read().toString('utf8');

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

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

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

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

var decipher = crypto.createDecipher('aes192', key);
let decipher = crypto.createDecipher('aes192', key);

var txt;
let txt;
assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs2'));
assert.doesNotThrow(() => txt += decipher.final('ucs2'));
assert.strictEqual(txt, plaintext, 'decrypted result in ucs2');
Expand Down
16 changes: 8 additions & 8 deletions test/parallel/test-https-timeout-server.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
var https = require('https');
const assert = require('assert');
const https = require('https');

var net = require('net');
var fs = require('fs');
const net = require('net');
const fs = require('fs');

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

var server = https.createServer(options, common.fail);
const server = https.createServer(options, common.fail);

server.on('clientError', common.mustCall(function(err, conn) {
// Don't hesitate to update the asserts if the internal structure of
// the cleartext object ever changes. We're checking that the https.Server
// has closed the client connection.
assert.equal(conn._secureEstablished, false);
assert.strictEqual(conn._secureEstablished, false);
server.close();
conn.destroy();
}));
Expand Down
20 changes: 10 additions & 10 deletions test/parallel/test-tls-on-empty-socket.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
var tls = require('tls');
const assert = require('assert');
const tls = require('tls');

var fs = require('fs');
var net = require('net');
const fs = require('fs');
const net = require('net');

var out = '';
let out = '';

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

var s = tls.connect({
const s = tls.connect({
socket: socket,
rejectUnauthorized: false
}, function() {
Expand All @@ -38,5 +38,5 @@ var server = tls.createServer({
});

process.on('exit', function() {
assert.equal(out, 'hello');
assert.strictEqual(out, 'hello');
});

0 comments on commit a1bd070

Please sign in to comment.