Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[fixup] lib/net: update tests
- refactor the portTypeError and portRangeError assertions,
  by passing the expected call count to common.expectsError in
  test-net-connect-options-port.js
  (Each syncFailToConnect() call will call 4 or 2 times the
  doConnect() method, wich returns an array of size 6,
  so the call counts are 96 and 168 for portTypeError and
  portRangeError respectively)
- refactor the connect() method in test-net-localerror.js,
  by removing the reduntant assert
  and use the common.expectsError() assertion
- move require('../common') to the top in test-net-server-options.js
  • Loading branch information
matzavinos authored and jasnell committed Sep 25, 2017
commit 00b8f490457a165db4fd2de85c4d8afcf64f19c1
28 changes: 12 additions & 16 deletions test/parallel/test-net-connect-options-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ const net = require('net');

// Test wrong type of ports
{
function portTypeError() {
return common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});
}
const portTypeError = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
}, 96);

syncFailToConnect(true, portTypeError);
syncFailToConnect(false, portTypeError);
Expand All @@ -43,12 +41,10 @@ const net = require('net');

// Test out of range ports
{
function portRangeError() {
return common.expectsError({
code: 'ERR_SOCKET_BAD_PORT',
type: RangeError
});
}
const portRangeError = common.expectsError({
code: 'ERR_SOCKET_BAD_PORT',
type: RangeError
}, 168);

syncFailToConnect('', portRangeError);
syncFailToConnect(' ', portRangeError);
Expand Down Expand Up @@ -137,7 +133,7 @@ function syncFailToConnect(port, assertErr, optOnly) {
const portArgBlocks = doConnect([port], () => common.mustNotCall());
for (const block of portArgBlocks) {
assert.throws(block,
assertErr(),
assertErr,
`${block.name}(${port})`);
}

Expand All @@ -146,7 +142,7 @@ function syncFailToConnect(port, assertErr, optOnly) {
() => common.mustNotCall());
for (const block of portHostArgBlocks) {
assert.throws(block,
assertErr(),
assertErr,
`${block.name}(${port}, 'localhost')`);
}
}
Expand All @@ -155,7 +151,7 @@ function syncFailToConnect(port, assertErr, optOnly) {
() => common.mustNotCall());
for (const block of portOptBlocks) {
assert.throws(block,
assertErr(),
assertErr,
`${block.name}({port: ${port}})`);
}

Expand All @@ -164,7 +160,7 @@ function syncFailToConnect(port, assertErr, optOnly) {
() => common.mustNotCall());
for (const block of portHostOptBlocks) {
assert.throws(block,
assertErr(),
assertErr,
`${block.name}({port: ${port}, host: 'localhost'})`);
}
}
Expand Down
11 changes: 5 additions & 6 deletions test/parallel/test-net-localerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');

const connect = (opts, code, type) => common.expectsError(
() => net.connect(opts),
{ code, type }
);

connect({
host: 'localhost',
port: 0,
Expand All @@ -35,8 +39,3 @@ connect({
port: 0,
localPort: 'foobar',
}, 'ERR_INVALID_ARG_TYPE', TypeError);

function connect(opts, code, type) {
assert.throws(() => net.connect(opts),
common.expectsError({ code: code, type: type }));
}
2 changes: 1 addition & 1 deletion test/parallel/test-net-server-options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const assert = require('assert');
const common = require('../common');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually require('../common'); should be first. It does some wiring, and maybe we'll want it to monkeypatch assert in the future.

const assert = require('assert');
const net = require('net');

assert.throws(function() { net.createServer('path'); },
Expand Down