Skip to content

Commit 54be1e4

Browse files
committed
test checks output
1 parent 9f22b8c commit 54be1e4

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

test/parallel/test-debug-brk.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,23 @@ const common = require('../common');
44
const spawn = require('child_process').spawn;
55

66
let run = () => {};
7-
function test(extraArgs) {
7+
function test(extraArgs, stdoutPattern) {
88
const next = run;
99
run = () => {
10+
var procStdout = '';
1011
var procStderr = '';
1112
var agentStdout = '';
13+
var debuggerListening = false;
14+
var outputMatched = false;
1215
var needToSpawnAgent = true;
1316
var needToExit = true;
1417

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

19-
const exitAll = common.mustCall((processes) => {
20-
processes.forEach((myProcess) => { myProcess.kill(); });
21-
});
22-
23-
proc.stderr.on('data', (chunk) => {
24-
procStderr += chunk;
25-
if (/Debugger listening on/.test(procStderr) && needToSpawnAgent) {
22+
const tryStartAgent = () => {
23+
if (debuggerListening && outputMatched && needToSpawnAgent) {
2624
needToSpawnAgent = false;
2725
const agentArgs = ['debug', `localhost:${common.PORT}`];
2826
const agent = spawn(process.execPath, agentArgs);
@@ -36,6 +34,27 @@ function test(extraArgs) {
3634
}
3735
});
3836
}
37+
};
38+
39+
const exitAll = common.mustCall((processes) => {
40+
processes.forEach((myProcess) => { myProcess.kill(); });
41+
});
42+
43+
if (stdoutPattern != null) {
44+
proc.stdout.on('data', (chunk) => {
45+
procStdout += chunk;
46+
outputMatched = outputMatched || stdoutPattern.test(procStdout);
47+
tryStartAgent();
48+
});
49+
} else {
50+
outputMatched = true;
51+
}
52+
53+
proc.stderr.on('data', (chunk) => {
54+
procStderr += chunk;
55+
debuggerListening = debuggerListening ||
56+
/Debugger listening on/.test(procStderr);
57+
tryStartAgent();
3958
});
4059

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

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

5070
run();

0 commit comments

Comments
 (0)