forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process: support promisified
exec(File)
Author: Benjamin Gruenbaum <[email protected]> Author: Anna Henningsen <[email protected]> PR-URL: nodejs#12442 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: William Kapke <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Teddy Katz <[email protected]>
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const child_process = require('child_process'); | ||
const { promisify } = require('util'); | ||
|
||
common.crashOnUnhandledRejection(); | ||
|
||
const exec = promisify(child_process.exec); | ||
const execFile = promisify(child_process.execFile); | ||
|
||
{ | ||
exec(`${process.execPath} -p 42`).then(common.mustCall((obj) => { | ||
assert.deepStrictEqual(obj, { stdout: '42\n', stderr: '' }); | ||
})); | ||
} | ||
|
||
{ | ||
execFile(process.execPath, ['-p', '42']).then(common.mustCall((obj) => { | ||
assert.deepStrictEqual(obj, { stdout: '42\n', stderr: '' }); | ||
})); | ||
} | ||
|
||
{ | ||
exec('doesntexist').catch(common.mustCall((err) => { | ||
assert(err.message.includes('doesntexist')); | ||
})); | ||
} | ||
|
||
{ | ||
execFile('doesntexist', ['-p', '42']).catch(common.mustCall((err) => { | ||
assert(err.message.includes('doesntexist')); | ||
})); | ||
} |