Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1a39bfb

Browse filesBrowse files
cjihrigItalo A. Casas
authored andcommitted
test: increase coverage for exec() functions
This commit increases code coverage related to the stdout and stderr outputs of the child_process exec() functions. Previously, stdout was completely covered, but stderr was not. PR-URL: #10919 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 4b38744 commit 1a39bfb
Copy full SHA for 1a39bfb

File tree

Expand file treeCollapse file tree

2 files changed

+49
-24
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+49
-24
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-child-process-exec-buffer.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-child-process-exec-buffer.js
-24Lines changed: 0 additions & 24 deletions
This file was deleted.
Collapse file
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cp = require('child_process');
5+
const stdoutData = 'foo';
6+
const stderrData = 'bar';
7+
const expectedStdout = `${stdoutData}\n`;
8+
const expectedStderr = `${stderrData}\n`;
9+
10+
if (process.argv[2] === 'child') {
11+
// The following console calls are part of the test.
12+
console.log(stdoutData);
13+
console.error(stderrData);
14+
} else {
15+
function run(options, callback) {
16+
const cmd = `${process.execPath} ${__filename} child`;
17+
18+
cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
19+
assert.ifError(err);
20+
callback(stdout, stderr);
21+
}));
22+
}
23+
24+
// Test default encoding, which should be utf8.
25+
run({}, (stdout, stderr) => {
26+
assert.strictEqual(typeof stdout, 'string');
27+
assert.strictEqual(typeof stderr, 'string');
28+
assert.strictEqual(stdout, expectedStdout);
29+
assert.strictEqual(stderr, expectedStderr);
30+
});
31+
32+
// Test explicit utf8 encoding.
33+
run({ encoding: 'utf8' }, (stdout, stderr) => {
34+
assert.strictEqual(typeof stdout, 'string');
35+
assert.strictEqual(typeof stderr, 'string');
36+
assert.strictEqual(stdout, expectedStdout);
37+
assert.strictEqual(stderr, expectedStderr);
38+
});
39+
40+
// Test cases that result in buffer encodings.
41+
[undefined, null, 'buffer', 'invalid'].forEach((encoding) => {
42+
run({ encoding }, (stdout, stderr) => {
43+
assert(stdout instanceof Buffer);
44+
assert(stdout instanceof Buffer);
45+
assert.strictEqual(stdout.toString(), expectedStdout);
46+
assert.strictEqual(stderr.toString(), expectedStderr);
47+
});
48+
});
49+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.