| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7347860 commit 41284fb
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + // Flags: --expose_internals | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const cp = require('child_process'); | ||
| 6 | + const internalCp = require('internal/child_process'); | ||
| 7 | + | ||
| 8 | + if (process.argv[2] === 'child') { | ||
| 9 | + // Keep the process alive and printing to stdout. | ||
| 10 | + setInterval(() => { console.log('foo'); }, 1); | ||
| 11 | + } else { | ||
| 12 | + // Monkey patch ChildProcess#kill() to kill the process and then throw. | ||
| 13 | + const kill = internalCp.ChildProcess.prototype.kill; | ||
| 14 | + | ||
| 15 | + internalCp.ChildProcess.prototype.kill = function() { | ||
| 16 | + kill.apply(this, arguments); | ||
| 17 | + throw new Error('mock error'); | ||
| 18 | + }; | ||
| 19 | + | ||
| 20 | + const cmd = `${process.execPath} ${__filename} child`; | ||
| 21 | + const options = { maxBuffer: 0 }; | ||
| 22 | + const child = cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => { | ||
| 23 | + // Verify that if ChildProcess#kill() throws, the error is reported. | ||
| 24 | + assert(/^Error: mock error$/.test(err)); | ||
| 25 | + assert.strictEqual(stdout, ''); | ||
| 26 | + assert.strictEqual(stderr, ''); | ||
| 27 | + assert.strictEqual(child.killed, true); | ||
| 28 | + })); | ||
| 29 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments