|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const spawn = require('child_process').spawn; |
| 5 | + |
| 6 | +var buffer = ''; |
| 7 | + |
| 8 | +// connect to debug agent |
| 9 | +var interfacer = spawn(process.execPath, ['debug', '-p', '655555']); |
| 10 | + |
| 11 | +console.error(process.execPath, 'debug', '-p', '655555'); |
| 12 | +interfacer.stdout.setEncoding('utf-8'); |
| 13 | +interfacer.stderr.setEncoding('utf-8'); |
| 14 | +var onData = function(data) { |
| 15 | + data = (buffer + data).split('\n'); |
| 16 | + buffer = data.pop(); |
| 17 | + data.forEach(function(line) { |
| 18 | + interfacer.emit('line', line); |
| 19 | + }); |
| 20 | +}; |
| 21 | +interfacer.stdout.on('data', onData); |
| 22 | +interfacer.stderr.on('data', onData); |
| 23 | + |
| 24 | +var lineCount = 0; |
| 25 | +interfacer.on('line', function(line) { |
| 26 | + var expected; |
| 27 | + const pid = interfacer.pid; |
| 28 | + if (common.isWindows) { |
| 29 | + switch (++lineCount) { |
| 30 | + case 1: |
| 31 | + line = line.replace(/^(debug> *)+/, ''); |
| 32 | + var msg = 'There was an internal error in Node\'s debugger. ' + |
| 33 | + 'Please report this bug.'; |
| 34 | + expected = `(node:${pid}) ${msg}`; |
| 35 | + break; |
| 36 | + |
| 37 | + case 2: |
| 38 | + expected = 'The parameter is incorrect.'; |
| 39 | + break; |
| 40 | + |
| 41 | + default: |
| 42 | + return; |
| 43 | + } |
| 44 | + } else { |
| 45 | + line = line.replace(/^(debug> *)+/, ''); |
| 46 | + expected = `(node:${pid}) Target process: 655555 doesn\'t exist.`; |
| 47 | + } |
| 48 | + |
| 49 | + assert.strictEqual(expected, line); |
| 50 | +}); |
| 51 | + |
| 52 | +interfacer.on('exit', function(code, signal) { |
| 53 | + assert.ok(code == 1, 'Got unexpected code: ' + code); |
| 54 | +}); |
0 commit comments