Skip to content

Commit

Permalink
test: complete coverage of lib/child_process.js
Browse files Browse the repository at this point in the history
This commit adds a test which brings coverage of
lib/child_process.js to 100%. It adds coverage for the call to
uv.errname() in execFile()'s exithandler() function.

PR-URL: #12367
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
cjihrig committed Apr 18, 2017
1 parent b4f59a7 commit d2a3651
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion test/parallel/test-child-process-execfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const execFile = require('child_process').execFile;
const path = require('path');
const uv = process.binding('uv');

const fixture = path.join(common.fixturesDir, 'exit.js');

Expand All @@ -19,3 +19,22 @@ const fixture = path.join(common.fixturesDir, 'exit.js');
})
);
}

{
// Verify that negative exit codes can be translated to UV error names.
const errorString = `Error: Command failed: ${process.execPath}`;
const code = -1;
const callback = common.mustCall((err, stdout, stderr) => {
assert.strictEqual(err.toString().trim(), errorString);
assert.strictEqual(err.code, uv.errname(code));
assert.strictEqual(err.killed, true);
assert.strictEqual(err.signal, null);
assert.strictEqual(err.cmd, process.execPath);
assert.strictEqual(stdout.trim(), '');
assert.strictEqual(stderr.trim(), '');
});
const child = execFile(process.execPath, callback);

child.kill();
child.emit('close', code, null);
}

0 comments on commit d2a3651

Please sign in to comment.