Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
test checks output
  • Loading branch information
kjin committed Oct 3, 2016
commit 54be1e4c47c48c4b7361dbc4e46ed634e4c7b2f5
36 changes: 28 additions & 8 deletions test/parallel/test-debug-brk.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@ const common = require('../common');
const spawn = require('child_process').spawn;

let run = () => {};
function test(extraArgs) {
function test(extraArgs, stdoutPattern) {
const next = run;
run = () => {
var procStdout = '';
var procStderr = '';
var agentStdout = '';
var debuggerListening = false;
var outputMatched = false;
var needToSpawnAgent = true;
var needToExit = true;

const procArgs = [`--debug-brk=${common.PORT}`].concat(extraArgs);
const proc = spawn(process.execPath, procArgs);
proc.stderr.setEncoding('utf8');

const exitAll = common.mustCall((processes) => {
processes.forEach((myProcess) => { myProcess.kill(); });
});

proc.stderr.on('data', (chunk) => {
procStderr += chunk;
if (/Debugger listening on/.test(procStderr) && needToSpawnAgent) {
const tryStartAgent = () => {
if (debuggerListening && outputMatched && needToSpawnAgent) {
needToSpawnAgent = false;
const agentArgs = ['debug', `localhost:${common.PORT}`];
const agent = spawn(process.execPath, agentArgs);
Expand All @@ -36,6 +34,27 @@ function test(extraArgs) {
}
});
}
};

const exitAll = common.mustCall((processes) => {
processes.forEach((myProcess) => { myProcess.kill(); });
});

if (stdoutPattern != null) {
proc.stdout.on('data', (chunk) => {
procStdout += chunk;
outputMatched = outputMatched || stdoutPattern.test(procStdout);
tryStartAgent();
});
} else {
outputMatched = true;
}

proc.stderr.on('data', (chunk) => {
procStderr += chunk;
debuggerListening = debuggerListening ||
/Debugger listening on/.test(procStderr);
tryStartAgent();
});

proc.on('exit', () => {
Expand All @@ -46,5 +65,6 @@ function test(extraArgs) {

test(['-e', '0']);
test(['-e', '0', 'foo']);
test(['-p', 'process.argv[1]', 'foo'], /^\s*foo\s*$/);

run();