Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use ES6 in test-debugger-client.js #10183

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions test/debugger/test-debugger-client.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict';
const common = require('../common');
var assert = require('assert');
var debug = require('_debugger');
const assert = require('assert');
const debug = require('_debugger');

process.env.NODE_DEBUGGER_TIMEOUT = 2000;
var debugPort = common.PORT;
const debugPort = common.PORT;
debug.port = debugPort;
var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;

setTimeout(function() {
if (nodeProcess) nodeProcess.kill('SIGTERM');
throw new Error('timeout');
}, 10000).unref();


var resCount = 0;
var p = new debug.Protocol();
let resCount = 0;
const p = new debug.Protocol();
p.onResponse = function(res) {
resCount++;
};
Expand All @@ -29,12 +29,12 @@ assert.strictEqual(resCount, 1);

// Make sure split messages go in.

var parts = [];
const parts = [];
parts.push('Content-Length: 336\r\n');
assert.strictEqual(parts[0].length, 21);
parts.push('\r\n');
assert.strictEqual(parts[1].length, 2);
var bodyLength = 0;
let bodyLength = 0;

parts.push('{"seq":12,"type":"event","event":"break","body":' +
'{"invocationText":"#<a Server>');
Expand All @@ -55,32 +55,32 @@ bodyLength += parts[4].length;

assert.strictEqual(bodyLength, 336);

for (var i = 0; i < parts.length; i++) {
for (let i = 0; i < parts.length; i++) {
p.execute(parts[i]);
}
assert.strictEqual(resCount, 2);


// Make sure that if we get backed up, we still manage to get all the
// messages
var d = 'Content-Length: 466\r\n\r\n' +
'{"seq":10,"type":"event","event":"afterCompile","success":true,' +
'"body":{"script":{"handle":1,"type":"script","name":"dns.js",' +
'"id":34,"lineOffset":0,"columnOffset":0,"lineCount":241,' +
'"sourceStart":"(function(module, exports, require) {' +
'var dns = process.binding(\'cares\')' +
';\\nvar ne","sourceLength":6137,"scriptType":2,"compilationType":0,' +
'"context":{"ref":0},"text":"dns.js (lines: 241)"}},"refs":' +
'[{"handle":0' +
',"type":"context","text":"#<a ContextMirror>"}],"running":true}' +
'\r\n\r\nContent-Length: 119\r\n\r\n' +
'{"seq":11,"type":"event","event":"scriptCollected","success":true,' +
'"body":{"script":{"id":26}},"refs":[],"running":true}';
const d = 'Content-Length: 466\r\n\r\n' +
'{"seq":10,"type":"event","event":"afterCompile","success":true,' +
'"body":{"script":{"handle":1,"type":"script","name":"dns.js",' +
'"id":34,"lineOffset":0,"columnOffset":0,"lineCount":241,' +
'"sourceStart":"(function(module, exports, require) {' +
'var dns = process.binding(\'cares\')' +
';\\nvar ne","sourceLength":6137,"scriptType":2,"compilationType"' +
':0,"context":{"ref":0},"text":"dns.js (lines: 241)"}},"refs":' +
'[{"handle":0' +
',"type":"context","text":"#<a ContextMirror>"}],"running":true}' +
'\r\n\r\nContent-Length: 119\r\n\r\n' +
'{"seq":11,"type":"event","event":"scriptCollected","success":true' +
',"body":{"script":{"id":26}},"refs":[],"running":true}';
p.execute(d);
assert.strictEqual(resCount, 4);

var expectedConnections = 0;
var tests = [];
let expectedConnections = 0;
const tests = [];
function addTest(cb) {
expectedConnections++;
tests.push(cb);
Expand All @@ -102,9 +102,9 @@ addTest(function(client, done) {
assert.ok(!err);
console.error('got %d scripts', Object.keys(client.scripts).length);

var foundMainScript = false;
for (var k in client.scripts) {
var script = client.scripts[k];
let foundMainScript = false;
for (const k in client.scripts) {
const script = client.scripts[k];
if (script && script.name === 'node.js') {
foundMainScript = true;
break;
Expand All @@ -127,19 +127,19 @@ addTest(function(client, done) {
});


var connectCount = 0;
var script = 'setTimeout(function() { console.log("blah"); });' +
'setInterval(function() {}, 1000000);';
let connectCount = 0;
const script = 'setTimeout(function() { console.log("blah"); });' +
'setInterval(function() {}, 1000000);';

var nodeProcess;
let nodeProcess;

function doTest(cb, done) {
var args = ['--debug=' + debugPort, '-e', script];
const args = ['--debug=' + debugPort, '-e', script];
nodeProcess = spawn(process.execPath, args);

nodeProcess.stdout.once('data', function(c) {
console.log('>>> new node process: %d', nodeProcess.pid);
var failed = true;
let failed = true;
try {
process._debugProcess(nodeProcess.pid);
failed = false;
Expand All @@ -151,9 +151,9 @@ function doTest(cb, done) {
console.log('>>> starting debugger session');
});

var didTryConnect = false;
let didTryConnect = false;
nodeProcess.stderr.setEncoding('utf8');
var b = '';
let b = '';
nodeProcess.stderr.on('data', function(data) {
console.error('got stderr data %j', data);
nodeProcess.stderr.resume();
Expand Down