Browse Source

test: fix and improve debug-break-on-uncaught

This test runs based on a expectation that the stderr will get the
string 'Debugger listening on port'. But the actual message printed
to stderr has changed to 'Debugger listening on host:port'. So the
the actuals tests did not even start and eventually timeout.

Apart from that, changed `var`s to `let`s or `const`s.

Refs: https://github.com/nodejs/node/issues/10361
PR-URL: https://github.com/nodejs/node/pull/10370
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com
v7.x
Sakthipriyan Vairamani (thefourtheye) 8 years ago
committed by Evan Lucas
parent
commit
d33e560929
  1. 25
      test/debugger/test-debug-break-on-uncaught.js

25
test/debugger/test-debug-break-on-uncaught.js

@ -5,7 +5,7 @@ const assert = require('assert');
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
const debug = require('_debugger'); const debug = require('_debugger');
var scenarios = []; const scenarios = [];
addScenario('global.js', 2); addScenario('global.js', 2);
addScenario('timeout.js', 2); addScenario('timeout.js', 2);
@ -21,34 +21,33 @@ function addScenario(scriptName, throwsOnLine) {
} }
function run() { function run() {
var next = scenarios.shift(); const next = scenarios.shift();
if (next) next(); if (next) next();
} }
function runScenario(scriptName, throwsOnLine, next) { function runScenario(scriptName, throwsOnLine, next) {
console.log('**[ %s ]**', scriptName); let asserted = false;
var asserted = false; const port = common.PORT;
var port = common.PORT;
var testScript = path.join( const testScript = path.join(
common.fixturesDir, common.fixturesDir,
'uncaught-exceptions', 'uncaught-exceptions',
scriptName scriptName
); );
var child = spawn(process.execPath, [ '--debug-brk=' + port, testScript ]); const child = spawn(process.execPath, [ '--debug-brk=' + port, testScript ]);
child.on('close', function() { child.on('close', function() {
assert(asserted, 'debugger did not pause on exception'); assert(asserted, 'debugger did not pause on exception');
if (next) next(); if (next) next();
}); });
var exceptions = []; const exceptions = [];
var stderr = ''; let stderr = '';
function stderrListener(data) { function stderrListener(data) {
stderr += data; stderr += data;
if (stderr.includes('Debugger listening on port')) { if (stderr.includes('Debugger listening on ')) {
setTimeout(setupClient.bind(null, runTest), 200); setTimeout(setupClient.bind(null, runTest), 200);
child.stderr.removeListener('data', stderrListener); child.stderr.removeListener('data', stderrListener);
} }
@ -58,7 +57,7 @@ function runScenario(scriptName, throwsOnLine, next) {
child.stderr.on('data', stderrListener); child.stderr.on('data', stderrListener);
function setupClient(callback) { function setupClient(callback) {
var client = new debug.Client(); const client = new debug.Client();
client.once('ready', callback.bind(null, client)); client.once('ready', callback.bind(null, client));
@ -83,14 +82,14 @@ function runScenario(scriptName, throwsOnLine, next) {
enabled: true enabled: true
} }
}, },
function(error, result) { function(error) {
assert.ifError(error); assert.ifError(error);
client.on('exception', function(event) { client.on('exception', function(event) {
exceptions.push(event.body); exceptions.push(event.body);
}); });
client.reqContinue(function(error, result) { client.reqContinue(function(error) {
assert.ifError(error); assert.ifError(error);
setTimeout(assertHasPaused.bind(null, client), 100); setTimeout(assertHasPaused.bind(null, client), 100);
}); });

Loading…
Cancel
Save