|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const path = require('path'); |
| 6 | +const spawn = require('child_process').spawn; |
| 7 | + |
| 8 | +const children = []; |
| 9 | +for (let i = 0; i < 4; i += 1) { |
| 10 | + const port = common.PORT + i; |
| 11 | + const args = [`--debug-port=${port}`, '--interactive', 'debug', __filename]; |
| 12 | + const child = spawn(process.execPath, args, { stdio: 'pipe' }); |
| 13 | + child.test = { port: port, stdout: '' }; |
| 14 | + child.stdout.setEncoding('utf8'); |
| 15 | + child.stdout.on('data', function(s) { child.test.stdout += s; update(); }); |
| 16 | + child.stdout.pipe(process.stdout); |
| 17 | + child.stderr.pipe(process.stderr); |
| 18 | + children.push(child); |
| 19 | +} |
| 20 | + |
| 21 | +function update() { |
| 22 | + // Debugger prints relative paths except on Windows. |
| 23 | + const filename = path.basename(__filename); |
| 24 | + |
| 25 | + let ready = 0; |
| 26 | + for (const child of children) |
| 27 | + ready += RegExp(`break in .*?${filename}:1`).test(child.test.stdout); |
| 28 | + |
| 29 | + if (ready === children.length) |
| 30 | + for (const child of children) |
| 31 | + child.kill(); |
| 32 | +} |
| 33 | + |
| 34 | +process.on('exit', function() { |
| 35 | + for (const child of children) { |
| 36 | + const one = RegExp(`Debugger listening on port ${child.test.port}`); |
| 37 | + const two = RegExp(`connecting to 127.0.0.1:${child.test.port}`); |
| 38 | + assert(one.test(child.test.stdout)); |
| 39 | + assert(two.test(child.test.stdout)); |
| 40 | + } |
| 41 | +}); |
0 commit comments