| 1 | 'use strict' |
| 2 | |
| 3 | const main = () => { |
| 4 | const t = require('tap') |
| 5 | const { spawn } = require('child_process') |
| 6 | t.plan(2) |
| 7 | t.test('without env set', t => { |
| 8 | const c = spawn(process.execPath, [__filename, 'child'], { env: { |
| 9 | ...process.env, |
| 10 | NODE_DEBUG: '', |
| 11 | } }) |
| 12 | const err = [] |
| 13 | c.stderr.on('data', chunk => err.push(chunk)) |
| 14 | c.on('close', (code, signal) => { |
| 15 | t.equal(code, 0, 'success exit status') |
| 16 | t.equal(signal, null, 'no signal') |
| 17 | t.equal(Buffer.concat(err).toString('utf8'), '', 'got no output') |
| 18 | t.end() |
| 19 | }) |
| 20 | }) |
| 21 | t.test('with env set', t => { |
| 22 | const c = spawn(process.execPath, [__filename, 'child'], { env: { |
| 23 | ...process.env, |
| 24 | NODE_DEBUG: 'semver', |
| 25 | } }) |
| 26 | const err = [] |
| 27 | c.stderr.on('data', chunk => err.push(chunk)) |
| 28 | c.on('close', (code, signal) => { |
| 29 | t.equal(code, 0, 'success exit status') |
| 30 | t.equal(signal, null, 'no signal') |
| 31 | t.equal(Buffer.concat(err).toString('utf8'), 'SEMVER hello, world\n', 'got expected output') |
| 32 | t.end() |
| 33 | }) |
| 34 | }) |
| 35 | t.end() |
| 36 | } |
| 37 | |
| 38 | if (process.argv[2] === 'child') { |
| 39 | require('../../internal/debug')('hello, world') |