src: don't error at startup when cwd doesn't exist
[platform/upstream/nodejs.git] / test / parallel / test-debug-port-from-cmdline.js
1 var common = require('../common');
2 var assert = require('assert');
3 var spawn = require('child_process').spawn;
4
5 var debugPort = common.PORT;
6 var args = ['--debug-port=' + debugPort];
7 var childOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] };
8 var child = spawn(process.execPath, args, childOptions);
9
10 child.stdin.end("process.send({ msg: 'childready' });");
11
12 child.stderr.on('data', function(data) {
13   var lines = data.toString().replace(/\r/g, '').trim().split('\n');
14   lines.forEach(processStderrLine);
15 });
16
17 child.on('message', function onChildMsg(message) {
18   if (message.msg === 'childready') {
19     process._debugProcess(child.pid);
20   }
21 });
22
23 process.on('exit', function() {
24   child.kill();
25 });
26
27 var outputLines = [];
28 function processStderrLine(line) {
29   console.log('> ' + line);
30   outputLines.push(line);
31
32   if (/Debugger listening/.test(line)) {
33     assertOutputLines();
34     process.exit();
35   }
36 }
37
38 function assertOutputLines() {
39   var expectedLines = [
40     'Starting debugger agent.',
41     'Debugger listening on port ' + debugPort
42   ];
43
44   assert.equal(outputLines.length, expectedLines.length);
45   for (var i = 0; i < expectedLines.length; i++)
46     assert.equal(outputLines[i], expectedLines[i]);
47
48 }