Skip to content

Commit

Permalink
test: refactor test-child-process-send-type-error
Browse files Browse the repository at this point in the history
* Add exit listener to child process to check return code. Previously,
  child process faiilure would not cause the test to fail.
* Use common.mustNotCall() to guarantee callback is not invoked.
* Insert blank line per test writing guide.

PR-URL: #13904
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
  • Loading branch information
Trott authored and MylesBorins committed Aug 16, 2017
1 parent 35f9111 commit bd8574c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/parallel/test-child-process-send-type-error.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
require('../common');
const common = require('../common');

const assert = require('assert');
const cp = require('child_process');

function noop() {}

function fail(proc, args) {
assert.throws(() => {
proc.send.apply(proc, args);
Expand All @@ -13,13 +12,18 @@ function fail(proc, args) {

let target = process;

if (process.argv[2] !== 'child')
if (process.argv[2] !== 'child') {
target = cp.fork(__filename, ['child']);
target.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
}));
}

fail(target, ['msg', null, null]);
fail(target, ['msg', null, '']);
fail(target, ['msg', null, 'foo']);
fail(target, ['msg', null, 0]);
fail(target, ['msg', null, NaN]);
fail(target, ['msg', null, 1]);
fail(target, ['msg', null, null, noop]);
fail(target, ['msg', null, null, common.mustNotCall()]);

0 comments on commit bd8574c

Please sign in to comment.