| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent af8e27d commit c2ff36e
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,13 +23,13 @@ const errMessage = /^Bad socket type specified\. Valid types are: udp4, udp6$/; | |||
| 23 | 23 | ||
| 24 | 24 | // Error must be thrown with invalid types | |
| 25 | 25 | invalidTypes.forEach((invalidType) => { | |
| 26 | - assert.throws(() => { | ||
| 26 | + common.expectsError(() => { | ||
| 27 | 27 | dgram.createSocket(invalidType); | |
| 28 | - }, common.expectsError({ | ||
| 28 | + }, { | ||
| 29 | 29 | code: 'ERR_SOCKET_BAD_TYPE', | |
| 30 | 30 | type: TypeError, | |
| 31 | 31 | message: errMessage | |
| 32 | - })); | ||
| 32 | + }); | ||
| 33 | 33 | }); | |
| 34 | 34 | ||
| 35 | 35 | // Error must not be thrown with valid types | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | - const assert = require('assert'); | ||
| 4 | 3 | const dgram = require('dgram'); | |
| 5 | 4 | const dns = require('dns'); | |
| 6 | 5 | ||
@@ -36,12 +35,12 @@ const dns = require('dns'); | |||
| 36 | 35 | { | |
| 37 | 36 | // Verify that non-functions throw. | |
| 38 | 37 | [null, true, false, 0, 1, NaN, '', 'foo', {}, Symbol()].forEach((value) => { | |
| 39 | - assert.throws(() => { | ||
| 38 | + common.expectsError(() => { | ||
| 40 | 39 | dgram.createSocket({ type: 'udp4', lookup: value }); | |
| 41 | - }, common.expectsError({ | ||
| 40 | + }, { | ||
| 42 | 41 | code: 'ERR_INVALID_ARG_TYPE', | |
| 43 | 42 | type: TypeError, | |
| 44 | 43 | message: 'The "lookup" argument must be of type Function' | |
| 45 | - })); | ||
| 44 | + }); | ||
| 46 | 45 | }); | |
| 47 | 46 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,53 +11,53 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true }); | |||
| 11 | 11 | { | |
| 12 | 12 | const socket = setup(); | |
| 13 | 13 | socket.close(common.mustCall(() => { | |
| 14 | - assert.throws(() => { | ||
| 14 | + common.expectsError(() => { | ||
| 15 | 15 | socket.addMembership(multicastAddress); | |
| 16 | - }, common.expectsError({ | ||
| 16 | + }, { | ||
| 17 | 17 | code: 'ERR_SOCKET_DGRAM_NOT_RUNNING', | |
| 18 | 18 | type: Error, | |
| 19 | 19 | message: /^Not running$/ | |
| 20 | - })); | ||
| 20 | + }); | ||
| 21 | 21 | })); | |
| 22 | 22 | } | |
| 23 | 23 | ||
| 24 | 24 | // dropMembership() on closed socket should throw | |
| 25 | 25 | { | |
| 26 | 26 | const socket = setup(); | |
| 27 | 27 | socket.close(common.mustCall(() => { | |
| 28 | - assert.throws(() => { | ||
| 28 | + common.expectsError(() => { | ||
| 29 | 29 | socket.dropMembership(multicastAddress); | |
| 30 | - }, common.expectsError({ | ||
| 30 | + }, { | ||
| 31 | 31 | code: 'ERR_SOCKET_DGRAM_NOT_RUNNING', | |
| 32 | 32 | type: Error, | |
| 33 | 33 | message: /^Not running$/ | |
| 34 | - })); | ||
| 34 | + }); | ||
| 35 | 35 | })); | |
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | // addMembership() with no argument should throw | |
| 39 | 39 | { | |
| 40 | 40 | const socket = setup(); | |
| 41 | - assert.throws(() => { | ||
| 41 | + common.expectsError(() => { | ||
| 42 | 42 | socket.addMembership(); | |
| 43 | - }, common.expectsError({ | ||
| 43 | + }, { | ||
| 44 | 44 | code: 'ERR_MISSING_ARGS', | |
| 45 | 45 | type: TypeError, | |
| 46 | 46 | message: /^The "multicastAddress" argument must be specified$/ | |
| 47 | - })); | ||
| 47 | + }); | ||
| 48 | 48 | socket.close(); | |
| 49 | 49 | } | |
| 50 | 50 | ||
| 51 | 51 | // dropMembership() with no argument should throw | |
| 52 | 52 | { | |
| 53 | 53 | const socket = setup(); | |
| 54 | - assert.throws(() => { | ||
| 54 | + common.expectsError(() => { | ||
| 55 | 55 | socket.dropMembership(); | |
| 56 | - }, common.expectsError({ | ||
| 56 | + }, { | ||
| 57 | 57 | code: 'ERR_MISSING_ARGS', | |
| 58 | 58 | type: TypeError, | |
| 59 | 59 | message: /^The "multicastAddress" argument must be specified$/ | |
| 60 | - })); | ||
| 60 | + }); | ||
| 61 | 61 | socket.close(); | |
| 62 | 62 | } | |
| 63 | 63 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,13 +35,13 @@ socket.on('listening', common.mustCall(() => { | |||
| 35 | 35 | socket.setMulticastTTL(1000); | |
| 36 | 36 | }, /^Error: setMulticastTTL EINVAL$/); | |
| 37 | 37 | ||
| 38 | - assert.throws(() => { | ||
| 38 | + common.expectsError(() => { | ||
| 39 | 39 | socket.setMulticastTTL('foo'); | |
| 40 | - }, common.expectsError({ | ||
| 40 | + }, { | ||
| 41 | 41 | code: 'ERR_INVALID_ARG_TYPE', | |
| 42 | 42 | type: TypeError, | |
| 43 | 43 | message: 'The "ttl" argument must be of type number. Received type string' | |
| 44 | - })); | ||
| 44 | + }); | ||
| 45 | 45 | ||
| 46 | 46 | //close the socket | |
| 47 | 47 | socket.close(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,19 +38,19 @@ const client = dgram.createSocket('udp4').bind(0, () => { | |||
| 38 | 38 | client.send(buf, port, onMessage); | |
| 39 | 39 | ||
| 40 | 40 | // invalid address: object | |
| 41 | - assert.throws(() => { | ||
| 41 | + common.expectsError(() => { | ||
| 42 | 42 | client.send(buf, port, []); | |
| 43 | - }, common.expectsError(expectedError)); | ||
| 43 | + }, expectedError); | ||
| 44 | 44 | ||
| 45 | 45 | // invalid address: nonzero number | |
| 46 | - assert.throws(() => { | ||
| 46 | + common.expectsError(() => { | ||
| 47 | 47 | client.send(buf, port, 1); | |
| 48 | - }, common.expectsError(expectedError)); | ||
| 48 | + }, expectedError); | ||
| 49 | 49 | ||
| 50 | 50 | // invalid address: true | |
| 51 | - assert.throws(() => { | ||
| 51 | + common.expectsError(() => { | ||
| 52 | 52 | client.send(buf, port, true); | |
| 53 | - }, common.expectsError(expectedError)); | ||
| 53 | + }, expectedError); | ||
| 54 | 54 | }); | |
| 55 | 55 | ||
| 56 | 56 | client.unref(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,48 +1,47 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | - const assert = require('assert'); | ||
| 4 | 3 | const dgram = require('dgram'); | |
| 5 | 4 | const socket = dgram.createSocket('udp4'); | |
| 6 | 5 | ||
| 7 | 6 | const errorMessageOffset = | |
| 8 | 7 | /^The "offset" argument must be of type number$/; | |
| 9 | 8 | ||
| 10 | - assert.throws(() => { | ||
| 9 | + common.expectsError(() => { | ||
| 11 | 10 | socket.sendto(); | |
| 12 | - }, common.expectsError({ | ||
| 11 | + }, { | ||
| 13 | 12 | code: 'ERR_INVALID_ARG_TYPE', | |
| 14 | 13 | type: TypeError, | |
| 15 | 14 | message: errorMessageOffset | |
| 16 | - })); | ||
| 15 | + }); | ||
| 17 | 16 | ||
| 18 | - assert.throws(() => { | ||
| 17 | + common.expectsError(() => { | ||
| 19 | 18 | socket.sendto('buffer', 1, 'offset', 'port', 'address', 'cb'); | |
| 20 | - }, common.expectsError({ | ||
| 19 | + }, { | ||
| 21 | 20 | code: 'ERR_INVALID_ARG_TYPE', | |
| 22 | 21 | type: TypeError, | |
| 23 | 22 | message: /^The "length" argument must be of type number$/ | |
| 24 | - })); | ||
| 23 | + }); | ||
| 25 | 24 | ||
| 26 | - assert.throws(() => { | ||
| 25 | + common.expectsError(() => { | ||
| 27 | 26 | socket.sendto('buffer', 'offset', 1, 'port', 'address', 'cb'); | |
| 28 | - }, common.expectsError({ | ||
| 27 | + }, { | ||
| 29 | 28 | code: 'ERR_INVALID_ARG_TYPE', | |
| 30 | 29 | type: TypeError, | |
| 31 | 30 | message: errorMessageOffset | |
| 32 | - })); | ||
| 31 | + }); | ||
| 33 | 32 | ||
| 34 | - assert.throws(() => { | ||
| 33 | + common.expectsError(() => { | ||
| 35 | 34 | socket.sendto('buffer', 1, 1, 10, false, 'cb'); | |
| 36 | - }, common.expectsError({ | ||
| 35 | + }, { | ||
| 37 | 36 | code: 'ERR_INVALID_ARG_TYPE', | |
| 38 | 37 | type: TypeError, | |
| 39 | 38 | message: /^The "address" argument must be of type string$/ | |
| 40 | - })); | ||
| 39 | + }); | ||
| 41 | 40 | ||
| 42 | - assert.throws(() => { | ||
| 41 | + common.expectsError(() => { | ||
| 43 | 42 | socket.sendto('buffer', 1, 1, false, 'address', 'cb'); | |
| 44 | - }, common.expectsError({ | ||
| 43 | + }, { | ||
| 45 | 44 | code: 'ERR_INVALID_ARG_TYPE', | |
| 46 | 45 | type: TypeError, | |
| 47 | 46 | message: /^The "port" argument must be of type number$/ | |
| 48 | - })); | ||
| 47 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,13 +9,13 @@ socket.on('listening', common.mustCall(() => { | |||
| 9 | 9 | const result = socket.setTTL(16); | |
| 10 | 10 | assert.strictEqual(result, 16); | |
| 11 | 11 | ||
| 12 | - assert.throws(() => { | ||
| 12 | + common.expectsError(() => { | ||
| 13 | 13 | socket.setTTL('foo'); | |
| 14 | - }, common.expectsError({ | ||
| 14 | + }, { | ||
| 15 | 15 | code: 'ERR_INVALID_ARG_TYPE', | |
| 16 | 16 | type: TypeError, | |
| 17 | 17 | message: 'The "ttl" argument must be of type number. Received type string' | |
| 18 | - })); | ||
| 18 | + }); | ||
| 19 | 19 | ||
| 20 | 20 | // TTL must be a number from > 0 to < 256 | |
| 21 | 21 | assert.throws(() => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,21 +14,21 @@ const dgram = require('dgram'); | |||
| 14 | 14 | ||
| 15 | 15 | const socket = dgram.createSocket('udp4'); | |
| 16 | 16 | ||
| 17 | - assert.throws(() => { | ||
| 17 | + common.expectsError(() => { | ||
| 18 | 18 | socket.setRecvBufferSize(8192); | |
| 19 | - }, common.expectsError(errorObj)); | ||
| 19 | + }, errorObj); | ||
| 20 | 20 | ||
| 21 | - assert.throws(() => { | ||
| 21 | + common.expectsError(() => { | ||
| 22 | 22 | socket.setSendBufferSize(8192); | |
| 23 | - }, common.expectsError(errorObj)); | ||
| 23 | + }, errorObj); | ||
| 24 | 24 | ||
| 25 | - assert.throws(() => { | ||
| 25 | + common.expectsError(() => { | ||
| 26 | 26 | socket.getRecvBufferSize(); | |
| 27 | - }, common.expectsError(errorObj)); | ||
| 27 | + }, errorObj); | ||
| 28 | 28 | ||
| 29 | - assert.throws(() => { | ||
| 29 | + common.expectsError(() => { | ||
| 30 | 30 | socket.getSendBufferSize(); | |
| 31 | - }, common.expectsError(errorObj)); | ||
| 31 | + }, errorObj); | ||
| 32 | 32 | } | |
| 33 | 33 | ||
| 34 | 34 | { | |
@@ -45,13 +45,13 @@ const dgram = require('dgram'); | |||
| 45 | 45 | ||
| 46 | 46 | socket.bind(common.mustCall(() => { | |
| 47 | 47 | badBufferSizes.forEach((badBufferSize) => { | |
| 48 | - assert.throws(() => { | ||
| 48 | + common.expectsError(() => { | ||
| 49 | 49 | socket.setRecvBufferSize(badBufferSize); | |
| 50 | - }, common.expectsError(errorObj)); | ||
| 50 | + }, errorObj); | ||
| 51 | 51 | ||
| 52 | - assert.throws(() => { | ||
| 52 | + common.expectsError(() => { | ||
| 53 | 53 | socket.setSendBufferSize(badBufferSize); | |
| 54 | - }, common.expectsError(errorObj)); | ||
| 54 | + }, errorObj); | ||
| 55 | 55 | }); | |
| 56 | 56 | socket.close(); | |
| 57 | 57 | })); | |
@@ -84,9 +84,9 @@ function checkBufferSizeError(type, size) { | |||
| 84 | 84 | 'BufferSize'; | |
| 85 | 85 | const socket = dgram.createSocket('udp4'); | |
| 86 | 86 | socket.bind(common.mustCall(() => { | |
| 87 | - assert.throws(() => { | ||
| 87 | + common.expectsError(() => { | ||
| 88 | 88 | socket[functionName](size); | |
| 89 | - }, common.expectsError(errorObj)); | ||
| 89 | + }, errorObj); | ||
| 90 | 90 | socket.close(); | |
| 91 | 91 | })); | |
| 92 | 92 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,51 +7,51 @@ const dns = require('dns'); | |||
| 7 | 7 | // Stub `getaddrinfo` to *always* error. | |
| 8 | 8 | cares.getaddrinfo = () => process.binding('uv').UV_ENOENT; | |
| 9 | 9 | ||
| 10 | - assert.throws(() => { | ||
| 10 | + common.expectsError(() => { | ||
| 11 | 11 | dns.lookup(1, {}); | |
| 12 | - }, common.expectsError({ | ||
| 12 | + }, { | ||
| 13 | 13 | code: 'ERR_INVALID_ARG_TYPE', | |
| 14 | 14 | type: TypeError, | |
| 15 | 15 | message: /^The "hostname" argument must be one of type string or falsy/ | |
| 16 | - })); | ||
| 16 | + }); | ||
| 17 | 17 | ||
| 18 | - assert.throws(() => { | ||
| 18 | + common.expectsError(() => { | ||
| 19 | 19 | dns.lookup(false, 'cb'); | |
| 20 | - }, common.expectsError({ | ||
| 20 | + }, { | ||
| 21 | 21 | code: 'ERR_INVALID_CALLBACK', | |
| 22 | 22 | type: TypeError | |
| 23 | - })); | ||
| 23 | + }); | ||
| 24 | 24 | ||
| 25 | - assert.throws(() => { | ||
| 25 | + common.expectsError(() => { | ||
| 26 | 26 | dns.lookup(false, 'options', 'cb'); | |
| 27 | - }, common.expectsError({ | ||
| 27 | + }, { | ||
| 28 | 28 | code: 'ERR_INVALID_CALLBACK', | |
| 29 | 29 | type: TypeError | |
| 30 | - })); | ||
| 30 | + }); | ||
| 31 | 31 | ||
| 32 | - assert.throws(() => { | ||
| 32 | + common.expectsError(() => { | ||
| 33 | 33 | dns.lookup(false, { | |
| 34 | 34 | hints: 100, | |
| 35 | 35 | family: 0, | |
| 36 | 36 | all: false | |
| 37 | 37 | }, common.mustNotCall()); | |
| 38 | - }, common.expectsError({ | ||
| 38 | + }, { | ||
| 39 | 39 | code: 'ERR_INVALID_OPT_VALUE', | |
| 40 | 40 | type: TypeError, | |
| 41 | 41 | message: 'The value "100" is invalid for option "hints"' | |
| 42 | - })); | ||
| 42 | + }); | ||
| 43 | 43 | ||
| 44 | - assert.throws(() => { | ||
| 44 | + common.expectsError(() => { | ||
| 45 | 45 | dns.lookup(false, { | |
| 46 | 46 | hints: 0, | |
| 47 | 47 | family: 20, | |
| 48 | 48 | all: false | |
| 49 | 49 | }, common.mustNotCall()); | |
| 50 | - }, common.expectsError({ | ||
| 50 | + }, { | ||
| 51 | 51 | code: 'ERR_INVALID_OPT_VALUE', | |
| 52 | 52 | type: TypeError, | |
| 53 | 53 | message: 'The value "20" is invalid for option "family"' | |
| 54 | - })); | ||
| 54 | + }); | ||
| 55 | 55 | ||
| 56 | 56 | assert.doesNotThrow(() => { | |
| 57 | 57 | dns.lookup(false, { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,18 +21,17 @@ | |||
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | const common = require('../common'); | |
| 24 | - const assert = require('assert'); | ||
| 25 | 24 | const dns = require('dns'); | |
| 26 | 25 | ||
| 27 | 26 | // Should not raise assertion error. Issue #7070 | |
| 28 | - assert.throws(() => dns.resolveNs([]), // bad name | ||
| 29 | - common.expectsError({ | ||
| 30 | - code: 'ERR_INVALID_ARG_TYPE', | ||
| 31 | - type: TypeError, | ||
| 32 | - message: /^The "name" argument must be of type string/ | ||
| 33 | - })); | ||
| 34 | - assert.throws(() => dns.resolveNs(''), // bad callback | ||
| 35 | - common.expectsError({ | ||
| 36 | - code: 'ERR_INVALID_CALLBACK', | ||
| 37 | - type: TypeError | ||
| 38 | - })); | ||
| 27 | + common.expectsError(() => dns.resolveNs([]), // bad name | ||
| 28 | + { | ||
| 29 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 30 | + type: TypeError, | ||
| 31 | + message: /^The "name" argument must be of type string/ | ||
| 32 | + }); | ||
| 33 | + common.expectsError(() => dns.resolveNs(''), // bad callback | ||
| 34 | + { | ||
| 35 | + code: 'ERR_INVALID_CALLBACK', | ||
| 36 | + type: TypeError | ||
| 37 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments