|
2 | 2 | const common = require('../common'); |
3 | 3 | const assert = require('assert'); |
4 | 4 |
|
5 | | -const spawn = require('child_process').spawn; |
6 | | -const child = spawn(process.execPath, [], { |
7 | | - env: Object.assign(process.env, { |
8 | | - NODE_DEBUG: process.argv[2] |
9 | | - }) |
10 | | -}); |
11 | | -const wanted = `${child.pid}\n`; |
12 | | -let found = ''; |
| 5 | +const { spawn } = require('child_process'); |
| 6 | +for (const args of [[], ['-']]) { |
| 7 | + const child = spawn(process.execPath, args, { |
| 8 | + env: Object.assign(process.env, { |
| 9 | + NODE_DEBUG: process.argv[2] |
| 10 | + }) |
| 11 | + }); |
| 12 | + const wanted = `${child.pid}\n`; |
| 13 | + let found = ''; |
13 | 14 |
|
14 | | -child.stdout.setEncoding('utf8'); |
15 | | -child.stdout.on('data', function(c) { |
16 | | - found += c; |
17 | | -}); |
| 15 | + child.stdout.setEncoding('utf8'); |
| 16 | + child.stdout.on('data', function(c) { |
| 17 | + found += c; |
| 18 | + }); |
18 | 19 |
|
19 | | -child.stderr.setEncoding('utf8'); |
20 | | -child.stderr.on('data', function(c) { |
21 | | - console.error(`> ${c.trim().split(/\n/).join('\n> ')}`); |
22 | | -}); |
| 20 | + child.stderr.setEncoding('utf8'); |
| 21 | + child.stderr.on('data', function(c) { |
| 22 | + console.error(`> ${c.trim().split(/\n/).join('\n> ')}`); |
| 23 | + }); |
23 | 24 |
|
24 | | -child.on('close', common.mustCall(function(c) { |
25 | | - assert.strictEqual(c, 0); |
26 | | - assert.strictEqual(found, wanted); |
27 | | - console.log('ok'); |
28 | | -})); |
| 25 | + child.on('close', common.mustCall(function(c) { |
| 26 | + assert.strictEqual(c, 0); |
| 27 | + assert.strictEqual(found, wanted); |
| 28 | + })); |
29 | 29 |
|
30 | | -setTimeout(function() { |
31 | | - child.stdin.end('console.log(process.pid)'); |
32 | | -}, 1); |
| 30 | + setTimeout(function() { |
| 31 | + child.stdin.end('console.log(process.pid)'); |
| 32 | + }, 1); |
| 33 | +} |
0 commit comments