test: fix style issues after eslint update

Replace var keyword with const or let.

PR-URL: https://github.com/nodejs/io.js/pull/2286
Reviewed-By: Roman Reiss <me@silverwind.io>
This commit is contained in:
Michaël Zasso 2016-01-13 21:42:45 +01:00 committed by Roman Reiss
parent ec8e0ae697
commit d1aabd6264
110 changed files with 939 additions and 892 deletions

View File

@ -437,7 +437,7 @@ exports.getServiceName = function getServiceName(port, protocol) {
if (matches && matches.length > 1) {
serviceName = matches[1];
}
} catch(e) {
} catch (e) {
console.error('Cannot read file: ', etcServicesFileName);
return undefined;
}

View File

@ -20,8 +20,8 @@ repl.addTest('sb(")^$*+?}{|][(.js\\\\", 1)', [
// continue - the breakpoint should be triggered
repl.addTest('c', [
/break in .*[\\\/]mod\.js:23/,
/21/, /22/, /23/, /24/, /25/
/break in .*[\\\/]mod\.js:23/,
/21/, /22/, /23/, /24/, /25/
]);
// -- RESTORE BREAKPOINT ON RESTART --

View File

@ -4,7 +4,7 @@ var repl = require('./helper-debugger-repl.js');
repl.startDebugger('breakpoints.js');
var linesWithBreakpoint = [
/1/, /2/, /3/, /4/, /5/, /\* 6/
/1/, /2/, /3/, /4/, /5/, /\* 6/
];
// We slice here, because addTest will change the given array.
repl.addTest('sb(6)', linesWithBreakpoint.slice());

View File

@ -6,15 +6,15 @@ function serverHandler(req, res) {
res.connection.destroy();
}
var http = require('http'),
weak = require('weak'),
done = 0,
count = 0,
countGC = 0,
todo = 500,
common = require('../common'),
assert = require('assert'),
PORT = common.PORT;
const http = require('http');
const weak = require('weak');
const common = require('../common');
const assert = require('assert');
const PORT = common.PORT;
const todo = 500;
let done = 0;
let count = 0;
let countGC = 0;
console.log('We should do ' + todo + ' requests');

View File

@ -8,15 +8,15 @@ function serverHandler(req, res) {
res.end('Hello World\n');
}
var http = require('http'),
weak = require('weak'),
done = 0,
count = 0,
countGC = 0,
todo = 500,
common = require('../common'),
assert = require('assert'),
PORT = common.PORT;
const http = require('http');
const weak = require('weak');
const common = require('../common');
const assert = require('assert');
const PORT = common.PORT;
const todo = 500;
let done = 0;
let count = 0;
let countGC = 0;
console.log('We should do ' + todo + ' requests');

View File

@ -10,15 +10,15 @@ function serverHandler(req, res) {
}, 100);
}
var http = require('http'),
weak = require('weak'),
done = 0,
count = 0,
countGC = 0,
todo = 550,
common = require('../common'),
assert = require('assert'),
PORT = common.PORT;
const http = require('http');
const weak = require('weak');
const common = require('../common');
const assert = require('assert');
const PORT = common.PORT;
const todo = 550;
let done = 0;
let count = 0;
let countGC = 0;
console.log('We should do ' + todo + ' requests');

View File

@ -6,15 +6,15 @@ function serverHandler(req, res) {
res.end('Hello World\n');
}
var http = require('http'),
weak = require('weak'),
done = 0,
count = 0,
countGC = 0,
todo = 500,
common = require('../common'),
assert = require('assert'),
PORT = common.PORT;
const http = require('http');
const weak = require('weak');
const common = require('../common');
const assert = require('assert');
const PORT = common.PORT;
const todo = 500;
let done = 0;
let count = 0;
let countGC = 0;
console.log('We should do ' + todo + ' requests');

View File

@ -17,15 +17,15 @@ function serverHandler(sock) {
}, 100);
}
var net = require('net'),
weak = require('weak'),
done = 0,
count = 0,
countGC = 0,
todo = 500,
common = require('../common'),
assert = require('assert'),
PORT = common.PORT;
const net = require('net');
const weak = require('weak');
const common = require('../common');
const assert = require('assert');
const PORT = common.PORT;
const todo = 500;
let done = 0;
let count = 0;
let countGC = 0;
console.log('We should do ' + todo + ' requests');

View File

@ -1,19 +1,19 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
dgram = require('dgram'),
util = require('util'),
networkInterfaces = require('os').networkInterfaces(),
Buffer = require('buffer').Buffer,
fork = require('child_process').fork,
LOCAL_BROADCAST_HOST = '255.255.255.255',
TIMEOUT = common.platformTimeout(5000),
messages = [
new Buffer('First message to send'),
new Buffer('Second message to send'),
new Buffer('Third message to send'),
new Buffer('Fourth message to send')
];
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const util = require('util');
const networkInterfaces = require('os').networkInterfaces();
const Buffer = require('buffer').Buffer;
const fork = require('child_process').fork;
const LOCAL_BROADCAST_HOST = '255.255.255.255';
const TIMEOUT = common.platformTimeout(5000);
const messages = [
new Buffer('First message to send'),
new Buffer('Second message to send'),
new Buffer('Third message to send'),
new Buffer('Fourth message to send')
];
if (common.inFreeBSDJail) {
console.log('1..0 # Skipped: in a FreeBSD jail');
@ -34,13 +34,13 @@ get_bindAddress: for (var name in networkInterfaces) {
assert.ok(bindAddress);
if (process.argv[2] !== 'child') {
var workers = {},
listeners = 3,
listening = 0,
dead = 0,
i = 0,
done = 0,
timer = null;
const workers = {};
const listeners = 3;
let listening = 0;
let dead = 0;
let i = 0;
let done = 0;
let timer = null;
//exit the test if it doesn't succeed within TIMEOUT
timer = setTimeout(function() {
@ -166,15 +166,21 @@ if (process.argv[2] !== 'child') {
return;
}
sendSocket.send(buf, 0, buf.length,
common.PORT, LOCAL_BROADCAST_HOST, function(err) {
if (err) throw err;
console.error('[PARENT] sent %s to %s:%s',
util.inspect(buf.toString()),
LOCAL_BROADCAST_HOST, common.PORT);
sendSocket.send(
buf,
0,
buf.length,
common.PORT,
LOCAL_BROADCAST_HOST,
function(err) {
if (err) throw err;
console.error('[PARENT] sent %s to %s:%s',
util.inspect(buf.toString()),
LOCAL_BROADCAST_HOST, common.PORT);
process.nextTick(sendSocket.sendNext);
});
process.nextTick(sendSocket.sendNext);
}
);
};
function killChildren(children) {

View File

@ -157,14 +157,20 @@ if (process.argv[2] !== 'child') {
return;
}
sendSocket.send(buf, 0, buf.length,
common.PORT, LOCAL_BROADCAST_HOST, function(err) {
if (err) throw err;
console.error('[PARENT] sent "%s" to %s:%s',
buf.toString(),
LOCAL_BROADCAST_HOST, common.PORT);
process.nextTick(sendSocket.sendNext);
});
sendSocket.send(
buf,
0,
buf.length,
common.PORT,
LOCAL_BROADCAST_HOST,
function(err) {
if (err) throw err;
console.error('[PARENT] sent "%s" to %s:%s',
buf.toString(),
LOCAL_BROADCAST_HOST, common.PORT);
process.nextTick(sendSocket.sendNext);
}
);
};
}

View File

@ -1,14 +1,14 @@
'use strict';
var common = require('../common');
var assert = require('assert'),
dns = require('dns'),
net = require('net'),
isIPv4 = net.isIPv4;
const common = require('../common');
const assert = require('assert');
const dns = require('dns');
const net = require('net');
const isIPv4 = net.isIPv4;
var expected = 0,
completed = 0,
running = false,
queue = [];
let expected = 0;
let completed = 0;
let running = false;
const queue = [];
function TEST(f) {
function next() {
@ -148,19 +148,22 @@ TEST(function test_lookup_localhost_ipv4(done) {
});
TEST(function test_lookup_all_ipv4(done) {
var req = dns.lookup('www.google.com', {all: true, family: 4},
function(err, ips) {
if (err) throw err;
assert.ok(Array.isArray(ips));
assert.ok(ips.length > 0);
var req = dns.lookup(
'www.google.com',
{all: true, family: 4},
function(err, ips) {
if (err) throw err;
assert.ok(Array.isArray(ips));
assert.ok(ips.length > 0);
ips.forEach(function(ip) {
assert.ok(isIPv4(ip.address));
assert.strictEqual(ip.family, 4);
});
ips.forEach(function(ip) {
assert.ok(isIPv4(ip.address));
assert.strictEqual(ip.family, 4);
});
done();
});
done();
}
);
checkWrap(req);
});

View File

@ -1,14 +1,14 @@
'use strict';
var common = require('../common');
var assert = require('assert'),
dns = require('dns'),
net = require('net'),
isIPv6 = net.isIPv6;
const common = require('../common');
const assert = require('assert');
const dns = require('dns');
const net = require('net');
const isIPv6 = net.isIPv6;
var expected = 0,
completed = 0,
running = false,
queue = [];
let expected = 0;
let completed = 0;
let running = false;
const queue = [];
if (!common.hasIPv6) {
console.log('1..0 # Skipped: this test, no IPv6 support');
@ -156,20 +156,23 @@ TEST(function test_lookup_ip_ipv6(done) {
});
TEST(function test_lookup_all_ipv6(done) {
var req = dns.lookup('www.google.com', {all: true, family: 6},
function(err, ips) {
if (err) throw err;
assert.ok(Array.isArray(ips));
assert.ok(ips.length > 0);
var req = dns.lookup(
'www.google.com',
{all: true, family: 6},
function(err, ips) {
if (err) throw err;
assert.ok(Array.isArray(ips));
assert.ok(ips.length > 0);
ips.forEach(function(ip) {
assert.ok(isIPv6(ip.address),
'Invalid IPv6: ' + ip.address.toString());
assert.strictEqual(ip.family, 6);
});
ips.forEach(function(ip) {
assert.ok(isIPv6(ip.address),
'Invalid IPv6: ' + ip.address.toString());
assert.strictEqual(ip.family, 6);
});
done();
});
done();
}
);
checkWrap(req);
});

View File

@ -1,16 +1,16 @@
'use strict';
require('../common');
var assert = require('assert'),
dns = require('dns'),
net = require('net'),
isIPv4 = net.isIPv4,
isIPv6 = net.isIPv6;
var util = require('util');
const assert = require('assert');
const dns = require('dns');
const net = require('net');
const isIPv4 = net.isIPv4;
const isIPv6 = net.isIPv6;
const util = require('util');
var expected = 0,
completed = 0,
running = false,
queue = [];
let expected = 0;
let completed = 0;
let running = false;
const queue = [];
function TEST(f) {

View File

@ -1,7 +1,7 @@
'use strict';
require('../common');
var assert = require('assert'),
exception = null;
const assert = require('assert');
let exception = null;
try {
eval('"\\uc/ef"');

View File

@ -921,8 +921,8 @@ Buffer(Buffer(0), 0, 0);
// GH-5110
(function() {
var buffer = new Buffer('test'),
string = JSON.stringify(buffer);
const buffer = new Buffer('test');
const string = JSON.stringify(buffer);
assert.equal(string, '{"type":"Buffer","data":[116,101,115,116]}');

View File

@ -1,9 +1,9 @@
'use strict';
var common = require('../common');
var assert = require('assert'),
os = require('os'),
util = require('util'),
spawn = require('child_process').spawn;
const common = require('../common');
const assert = require('assert');
const os = require('os');
const util = require('util');
const spawn = require('child_process').spawn;
// We're trying to reproduce:
// $ echo "hello\nnode\nand\nworld" | grep o | sed s/o/a/

View File

@ -6,18 +6,18 @@ var fork = require('child_process').fork;
// Fork, then spawn. The spawned process should not hang.
switch (process.argv[2] || '') {
case '':
fork(__filename, ['fork']).on('exit', checkExit);
process.on('exit', haveExit);
break;
case 'fork':
spawn(process.execPath, [__filename, 'spawn']).on('exit', checkExit);
process.on('exit', haveExit);
break;
case 'spawn':
break;
default:
assert(0);
case '':
fork(__filename, ['fork']).on('exit', checkExit);
process.on('exit', haveExit);
break;
case 'fork':
spawn(process.execPath, [__filename, 'spawn']).on('exit', checkExit);
process.on('exit', haveExit);
break;
case 'spawn':
break;
default:
assert(0);
}
var seenExit = false;

View File

@ -1,13 +1,13 @@
'use strict';
var assert = require('assert'),
common = require('../common'),
fork = require('child_process').fork;
const assert = require('assert');
const common = require('../common');
const fork = require('child_process').fork;
var cp = fork(common.fixturesDir + '/child-process-message-and-exit.js');
var gotMessage = false,
gotExit = false,
gotClose = false;
let gotMessage = false;
let gotExit = false;
let gotClose = false;
cp.on('message', function(message) {
assert(!gotMessage);

View File

@ -69,7 +69,13 @@ if (process.argv[2] === 'child') {
var sendMessages = function() {
var timer = setInterval(function() {
client.send(msg, 0, msg.length, common.PORT, '127.0.0.1', function(err) {
client.send(
msg,
0,
msg.length,
common.PORT,
'127.0.0.1',
function(err) {
if (err) throw err;
}
);

View File

@ -66,8 +66,8 @@ if (process.argv[2] === 'child') {
var server = net.createServer();
var connected = 0,
closed = 0;
let connected = 0;
let closed = 0;
server.on('connection', function(socket) {
switch (connected % 6) {
case 0:

View File

@ -5,11 +5,11 @@ if (module.parent) {
process.exit(42);
}
var common = require('../common'),
assert = require('assert'),
child = require('child_process'),
path = require('path'),
nodejs = '"' + process.execPath + '"';
const common = require('../common');
const assert = require('assert');
const child = require('child_process');
const path = require('path');
const nodejs = '"' + process.execPath + '"';
// replace \ by / because windows uses backslashes in paths, but they're still

View File

@ -24,23 +24,23 @@ if (cluster.isWorker) {
} else if (cluster.isMaster) {
var expected_results = {
cluster_emitDisconnect: [1, "the cluster did not emit 'disconnect'"],
cluster_emitExit: [1, "the cluster did not emit 'exit'"],
cluster_exitCode: [EXIT_CODE, 'the cluster exited w/ incorrect exitCode'],
cluster_signalCode: [null, 'the cluster exited w/ incorrect signalCode'],
worker_emitDisconnect: [1, "the worker did not emit 'disconnect'"],
worker_emitExit: [1, "the worker did not emit 'exit'"],
worker_state: ['disconnected', 'the worker state is incorrect'],
worker_suicideMode: [false, 'the worker.suicide flag is incorrect'],
worker_died: [true, 'the worker is still running'],
worker_exitCode: [EXIT_CODE, 'the worker exited w/ incorrect exitCode'],
worker_signalCode: [null, 'the worker exited w/ incorrect signalCode']
cluster_emitDisconnect: [1, "the cluster did not emit 'disconnect'"],
cluster_emitExit: [1, "the cluster did not emit 'exit'"],
cluster_exitCode: [EXIT_CODE, 'the cluster exited w/ incorrect exitCode'],
cluster_signalCode: [null, 'the cluster exited w/ incorrect signalCode'],
worker_emitDisconnect: [1, "the worker did not emit 'disconnect'"],
worker_emitExit: [1, "the worker did not emit 'exit'"],
worker_state: ['disconnected', 'the worker state is incorrect'],
worker_suicideMode: [false, 'the worker.suicide flag is incorrect'],
worker_died: [true, 'the worker is still running'],
worker_exitCode: [EXIT_CODE, 'the worker exited w/ incorrect exitCode'],
worker_signalCode: [null, 'the worker exited w/ incorrect signalCode']
};
var results = {
cluster_emitDisconnect: 0,
cluster_emitExit: 0,
worker_emitDisconnect: 0,
worker_emitExit: 0
cluster_emitDisconnect: 0,
cluster_emitExit: 0,
worker_emitDisconnect: 0,
worker_emitExit: 0
};
@ -103,8 +103,8 @@ if (cluster.isWorker) {
function checkResults(expected_results, results) {
for (var k in expected_results) {
var actual = results[k],
expected = expected_results[k];
const actual = results[k];
const expected = expected_results[k];
var msg = (expected[1] || '') +
(' [expected: ' + expected[0] + ' / actual: ' + actual + ']');

View File

@ -103,8 +103,8 @@ if (cluster.isWorker) {
function checkResults(expected_results, results) {
for (var k in expected_results) {
var actual = results[k],
expected = expected_results[k];
const actual = results[k];
const expected = expected_results[k];
var msg = (expected[1] || '') +
(' [expected: ' + expected[0] + ' / actual: ' + actual + ']');

View File

@ -15,11 +15,11 @@ crypto.DEFAULT_ENCODING = 'buffer';
* Input data
*/
var ODD_LENGTH_PLAIN = 'Hello node world!',
EVEN_LENGTH_PLAIN = 'Hello node world!AbC09876dDeFgHi';
const ODD_LENGTH_PLAIN = 'Hello node world!';
const EVEN_LENGTH_PLAIN = 'Hello node world!AbC09876dDeFgHi';
var KEY_PLAIN = 'S3c.r.e.t.K.e.Y!',
IV_PLAIN = 'blahFizz2011Buzz';
const KEY_PLAIN = 'S3c.r.e.t.K.e.Y!';
const IV_PLAIN = 'blahFizz2011Buzz';
var CIPHER_NAME = 'aes-128-cbc';

View File

@ -43,11 +43,11 @@ if (!common.hasFipsCrypto) {
}
// Decipher._flush() should emit an error event, not an exception.
var key = new Buffer('48fb56eb10ffeb13fc0ef551bbca3b1b', 'hex'),
badkey = new Buffer('12341234123412341234123412341234', 'hex'),
iv = new Buffer('6d358219d1f488f5f4eb12820a66d146', 'hex'),
cipher = crypto.createCipheriv('aes-128-cbc', key, iv),
decipher = crypto.createDecipheriv('aes-128-cbc', badkey, iv);
const key = new Buffer('48fb56eb10ffeb13fc0ef551bbca3b1b', 'hex');
const badkey = new Buffer('12341234123412341234123412341234', 'hex');
const iv = new Buffer('6d358219d1f488f5f4eb12820a66d146', 'hex');
const cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
const decipher = crypto.createDecipheriv('aes-128-cbc', badkey, iv);
cipher.pipe(decipher)
.on('error', common.mustCall(function end(err) {

View File

@ -5,8 +5,14 @@ var dgram = require('dgram');
var message = new Buffer('Some bytes');
var client = dgram.createSocket('udp4');
client.send(message, 0, message.length, 41234, 'localhost',
function(err, bytes) {
assert.strictEqual(bytes, message.length);
client.close();
});
client.send(
message,
0,
message.length,
41234,
'localhost',
function(err, bytes) {
assert.strictEqual(bytes, message.length);
client.close();
}
);

View File

@ -2,9 +2,9 @@
// Ensure that if a dgram socket is closed before the DNS lookup completes, it
// won't crash.
var assert = require('assert'),
common = require('../common'),
dgram = require('dgram');
const assert = require('assert');
const common = require('../common');
const dgram = require('dgram');
var buf = new Buffer(1024);
buf.fill(42);

View File

@ -1,9 +1,9 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
dgram = require('dgram'),
thrown = false,
socket = dgram.createSocket('udp4');
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
let thrown = false;
socket.bind(common.PORT);
socket.on('listening', function() {

View File

@ -1,11 +1,11 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var dgram = require('dgram'), server, client,
server_port = common.PORT,
message_to_send = 'A message to send',
timer;
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const server_port = common.PORT;
const message_to_send = 'A message to send';
let server, client;
let timer;
server = dgram.createSocket('udp4');
server.on('message', function(msg, rinfo) {
@ -28,13 +28,19 @@ server.on('listening', function() {
client.close();
server.close();
});
client.send(message_to_send, 0, message_to_send.length,
server_port, 'localhost', function(err) {
if (err) {
console.log('Caught error in client send.');
throw err;
}
});
client.send(
message_to_send,
0,
message_to_send.length,
server_port,
'localhost',
function(err) {
if (err) {
console.log('Caught error in client send.');
throw err;
}
}
);
client.on('close',
function() {
if (server.fd === null) {

View File

@ -140,24 +140,24 @@ if (process.argv[2] === 'child') {
}
testDomainExceptionHandling('--abort_on_uncaught_exception', {
throwInDomainErrHandler: false,
useTryCatch: false
});
throwInDomainErrHandler: false,
useTryCatch: false
});
testDomainExceptionHandling('--abort_on_uncaught_exception', {
throwInDomainErrHandler: false,
useTryCatch: true
});
throwInDomainErrHandler: false,
useTryCatch: true
});
testDomainExceptionHandling('--abort_on_uncaught_exception', {
throwInDomainErrHandler: true,
useTryCatch: false
});
throwInDomainErrHandler: true,
useTryCatch: false
});
testDomainExceptionHandling('--abort_on_uncaught_exception', {
throwInDomainErrHandler: true,
useTryCatch: true
});
throwInDomainErrHandler: true,
useTryCatch: true
});
testDomainExceptionHandling({
throwInDomainErrHandler: false

View File

@ -3,8 +3,8 @@ require('../common');
var assert = require('assert');
var events = require('events');
var e = new events.EventEmitter(),
num_args_emited = [];
const e = new events.EventEmitter();
const num_args_emited = [];
e.on('numArgs', function() {
var numArgs = arguments.length;

View File

@ -7,50 +7,50 @@ var fs = require('fs');
var fn = path.join(common.tmpDir, 'write.txt');
common.refreshTmpDir();
var file = fs.createWriteStream(fn, {
highWaterMark: 10
});
highWaterMark: 10
});
var EXPECTED = '012345678910';
var callbacks = {
open: -1,
drain: -2,
close: -1
};
open: -1,
drain: -2,
close: -1
};
file
.on('open', function(fd) {
console.error('open!');
callbacks.open++;
assert.equal('number', typeof fd);
})
console.error('open!');
callbacks.open++;
assert.equal('number', typeof fd);
})
.on('error', function(err) {
throw err;
})
throw err;
})
.on('drain', function() {
console.error('drain!', callbacks.drain);
callbacks.drain++;
if (callbacks.drain == -1) {
assert.equal(EXPECTED, fs.readFileSync(fn, 'utf8'));
file.write(EXPECTED);
} else if (callbacks.drain == 0) {
assert.equal(EXPECTED + EXPECTED, fs.readFileSync(fn, 'utf8'));
file.end();
}
})
console.error('drain!', callbacks.drain);
callbacks.drain++;
if (callbacks.drain == -1) {
assert.equal(EXPECTED, fs.readFileSync(fn, 'utf8'));
file.write(EXPECTED);
} else if (callbacks.drain == 0) {
assert.equal(EXPECTED + EXPECTED, fs.readFileSync(fn, 'utf8'));
file.end();
}
})
.on('close', function() {
console.error('close!');
assert.strictEqual(file.bytesWritten, EXPECTED.length * 2);
console.error('close!');
assert.strictEqual(file.bytesWritten, EXPECTED.length * 2);
callbacks.close++;
assert.throws(function() {
console.error('write after end should not be allowed');
file.write('should not work anymore');
});
fs.unlinkSync(fn);
callbacks.close++;
assert.throws(function() {
console.error('write after end should not be allowed');
file.write('should not work anymore');
});
fs.unlinkSync(fn);
});
for (var i = 0; i < 11; i++) {
(function(i) {
file.write('' + i);

View File

@ -1,16 +1,15 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path'),
fs = require('fs');
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
var filepath = path.join(common.tmpDir, 'write_pos.txt');
var cb_expected = 'write open close write open close write open close ',
cb_occurred = '';
const cb_expected = 'write open close write open close write open close ';
let cb_occurred = '';
var fileDataInitial = 'abcdefghijklmnopqrstuvwxyz';
@ -126,8 +125,8 @@ function run_test_2() {
function run_test_3() {
var file, options;
var data = '\u2026\u2026', // 3 bytes * 2 = 6 bytes in UTF-8
fileData;
const data = '\u2026\u2026'; // 3 bytes * 2 = 6 bytes in UTF-8
let fileData;
options = { start: 10,
flags: 'r+' };

View File

@ -51,8 +51,8 @@ if (common.isWindows) {
mode_sync = 0o644;
}
var file1 = path.join(common.fixturesDir, 'a.js'),
file2 = path.join(common.fixturesDir, 'a1.js');
const file1 = path.join(common.fixturesDir, 'a.js');
const file2 = path.join(common.fixturesDir, 'a1.js');
fs.chmod(file1, mode_async.toString(8), function(err) {
if (err) {

View File

@ -1,14 +1,13 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path'),
fs = require('fs'),
fn = path.join(common.fixturesDir, 'non-existent'),
existingFile = path.join(common.fixturesDir, 'exit.js'),
existingFile2 = path.join(common.fixturesDir, 'create-file.js'),
existingDir = path.join(common.fixturesDir, 'empty'),
existingDir2 = path.join(common.fixturesDir, 'keys');
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const fn = path.join(common.fixturesDir, 'non-existent');
const existingFile = path.join(common.fixturesDir, 'exit.js');
const existingFile2 = path.join(common.fixturesDir, 'create-file.js');
const existingDir = path.join(common.fixturesDir, 'empty');
const existingDir2 = path.join(common.fixturesDir, 'keys');
// ASYNC_CALL
@ -78,8 +77,8 @@ fs.readFile(fn, function(err) {
// Sync
var errors = [],
expected = 0;
const errors = [];
let expected = 0;
try {
++expected;

View File

@ -29,7 +29,8 @@ assert.equal(fs._stringToFlags('xa'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL);
assert.equal(fs._stringToFlags('ax+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
assert.equal(fs._stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
('+ +a +r +w rw wa war raw r++ a++ w++' +
'x +x x+ rx rx+ wxx wax xwx xxx').split(' ').forEach(function(flags) {
assert.throws(function() { fs._stringToFlags(flags); });
});
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
.split(' ')
.forEach(function(flags) {
assert.throws(function() { fs._stringToFlags(flags); });
});

View File

@ -1,15 +1,15 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path'),
Buffer = require('buffer').Buffer,
fs = require('fs'),
filepath = path.join(common.fixturesDir, 'x.txt'),
fd = fs.openSync(filepath, 'r'),
expected = 'xyz\n',
bufferAsync = new Buffer(expected.length),
bufferSync = new Buffer(expected.length),
readCalled = 0;
const common = require('../common');
const assert = require('assert');
const path = require('path');
const Buffer = require('buffer').Buffer;
const fs = require('fs');
const filepath = path.join(common.fixturesDir, 'x.txt');
const fd = fs.openSync(filepath, 'r');
const expected = 'xyz\n';
const bufferAsync = new Buffer(expected.length);
const bufferSync = new Buffer(expected.length);
let readCalled = 0;
fs.read(fd, bufferAsync, 0, expected.length, 0, function(err, bytesRead) {
readCalled++;

View File

@ -1,12 +1,12 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path'),
fs = require('fs'),
filepath = path.join(common.fixturesDir, 'x.txt'),
fd = fs.openSync(filepath, 'r'),
expected = 'xyz\n',
readCalled = 0;
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const filepath = path.join(common.fixturesDir, 'x.txt');
const fd = fs.openSync(filepath, 'r');
const expected = 'xyz\n';
let readCalled = 0;
fs.read(fd, expected.length, 0, 'utf-8', function(err, str, bytesRead) {
readCalled++;

View File

@ -1,10 +1,9 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path'),
fs = require('fs'),
fn = path.join(common.fixturesDir, 'empty.txt');
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const fn = path.join(common.fixturesDir, 'empty.txt');
fs.readFile(fn, function(err, data) {
assert.ok(data);

View File

@ -1,10 +1,9 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path'),
fs = require('fs'),
fn = path.join(common.fixturesDir, 'empty.txt');
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const fn = path.join(common.fixturesDir, 'empty.txt');
tempFd(function(fd, close) {
fs.readFile(fd, function(err, data) {

View File

@ -1,10 +1,10 @@
'use strict';
var assert = require('assert'),
common = require('../common'),
fs = require('fs'),
path = require('path'),
dirName = path.resolve(common.fixturesDir, 'test-readfile-unlink'),
fileName = path.resolve(dirName, 'test.bin');
const assert = require('assert');
const common = require('../common');
const fs = require('fs');
const path = require('path');
const dirName = path.resolve(common.fixturesDir, 'test-readfile-unlink');
const fileName = path.resolve(dirName, 'test.bin');
var buf = new Buffer(512 * 1024);
buf.fill(42);

View File

@ -85,8 +85,8 @@ function test_simple_relative_symlink(callback) {
console.log('1..0 # Skipped: symlink test (no privs)');
return runNextTest();
}
var entry = common.tmpDir + '/symlink',
expected = common.tmpDir + '/cycles/root.js';
const entry = common.tmpDir + '/symlink';
const expected = common.tmpDir + '/cycles/root.js';
[
[entry, '../' + common.tmpDirName + '/cycles/root.js']
].forEach(function(t) {
@ -111,8 +111,8 @@ function test_simple_absolute_symlink(callback) {
console.log('using type=%s', type);
var entry = tmpAbsDir + '/symlink',
expected = common.fixturesDir + '/nested-index/one';
const entry = tmpAbsDir + '/symlink';
const expected = common.fixturesDir + '/nested-index/one';
[
[entry, expected]
].forEach(function(t) {
@ -490,8 +490,8 @@ function test_lying_cache_liar(cb) {
});
assert(called === false);
var test = path.resolve('/a/b/c/d'),
expect = path.resolve('/a/b/d');
const test = path.resolve('/a/b/c/d');
const expect = path.resolve('/a/b/d');
var actual = fs.realpathSync(test, cache);
assert.equal(expect, actual);
fs.realpath(test, cache, function(er, actual) {

View File

@ -1,13 +1,13 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path'),
Buffer = require('buffer').Buffer,
fs = require('fs'),
filename = path.join(common.tmpDir, 'write.txt'),
expected = new Buffer('hello'),
openCalled = 0,
writeCalled = 0;
const common = require('../common');
const assert = require('assert');
const path = require('path');
const Buffer = require('buffer').Buffer;
const fs = require('fs');
const filename = path.join(common.tmpDir, 'write.txt');
const expected = new Buffer('hello');
let openCalled = 0;
let writeCalled = 0;
common.refreshTmpDir();

View File

@ -1,17 +1,16 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path'),
fs = require('fs');
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
var file = path.join(common.tmpDir, 'write.txt');
common.refreshTmpDir();
var stream = fs.WriteStream(file),
_fs_close = fs.close,
_fs_open = fs.open;
const stream = fs.WriteStream(file);
const _fs_close = fs.close;
const _fs_open = fs.open;
// change the fs.open with an identical function after the WriteStream
// has pushed it onto its internal action queue, but before it's

View File

@ -1,17 +1,16 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path'),
fs = require('fs');
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
var file = path.join(common.tmpDir, 'write.txt');
common.refreshTmpDir();
(function() {
var stream = fs.WriteStream(file),
_fs_close = fs.close;
const stream = fs.WriteStream(file);
const _fs_close = fs.close;
fs.close = function(fd) {
assert.ok(fd, 'fs.close must not be called without an undefined fd.');

View File

@ -11,8 +11,8 @@ assert.equal('foo', global.baseFoo, 'x -> global.x in base level not working');
assert.equal('bar', baseBar, 'global.x -> x in base level not working');
var module = require('../fixtures/global/plain'),
fooBar = module.fooBar;
var module = require('../fixtures/global/plain');
const fooBar = module.fooBar;
assert.equal('foo', fooBar.foo, 'x -> global.x in sub level not working');

View File

@ -1,7 +1,7 @@
'use strict';
var assert = require('assert'),
common = require('../common'),
http = require('http');
const assert = require('assert');
const common = require('../common');
const http = require('http');
var complete;

View File

@ -1,8 +1,8 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
http = require('http'),
domain = require('domain');
const common = require('../common');
const assert = require('assert');
const http = require('http');
const domain = require('domain');
var gotDomainError = false;
var d;

View File

@ -15,8 +15,8 @@ var options = {
//http.globalAgent.maxSockets = 15;
var server = http.createServer(function(req, res) {
var m = /\/(.*)/.exec(req.url),
reqid = parseInt(m[1], 10);
const m = /\/(.*)/.exec(req.url);
const reqid = parseInt(m[1], 10);
if ( reqid % 2 ) {
// do not reply the request
} else {

View File

@ -1,19 +1,19 @@
'use strict';
var common = require('../common');
var http = require('http'),
PORT = common.PORT,
SSLPORT = common.PORT + 1,
assert = require('assert'),
hostExpect = 'localhost',
fs = require('fs'),
path = require('path'),
fixtures = path.resolve(__dirname, '../fixtures/keys'),
options = {
key: fs.readFileSync(fixtures + '/agent1-key.pem'),
cert: fs.readFileSync(fixtures + '/agent1-cert.pem')
},
gotHttpsResp = false,
gotHttpResp = false;
const common = require('../common');
const http = require('http');
const PORT = common.PORT;
const SSLPORT = common.PORT + 1;
const assert = require('assert');
const hostExpect = 'localhost';
const fs = require('fs');
const path = require('path');
const fixtures = path.resolve(__dirname, '../fixtures/keys');
const options = {
key: fs.readFileSync(fixtures + '/agent1-key.pem'),
cert: fs.readFileSync(fixtures + '/agent1-cert.pem')
};
let gotHttpsResp = false;
let gotHttpResp = false;
if (common.hasCrypto) {
var https = require('https');

View File

@ -1,7 +1,7 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
http = require('http');
const common = require('../common');
const assert = require('assert');
const http = require('http');
var testIndex = 0;
const testCount = 2 * 4 * 6;
@ -10,24 +10,24 @@ const responseBody = 'Hi mars!';
var server = http.createServer(function(req, res) {
function reply(header) {
switch (testIndex % 4) {
case 0:
res.writeHead(200, { a: header, b: header });
break;
case 1:
res.setHeader('a', header);
res.setHeader('b', header);
res.writeHead(200);
break;
case 2:
res.setHeader('a', header);
res.writeHead(200, { b: header });
break;
case 3:
res.setHeader('a', [header]);
res.writeHead(200, { b: header });
break;
default:
assert.fail(null, null, 'unreachable');
case 0:
res.writeHead(200, { a: header, b: header });
break;
case 1:
res.setHeader('a', header);
res.setHeader('b', header);
res.writeHead(200);
break;
case 2:
res.setHeader('a', header);
res.writeHead(200, { b: header });
break;
case 3:
res.setHeader('a', [header]);
res.writeHead(200, { b: header });
break;
default:
assert.fail(null, null, 'unreachable');
}
res.write(responseBody);
if (testIndex % 8 < 4) {

View File

@ -1,8 +1,8 @@
'use strict';
var http = require('http'),
common = require('../common'),
assert = require('assert'),
httpServer = http.createServer(reqHandler);
const http = require('http');
const common = require('../common');
const assert = require('assert');
const httpServer = http.createServer(reqHandler);
function reqHandler(req, res) {
console.log('Got request: ' + req.headers.host + ' ' + req.url);

View File

@ -1,7 +1,7 @@
'use strict';
var common = require('../common');
var http = require('http'),
assert = require('assert');
const common = require('../common');
const http = require('http');
const assert = require('assert');
if (!common.hasMultiLocalhost()) {
console.log('1..0 # Skipped: platform-specific test.');

View File

@ -333,8 +333,8 @@ function expectBody(expected) {
assert.equal(versionMinor, 1);
};
var body_part = 0,
body_parts = ['123', '123456', '1234567890'];
let body_part = 0;
const body_parts = ['123', '123456', '1234567890'];
var onBody = function(buf, start, len) {
var body = '' + buf.slice(start, start + len);
@ -371,8 +371,8 @@ function expectBody(expected) {
assert.equal(versionMinor, 1);
};
var body_part = 0,
body_parts =
let body_part = 0;
const body_parts =
['123', '123456', '123456789', '123456789ABC', '123456789ABCDEF'];
var onBody = function(buf, start, len) {

View File

@ -23,20 +23,22 @@ server.listen(port, function() {
var count = 0;
function createRequest() {
var req = http.request({port: port, path: '/', agent: agent},
function(res) {
req.clearTimeout(callback);
const req = http.request(
{port: port, path: '/', agent: agent},
function(res) {
req.clearTimeout(callback);
res.on('end', function() {
count++;
res.on('end', function() {
count++;
if (count == 11) {
server.close();
}
});
if (count == 11) {
server.close();
}
});
res.resume();
});
res.resume();
}
);
req.setTimeout(1000, callback);
return req;

View File

@ -8,12 +8,12 @@ if (!common.hasCrypto) {
}
var https = require('https');
var fs = require('fs'),
options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
},
httpsServer = https.createServer(options, reqHandler);
const fs = require('fs');
const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
};
const httpsServer = https.createServer(options, reqHandler);
function reqHandler(req, res) {
console.log('Got request: ' + req.headers.host + ' ' + req.url);

View File

@ -1,7 +1,7 @@
'use strict';
var common = require('../common'),
fs = require('fs'),
assert = require('assert');
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');

View File

@ -14,7 +14,8 @@ net.Server().listen({ port: '' + common.PORT }, close);
1 / 0,
-1 / 0,
'+Infinity',
'-Infinity' ].forEach(function(port) {
'-Infinity'
].forEach(function(port) {
assert.throws(function() {
net.Server().listen({ port: port }, assert.fail);
}, /"port" option should be >= 0 and < 65536/i);

View File

@ -1,11 +1,11 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
net = require('net');
const common = require('../common');
const assert = require('assert');
const net = require('net');
var connections = 0,
dataEvents = 0,
conn;
let connections = 0;
let dataEvents = 0;
let conn;
// Server

View File

@ -38,14 +38,14 @@ var server = net.createServer(function(socket) {
socket.end();
}).listen(common.PORT, function() {
var conn = net.connect(common.PORT);
conn.on('data', function(buf) {
conn.pause();
setTimeout(function() {
conn.destroy();
}, 20);
});
var conn = net.connect(common.PORT);
conn.on('data', function(buf) {
conn.pause();
setTimeout(function() {
conn.destroy();
}, 20);
});
});
process.on('exit', function() {
assert.equal(server.connections, 0);

View File

@ -2,8 +2,8 @@
require('../common');
var assert = require('assert');
var order = [],
exceptionHandled = false;
const order = [];
let exceptionHandled = false;
// This nextTick function will throw an error. It should only be called once.
// When it throws an error, it should still get removed from the queue.

View File

@ -86,7 +86,7 @@ function checkErrors(path) {
errors.forEach(function(errorCase) {
try {
path[errorCase.method].apply(path, errorCase.input);
} catch(err) {
} catch (err) {
assert.ok(err instanceof TypeError);
assert.ok(
errorCase.message.test(err.message),

View File

@ -1,8 +1,8 @@
'use strict';
require('../common');
var assert = require('assert'),
path = require('path'),
child_process = require('child_process');
const assert = require('assert');
const path = require('path');
const child_process = require('child_process');
var nodeBinary = process.argv[0];

View File

@ -234,23 +234,27 @@ asyncTest('When re-throwing new errors in a promise catch, only the re-thrown' +
var promise2;
});
asyncTest('unhandledRejection should not be triggered if a promise catch is' +
' attached synchronously upon the promise\'s creation',
function(done) {
var e = new Error();
onUnhandledFail(done);
Promise.reject(e).then(common.fail, function() {});
});
asyncTest(
'unhandledRejection should not be triggered if a promise catch is' +
' attached synchronously upon the promise\'s creation',
function(done) {
var e = new Error();
onUnhandledFail(done);
Promise.reject(e).then(common.fail, function() {});
}
);
asyncTest('unhandledRejection should not be triggered if a promise catch is' +
' attached synchronously upon the promise\'s creation',
function(done) {
var e = new Error();
onUnhandledFail(done);
new Promise(function(_, reject) {
reject(e);
}).then(common.fail, function() {});
});
asyncTest(
'unhandledRejection should not be triggered if a promise catch is' +
' attached synchronously upon the promise\'s creation',
function(done) {
var e = new Error();
onUnhandledFail(done);
new Promise(function(_, reject) {
reject(e);
}).then(common.fail, function() {});
}
);
asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' +
' prevent unhandledRejection', function(done) {
@ -360,19 +364,21 @@ asyncTest('A rejected promise derived from throwing in a fulfillment handler' +
});
});
asyncTest('A rejected promise derived from returning a synchronously-rejected' +
' promise in a fulfillment handler does trigger unhandledRejection',
function(done) {
var e = new Error();
var _promise;
onUnhandledSucceed(done, function(reason, promise) {
assert.strictEqual(e, reason);
assert.strictEqual(_promise, promise);
});
_promise = Promise.resolve().then(function() {
return Promise.reject(e);
});
});
asyncTest(
'A rejected promise derived from returning a synchronously-rejected' +
' promise in a fulfillment handler does trigger unhandledRejection',
function(done) {
var e = new Error();
var _promise;
onUnhandledSucceed(done, function(reason, promise) {
assert.strictEqual(e, reason);
assert.strictEqual(_promise, promise);
});
_promise = Promise.resolve().then(function() {
return Promise.reject(e);
});
}
);
// Combinations with Promise.all
asyncTest('Catching the Promise.all() of a collection that includes a' +
@ -382,21 +388,23 @@ asyncTest('Catching the Promise.all() of a collection that includes a' +
Promise.all([Promise.reject(e)]).then(common.fail, function() {});
});
asyncTest('Catching the Promise.all() of a collection that includes a ' +
'nextTick-async rejected promise prevents unhandledRejection',
function(done) {
var e = new Error();
onUnhandledFail(done);
var p = new Promise(function(_, reject) {
process.nextTick(function() {
reject(e);
asyncTest(
'Catching the Promise.all() of a collection that includes a ' +
'nextTick-async rejected promise prevents unhandledRejection',
function(done) {
var e = new Error();
onUnhandledFail(done);
var p = new Promise(function(_, reject) {
process.nextTick(function() {
reject(e);
});
});
});
p = Promise.all([p]);
process.nextTick(function() {
p.then(common.fail, function() {});
});
});
p = Promise.all([p]);
process.nextTick(function() {
p.then(common.fail, function() {});
});
}
);
asyncTest('Failing to catch the Promise.all() of a collection that includes' +
' a rejected promise triggers unhandledRejection for the returned' +
@ -513,26 +521,28 @@ asyncTest('Waiting for some combination of promise microtasks + ' +
});
});
asyncTest('Waiting for some combination of promise microtasks +' +
' process.nextTick to attach a catch handler is still soon enough' +
' to prevent unhandledRejection: inside setImmediate',
function(done) {
var e = new Error();
onUnhandledFail(done);
asyncTest(
'Waiting for some combination of promise microtasks +' +
' process.nextTick to attach a catch handler is still soon enough' +
' to prevent unhandledRejection: inside setImmediate',
function(done) {
var e = new Error();
onUnhandledFail(done);
setImmediate(function() {
var a = Promise.reject(e);
Promise.resolve().then(function() {
process.nextTick(function() {
Promise.resolve().then(function() {
process.nextTick(function() {
a.catch(function() {});
setImmediate(function() {
var a = Promise.reject(e);
Promise.resolve().then(function() {
process.nextTick(function() {
Promise.resolve().then(function() {
process.nextTick(function() {
a.catch(function() {});
});
});
});
});
});
});
});
}
);
asyncTest('Waiting for some combination of promise microtasks +' +
' process.nextTick to attach a catch handler is still soon enough' +
@ -612,28 +622,30 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch' +
});
});
asyncTest('Promise unhandledRejection handler does not interfere with domain' +
' error handlers being given exceptions thrown from nextTick.',
function(done) {
var d = domain.create();
var domainReceivedError;
d.on('error', function(e) {
domainReceivedError = e;
});
d.run(function() {
var e = new Error('error');
var domainError = new Error('domain error');
onUnhandledSucceed(done, function(reason, promise) {
assert.strictEqual(reason, e);
assert.strictEqual(domainReceivedError, domainError);
d.dispose();
asyncTest(
'Promise unhandledRejection handler does not interfere with domain' +
' error handlers being given exceptions thrown from nextTick.',
function(done) {
var d = domain.create();
var domainReceivedError;
d.on('error', function(e) {
domainReceivedError = e;
});
Promise.reject(e);
process.nextTick(function() {
throw domainError;
d.run(function() {
var e = new Error('error');
var domainError = new Error('domain error');
onUnhandledSucceed(done, function(reason, promise) {
assert.strictEqual(reason, e);
assert.strictEqual(domainReceivedError, domainError);
d.dispose();
});
Promise.reject(e);
process.nextTick(function() {
throw domainError;
});
});
});
});
}
);
asyncTest('nextTick is immediately scheduled when called inside an event' +
' handler', function(done) {

View File

@ -182,12 +182,11 @@ assert.equal(
// Test removing limit
function testUnlimitedKeys() {
var query = {},
url;
const query = {};
for (var i = 0; i < 2000; i++) query[i] = i;
url = qs.stringify(query);
const url = qs.stringify(query);
assert.equal(
Object.keys(qs.parse(url, null, null, { maxKeys: 0 })).length,

View File

@ -259,7 +259,7 @@ function isWarned(emitter) {
});
try {
fi.emit('data', 'fooX');
} catch(e) { }
} catch (e) { }
fi.emit('data', 'bar');
assert.equal(keys.join(''), 'fooXbar');
rli.close();

View File

@ -1,7 +1,7 @@
'use strict';
require('../common');
var assert = require('assert'),
vm = require('vm');
const assert = require('assert');
const vm = require('vm');
assert.doesNotThrow(function() {
var context = vm.createContext({ process: process });

View File

@ -1,7 +1,7 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
repl = require('repl');
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
// Create a dummy stream that does nothing
const stream = new common.ArrayStream();

View File

@ -2,9 +2,9 @@
require('../common');
const stream = require('stream'),
assert = require('assert'),
repl = require('repl');
const stream = require('stream');
const assert = require('assert');
const repl = require('repl');
var output = '';
const inputStream = new stream.PassThrough();

View File

@ -1,9 +1,9 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
repl = require('repl'),
terminalExit = 0,
regularExit = 0;
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
let terminalExit = 0;
let regularExit = 0;
// Create a dummy stream that does nothing
const stream = new common.ArrayStream();

View File

@ -8,30 +8,32 @@ const REPL = require('internal/repl');
const assert = require('assert');
const inspect = require('util').inspect;
const tests = [{
env: {},
expected: { terminal: true, useColors: true }
},
{
env: { NODE_DISABLE_COLORS: '1' },
expected: { terminal: true, useColors: false }
},
{
env: { NODE_NO_READLINE: '1' },
expected: { terminal: false, useColors: false }
},
{
env: { TERM: 'dumb' },
expected: { terminal: true, useColors: false }
},
{
env: { NODE_NO_READLINE: '1', NODE_DISABLE_COLORS: '1' },
expected: { terminal: false, useColors: false }
},
{
env: { NODE_NO_READLINE: '0' },
expected: { terminal: true, useColors: true }
}];
const tests = [
{
env: {},
expected: { terminal: true, useColors: true }
},
{
env: { NODE_DISABLE_COLORS: '1' },
expected: { terminal: true, useColors: false }
},
{
env: { NODE_NO_READLINE: '1' },
expected: { terminal: false, useColors: false }
},
{
env: { TERM: 'dumb' },
expected: { terminal: true, useColors: false }
},
{
env: { NODE_NO_READLINE: '1', NODE_DISABLE_COLORS: '1' },
expected: { terminal: false, useColors: false }
},
{
env: { NODE_NO_READLINE: '0' },
expected: { terminal: true, useColors: true }
}
];
function run(test) {
const env = test.env;

View File

@ -1,7 +1,7 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
repl = require('repl');
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
common.globalCheck = false;

View File

@ -79,107 +79,109 @@ const enoentHistoryPath = path.join(fixtures, 'enoent-repl-history-file.json');
const emptyHistoryPath = path.join(fixtures, '.empty-repl-history-file');
const defaultHistoryPath = path.join(common.tmpDir, '.node_repl_history');
const tests = [{
env: { NODE_REPL_HISTORY: '' },
test: [UP],
expected: [prompt, replDisabled, prompt]
},
{
env: { NODE_REPL_HISTORY: '',
NODE_REPL_HISTORY_FILE: enoentHistoryPath },
test: [UP],
expected: [prompt, replDisabled, prompt]
},
{
env: { NODE_REPL_HISTORY: '',
NODE_REPL_HISTORY_FILE: oldHistoryPath },
test: [UP],
expected: [prompt, replDisabled, prompt]
},
{
env: { NODE_REPL_HISTORY_FILE: emptyHistoryPath },
test: [UP],
expected: [prompt, convertMsg, prompt]
},
{
env: { NODE_REPL_HISTORY_FILE: defaultHistoryPath },
test: [UP],
expected: [prompt, sameHistoryFilePaths, prompt]
},
{
env: { NODE_REPL_HISTORY: historyPath },
test: [UP, CLEAR],
expected: [prompt, prompt + '\'you look fabulous today\'', prompt]
},
{
env: { NODE_REPL_HISTORY: historyPath,
NODE_REPL_HISTORY_FILE: oldHistoryPath },
test: [UP, CLEAR],
expected: [prompt, prompt + '\'you look fabulous today\'', prompt]
},
{
env: { NODE_REPL_HISTORY: historyPath,
NODE_REPL_HISTORY_FILE: '' },
test: [UP, CLEAR],
expected: [prompt, prompt + '\'you look fabulous today\'', prompt]
},
{
env: {},
test: [UP],
expected: [prompt]
},
{
env: { NODE_REPL_HISTORY_FILE: oldHistoryPath },
test: [UP, CLEAR, '\'42\'', ENTER],
expected: [prompt, convertMsg, prompt, prompt + '\'=^.^=\'', prompt, '\'',
'4', '2', '\'', '\'42\'\n', prompt, prompt],
after: function ensureHistoryFixture() {
// XXX(Fishrock123) Make sure nothing weird happened to our fixture
// or it's temporary copy.
// Sometimes this test used to erase the fixture and I'm not sure why.
const history = fs.readFileSync(historyFixturePath, 'utf8');
assert.strictEqual(history,
'\'you look fabulous today\'\n\'Stay Fresh~\'\n');
const historyCopy = fs.readFileSync(historyPath, 'utf8');
assert.strictEqual(historyCopy, '\'you look fabulous today\'' + os.EOL +
'\'Stay Fresh~\'' + os.EOL);
}
},
{ // Requires the above testcase
env: {},
test: [UP, UP, ENTER],
expected: [prompt, prompt + '\'42\'', prompt + '\'=^.^=\'', '\'=^.^=\'\n',
prompt]
},
{
env: { NODE_REPL_HISTORY: historyPath,
NODE_REPL_HISTORY_SIZE: 1 },
test: [UP, UP, CLEAR],
expected: [prompt, prompt + '\'you look fabulous today\'', prompt]
},
{
env: { NODE_REPL_HISTORY_FILE: oldHistoryPath,
NODE_REPL_HISTORY_SIZE: 1 },
test: [UP, UP, UP, CLEAR],
expected: [prompt, convertMsg, prompt, prompt + '\'=^.^=\'', prompt]
},
{
env: { NODE_REPL_HISTORY: historyPathFail,
NODE_REPL_HISTORY_SIZE: 1 },
test: [UP],
expected: [prompt, replFailedRead, prompt, replDisabled, prompt]
},
{ // Make sure this is always the last test, since we change os.homedir()
before: function mockHomedirFailure() {
// Mock os.homedir() failure
os.homedir = function() {
throw new Error('os.homedir() failure');
};
const tests = [
{
env: { NODE_REPL_HISTORY: '' },
test: [UP],
expected: [prompt, replDisabled, prompt]
},
env: {},
test: [UP],
expected: [prompt, homedirErr, prompt, replDisabled, prompt]
}];
{
env: { NODE_REPL_HISTORY: '',
NODE_REPL_HISTORY_FILE: enoentHistoryPath },
test: [UP],
expected: [prompt, replDisabled, prompt]
},
{
env: { NODE_REPL_HISTORY: '',
NODE_REPL_HISTORY_FILE: oldHistoryPath },
test: [UP],
expected: [prompt, replDisabled, prompt]
},
{
env: { NODE_REPL_HISTORY_FILE: emptyHistoryPath },
test: [UP],
expected: [prompt, convertMsg, prompt]
},
{
env: { NODE_REPL_HISTORY_FILE: defaultHistoryPath },
test: [UP],
expected: [prompt, sameHistoryFilePaths, prompt]
},
{
env: { NODE_REPL_HISTORY: historyPath },
test: [UP, CLEAR],
expected: [prompt, prompt + '\'you look fabulous today\'', prompt]
},
{
env: { NODE_REPL_HISTORY: historyPath,
NODE_REPL_HISTORY_FILE: oldHistoryPath },
test: [UP, CLEAR],
expected: [prompt, prompt + '\'you look fabulous today\'', prompt]
},
{
env: { NODE_REPL_HISTORY: historyPath,
NODE_REPL_HISTORY_FILE: '' },
test: [UP, CLEAR],
expected: [prompt, prompt + '\'you look fabulous today\'', prompt]
},
{
env: {},
test: [UP],
expected: [prompt]
},
{
env: { NODE_REPL_HISTORY_FILE: oldHistoryPath },
test: [UP, CLEAR, '\'42\'', ENTER],
expected: [prompt, convertMsg, prompt, prompt + '\'=^.^=\'', prompt, '\'',
'4', '2', '\'', '\'42\'\n', prompt, prompt],
after: function ensureHistoryFixture() {
// XXX(Fishrock123) Make sure nothing weird happened to our fixture
// or it's temporary copy.
// Sometimes this test used to erase the fixture and I'm not sure why.
const history = fs.readFileSync(historyFixturePath, 'utf8');
assert.strictEqual(history,
'\'you look fabulous today\'\n\'Stay Fresh~\'\n');
const historyCopy = fs.readFileSync(historyPath, 'utf8');
assert.strictEqual(historyCopy, '\'you look fabulous today\'' + os.EOL +
'\'Stay Fresh~\'' + os.EOL);
}
},
{ // Requires the above testcase
env: {},
test: [UP, UP, ENTER],
expected: [prompt, prompt + '\'42\'', prompt + '\'=^.^=\'', '\'=^.^=\'\n',
prompt]
},
{
env: { NODE_REPL_HISTORY: historyPath,
NODE_REPL_HISTORY_SIZE: 1 },
test: [UP, UP, CLEAR],
expected: [prompt, prompt + '\'you look fabulous today\'', prompt]
},
{
env: { NODE_REPL_HISTORY_FILE: oldHistoryPath,
NODE_REPL_HISTORY_SIZE: 1 },
test: [UP, UP, UP, CLEAR],
expected: [prompt, convertMsg, prompt, prompt + '\'=^.^=\'', prompt]
},
{
env: { NODE_REPL_HISTORY: historyPathFail,
NODE_REPL_HISTORY_SIZE: 1 },
test: [UP],
expected: [prompt, replFailedRead, prompt, replDisabled, prompt]
},
{ // Make sure this is always the last test, since we change os.homedir()
before: function mockHomedirFailure() {
// Mock os.homedir() failure
os.homedir = function() {
throw new Error('os.homedir() failure');
};
},
env: {},
test: [UP],
expected: [prompt, homedirErr, prompt, replDisabled, prompt]
}
];
const numtests = tests.length;

View File

@ -1,7 +1,7 @@
'use strict';
require('../common');
var assert = require('assert'),
repl = require('repl');
const assert = require('assert');
const repl = require('repl');
// https://github.com/joyent/node/issues/3226

View File

@ -5,17 +5,17 @@ var assert = require('assert');
common.globalCheck = false;
common.refreshTmpDir();
var net = require('net'),
repl = require('repl'),
message = 'Read, Eval, Print Loop',
prompt_unix = 'node via Unix socket> ',
prompt_tcp = 'node via TCP socket> ',
prompt_multiline = '... ',
prompt_npm = 'npm should be run outside of the ' +
'node repl, in your normal shell.\n' +
'(Press Control-D to exit.)\n',
expect_npm = prompt_npm + prompt_unix,
server_tcp, server_unix, client_tcp, client_unix, timer;
const net = require('net');
const repl = require('repl');
const message = 'Read, Eval, Print Loop';
const prompt_unix = 'node via Unix socket> ';
const prompt_tcp = 'node via TCP socket> ';
const prompt_multiline = '... ';
const prompt_npm = 'npm should be run outside of the ' +
'node repl, in your normal shell.\n' +
'(Press Control-D to exit.)\n';
const expect_npm = prompt_npm + prompt_unix;
var server_tcp, server_unix, client_tcp, client_unix, timer;
// absolute path to test/fixtures/a.js

View File

@ -10,8 +10,8 @@ if (common.isWindows) {
console.log('process.pid: ' + process.pid);
var first = 0,
second = 0;
let first = 0;
let second = 0;
var sighup = false;

View File

@ -44,24 +44,24 @@ function test(decode, uncork, multi, next) {
};
var expectChunks = decode ?
[
{ encoding: 'buffer',
chunk: [104, 101, 108, 108, 111, 44, 32] },
{ encoding: 'buffer',
chunk: [119, 111, 114, 108, 100] },
{ encoding: 'buffer',
chunk: [33] },
{ encoding: 'buffer',
chunk: [10, 97, 110, 100, 32, 116, 104, 101, 110, 46, 46, 46] },
{ encoding: 'buffer',
chunk: [250, 206, 190, 167, 222, 173, 190, 239, 222, 202, 251, 173]}
] : [
{ encoding: 'ascii', chunk: 'hello, ' },
{ encoding: 'utf8', chunk: 'world' },
{ encoding: 'buffer', chunk: [33] },
{ encoding: 'binary', chunk: '\nand then...' },
{ encoding: 'hex', chunk: 'facebea7deadbeefdecafbad' }
];
[
{ encoding: 'buffer',
chunk: [104, 101, 108, 108, 111, 44, 32] },
{ encoding: 'buffer',
chunk: [119, 111, 114, 108, 100] },
{ encoding: 'buffer',
chunk: [33] },
{ encoding: 'buffer',
chunk: [10, 97, 110, 100, 32, 116, 104, 101, 110, 46, 46, 46] },
{ encoding: 'buffer',
chunk: [250, 206, 190, 167, 222, 173, 190, 239, 222, 202, 251, 173]}
] : [
{ encoding: 'ascii', chunk: 'hello, ' },
{ encoding: 'utf8', chunk: 'world' },
{ encoding: 'buffer', chunk: [33] },
{ encoding: 'binary', chunk: '\nand then...' },
{ encoding: 'hex', chunk: 'facebea7deadbeefdecafbad' }
];
var actualChunks;
w._writev = function(chunks, cb) {

View File

@ -21,7 +21,7 @@ try {
// Try to allocate memory first then force gc so future allocations succeed.
new Buffer(2 * kStringMaxLength);
gc();
} catch(e) {
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Invalid array buffer length') throw (e);
console.log(skipMessage);

View File

@ -2,15 +2,15 @@
require('../common');
var assert = require('assert');
var immediateA = false,
immediateB = false,
immediateC = [],
before;
let immediateA = false;
let immediateB = false;
let immediateC = [];
let before;
setImmediate(function() {
try {
immediateA = process.hrtime(before);
} catch(e) {
} catch (e) {
console.log('failed to get hrtime with offset');
}
clearImmediate(immediateB);

View File

@ -2,8 +2,8 @@
require('../common');
var assert = require('assert');
var immediateThis, intervalThis, timeoutThis,
immediateArgsThis, intervalArgsThis, timeoutArgsThis;
let immediateThis, intervalThis, timeoutThis;
let immediateArgsThis, intervalArgsThis, timeoutArgsThis;
var immediateHandler = setImmediate(function() {
immediateThis = this;

View File

@ -2,12 +2,12 @@
require('../common');
var assert = require('assert');
var interval_fired = false,
timeout_fired = false,
unref_interval = false,
unref_timer = false,
unref_callbacks = 0,
interval, check_unref, checks = 0;
let interval_fired = false;
let timeout_fired = false;
let unref_interval = false;
let unref_timer = false;
let unref_callbacks = 0;
let interval, check_unref, checks = 0;
var LONG_TIME = 10 * 1000;
var SHORT_TIME = 100;

View File

@ -23,12 +23,12 @@ tls.createServer({
}).listen(common.PORT);
var socket = tls.connect({
port: common.PORT,
ca: cert,
// No host set here. 'localhost' is the default,
// but tls.checkServerIdentity() breaks before the fix with:
// Error: Hostname/IP doesn't match certificate's altnames:
// "Host: undefined. is not cert's CN: localhost"
port: common.PORT,
ca: cert,
// No host set here. 'localhost' is the default,
// but tls.checkServerIdentity() breaks before the fix with:
// Error: Hostname/IP doesn't match certificate's altnames:
// "Host: undefined. is not cert's CN: localhost"
}, function() {
assert(socket.authorized);
process.exit();

View File

@ -1,16 +1,15 @@
'use strict';
var assert = require('assert'),
fs = require('fs'),
path = require('path'),
tls = require('tls'),
stream = require('stream'),
net = require('net');
var common = require('../common');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const tls = require('tls');
const stream = require('stream');
const net = require('net');
var server;
var cert_dir = path.resolve(__dirname, '../fixtures'),
options = { key: fs.readFileSync(cert_dir + '/test_key.pem'),
var cert_dir = path.resolve(__dirname, '../fixtures');
var options = { key: fs.readFileSync(cert_dir + '/test_key.pem'),
cert: fs.readFileSync(cert_dir + '/test_cert.pem'),
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ],
ciphers: 'AES256-GCM-SHA384' };

View File

@ -5,9 +5,9 @@ if (!process.features.tls_npn) {
return;
}
var common = require('../common'),
assert = require('assert'),
fs = require('fs');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
@ -69,8 +69,8 @@ var clientsOptions = [{
rejectUnauthorized: false
}];
var serverResults = [],
clientsResults = [];
const serverResults = [];
const clientsResults = [];
var server = tls.createServer(serverOptions, function(c) {
serverResults.push(c.npnProtocol);

View File

@ -87,15 +87,14 @@ var testCases =
renegotiate: false,
CAs: ['ca2-cert'],
crl: 'ca2-crl',
clients:
[
clients: [
{ name: 'agent1', shouldReject: true, shouldAuth: false },
{ name: 'agent2', shouldReject: true, shouldAuth: false },
{ name: 'agent3', shouldReject: false, shouldAuth: true },
// Agent4 has a cert in the CRL.
{ name: 'agent4', shouldReject: true, shouldAuth: false },
{ name: 'nocert', shouldReject: true }
]
]
}
];

View File

@ -5,9 +5,9 @@ if (!process.features.tls_sni) {
return;
}
var common = require('../common'),
assert = require('assert'),
fs = require('fs');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
@ -99,12 +99,12 @@ var clientsOptions = [{
rejectUnauthorized: false
}];
var serverResults = [],
clientResults = [],
serverErrors = [],
clientErrors = [],
serverError,
clientError;
const serverResults = [];
const clientResults = [];
const serverErrors = [];
const clientErrors = [];
let serverError;
let clientError;
var server = tls.createServer(serverOptions, function(c) {
serverResults.push({ sni: c.servername, authorized: c.authorized });

View File

@ -5,9 +5,9 @@ if (!process.features.tls_sni) {
return;
}
var common = require('../common'),
assert = require('assert'),
fs = require('fs');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
@ -73,8 +73,8 @@ var clientsOptions = [{
rejectUnauthorized: false
}];
var serverResults = [],
clientResults = [];
const serverResults = [];
const clientResults = [];
var server = tls.createServer(serverOptions, function(c) {
serverResults.push(c.servername);

View File

@ -260,19 +260,19 @@ var parseTests = {
},
'http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=':
{
'href': 'http://user:pass@mt0.google.com/vt/lyrs=m@114???' +
'&hl=en&src=api&x=2&y=2&z=3&s=',
'protocol': 'http:',
'slashes': true,
'host': 'mt0.google.com',
'auth': 'user:pass',
'hostname': 'mt0.google.com',
'search': '???&hl=en&src=api&x=2&y=2&z=3&s=',
'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',
'pathname': '/vt/lyrs=m@114',
'path': '/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s='
},
{
'href': 'http://user:pass@mt0.google.com/vt/lyrs=m@114???' +
'&hl=en&src=api&x=2&y=2&z=3&s=',
'protocol': 'http:',
'slashes': true,
'host': 'mt0.google.com',
'auth': 'user:pass',
'hostname': 'mt0.google.com',
'search': '???&hl=en&src=api&x=2&y=2&z=3&s=',
'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',
'pathname': '/vt/lyrs=m@114',
'path': '/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s='
},
'file:///etc/passwd' : {
'href': 'file:///etc/passwd',
@ -870,8 +870,8 @@ for (var u in parseTests) {
assert.deepEqual(actual, expected);
assert.deepEqual(spaced, expected);
var expected = parseTests[u].href,
actual = url.format(parseTests[u]);
expected = parseTests[u].href;
actual = url.format(parseTests[u]);
assert.equal(actual, expected,
'format(' + u + ') == ' + u + '\nactual:' + actual);
@ -1194,8 +1194,8 @@ var relativeTests = [
['http://localhost', 'file://foo/Users', 'file://foo/Users']
];
relativeTests.forEach(function(relativeTest) {
var a = url.resolve(relativeTest[0], relativeTest[1]),
e = relativeTest[2];
const a = url.resolve(relativeTest[0], relativeTest[1]);
const e = relativeTest[2];
assert.equal(a, e,
'resolve(' + [relativeTest[0], relativeTest[1]] + ') == ' + e +
'\n actual=' + a);
@ -1504,8 +1504,8 @@ var relativeTests2 = [
'http://diff:auth@www.example.com/']
];
relativeTests2.forEach(function(relativeTest) {
var a = url.resolve(relativeTest[1], relativeTest[0]),
e = relativeTest[2];
const a = url.resolve(relativeTest[1], relativeTest[0]);
const e = relativeTest[2];
assert.equal(a, e,
'resolve(' + [relativeTest[1], relativeTest[0]] + ') == ' + e +
'\n actual=' + a);
@ -1516,8 +1516,8 @@ relativeTests2.forEach(function(relativeTest) {
//format: [from, path, expected]
relativeTests.forEach(function(relativeTest) {
var actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]),
expected = url.parse(relativeTest[2]);
var actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]);
var expected = url.parse(relativeTest[2]);
assert.deepEqual(actual, expected);
@ -1544,13 +1544,13 @@ if (relativeTests2[181][0] === './/g' &&
relativeTests2.splice(181, 1);
}
relativeTests2.forEach(function(relativeTest) {
var actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]),
expected = url.parse(relativeTest[2]);
var actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]);
var expected = url.parse(relativeTest[2]);
assert.deepEqual(actual, expected);
var expected = relativeTest[2],
actual = url.format(actual);
expected = relativeTest[2];
actual = url.format(actual);
assert.equal(actual, expected,
'format(' + relativeTest[1] + ') == ' + expected +

View File

@ -28,9 +28,9 @@ var tests = [
// test util.log()
tests.forEach(function(test) {
util.log(test.input);
var result = strings.shift().trim(),
re = (/[0-9]{1,2} [A-Z][a-z]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - (.+)$/),
match = re.exec(result);
const result = strings.shift().trim();
const re = (/[0-9]{1,2} [A-Z][a-z]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - (.+)$/);
const match = re.exec(result);
assert.ok(match);
assert.equal(match[1], test.output);
});

View File

@ -5,18 +5,18 @@ var zlib = require('zlib');
var path = require('path');
var fs = require('fs');
var file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg')),
chunkSize = 16,
opts = { level: 0 },
deflater = zlib.createDeflate(opts);
const file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg'));
const chunkSize = 16;
const opts = { level: 0 };
const deflater = zlib.createDeflate(opts);
var chunk = file.slice(0, chunkSize),
expectedNone = new Buffer([0x78, 0x01]),
blkhdr = new Buffer([0x00, 0x10, 0x00, 0xef, 0xff]),
adler32 = new Buffer([0x00, 0x00, 0x00, 0xff, 0xff]),
expectedFull = Buffer.concat([blkhdr, chunk, adler32]),
actualNone,
actualFull;
const chunk = file.slice(0, chunkSize);
const expectedNone = new Buffer([0x78, 0x01]);
const blkhdr = new Buffer([0x00, 0x10, 0x00, 0xef, 0xff]);
const adler32 = new Buffer([0x00, 0x00, 0x00, 0xff, 0xff]);
const expectedFull = Buffer.concat([blkhdr, chunk, adler32]);
let actualNone;
let actualFull;
deflater.write(chunk, function() {
deflater.flush(zlib.Z_NO_FLUSH, function() {

View File

@ -2,8 +2,8 @@
// test uncompressing invalid input
require('../common');
var assert = require('assert'),
zlib = require('zlib');
const assert = require('assert');
const zlib = require('zlib');
var nonStringInputs = [1, true, {a: 1}, ['a']];

View File

@ -5,16 +5,16 @@ var zlib = require('zlib');
var path = require('path');
var fs = require('fs');
var file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg')),
chunkSize = 24 * 1024,
opts = { level: 9, strategy: zlib.Z_DEFAULT_STRATEGY },
deflater = zlib.createDeflate(opts);
const file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg'));
const chunkSize = 24 * 1024;
const opts = { level: 9, strategy: zlib.Z_DEFAULT_STRATEGY };
const deflater = zlib.createDeflate(opts);
var chunk1 = file.slice(0, chunkSize),
chunk2 = file.slice(chunkSize),
blkhdr = new Buffer([0x00, 0x48, 0x82, 0xb7, 0x7d]),
expected = Buffer.concat([blkhdr, chunk2]),
actual;
const chunk1 = file.slice(0, chunkSize);
const chunk2 = file.slice(chunkSize);
const blkhdr = new Buffer([0x00, 0x48, 0x82, 0xb7, 0x7d]);
const expected = Buffer.concat([blkhdr, chunk2]);
let actual;
deflater.write(chunk1, function() {
deflater.params(0, zlib.Z_DEFAULT_STRATEGY, function() {

View File

@ -11,8 +11,8 @@ var crypto = require('crypto');
var p = crypto.createDiffieHellman(1024).getPrime();
for (var i = 0; i < 2000; i++) {
var a = crypto.createDiffieHellman(p),
b = crypto.createDiffieHellman(p);
const a = crypto.createDiffieHellman(p);
const b = crypto.createDiffieHellman(p);
a.generateKeys();
b.generateKeys();

View File

@ -17,19 +17,21 @@ var success_count = 0;
var error_count = 0;
exec('"' + process.execPath + '" -p -e process.versions',
function(err, stdout, stderr) {
if (err) {
error_count++;
console.log('error!: ' + err.code);
console.log('stdout: ' + JSON.stringify(stdout));
console.log('stderr: ' + JSON.stringify(stderr));
assert.equal(false, err.killed);
} else {
success_count++;
console.dir(stdout);
exec(
'"' + process.execPath + '" -p -e process.versions',
function(err, stdout, stderr) {
if (err) {
error_count++;
console.log('error!: ' + err.code);
console.log('stdout: ' + JSON.stringify(stdout));
console.log('stderr: ' + JSON.stringify(stderr));
assert.equal(false, err.killed);
} else {
success_count++;
console.dir(stdout);
}
}
});
);
exec('thisisnotavalidcommand', function(err, stdout, stderr) {

View File

@ -19,19 +19,19 @@ catch (e) {
fs.watchFile(FILENAME, {interval:TIMEOUT - 250}, function(curr, prev) {
console.log([curr, prev]);
switch (++nevents) {
case 1:
assert.equal(common.fileExists(FILENAME), false);
break;
case 2:
case 3:
assert.equal(common.fileExists(FILENAME), true);
break;
case 4:
assert.equal(common.fileExists(FILENAME), false);
fs.unwatchFile(FILENAME);
break;
default:
assert(0);
case 1:
assert.equal(common.fileExists(FILENAME), false);
break;
case 2:
case 3:
assert.equal(common.fileExists(FILENAME), true);
break;
case 4:
assert.equal(common.fileExists(FILENAME), false);
fs.unwatchFile(FILENAME);
break;
default:
assert(0);
}
});

View File

@ -1,9 +1,8 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var net = require('net'),
http = require('http');
const common = require('../common');
const assert = require('assert');
const net = require('net');
const http = require('http');
var errorCount = 0;
var eofCount = 0;

View File

@ -2,10 +2,10 @@
// This tests setTimeout() by having multiple clients connecting and sending
// data in random intervals. Clients are also randomly disconnecting until there
// are no more clients left. If no false timeout occurs, this test has passed.
var common = require('../common'),
http = require('http'),
server = http.createServer(),
connections = 0;
const common = require('../common');
const http = require('http');
const server = http.createServer();
let connections = 0;
server.on('request', function(req, res) {
req.socket.setTimeout(1000);

View File

@ -12,8 +12,7 @@ var start = Date.now();
var err;
var caught = false;
try
{
try {
var cmd = `"${process.execPath}" -e "setTimeout(function(){}, ${SLEEP});"`;
var ret = execSync(cmd, {timeout: TIMER});
} catch (e) {

View File

@ -34,8 +34,8 @@ function pingPongTest(port, host) {
server.on('listening', function() {
console.log('server listening on ' + port + ' ' + host);
var buf = new Buffer('PING'),
client = dgram.createSocket('udp4');
const buf = new Buffer('PING');
const client = dgram.createSocket('udp4');
client.on('message', function(msg, rinfo) {
if (debug) console.log('client got: ' + msg +

View File

@ -1,9 +1,9 @@
'use strict';
(function() {
var assert = require('assert'),
child = require('child_process'),
util = require('util'),
common = require('../common');
const assert = require('assert');
const child = require('child_process');
const util = require('util');
const common = require('../common');
if (process.env['TEST_INIT']) {
util.print('Loaded successfully!');
} else {

Some files were not shown because too many files have changed in this diff Show More