| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b1d667b commit 0015430
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -557,12 +557,12 @@ function expectedException(actual, expected, msg) { | |||
| 557 | 557 | return expected.call({}, actual) === true; | |
| 558 | 558 | } | |
| 559 | 559 | ||
| 560 | - function getActual(block) { | ||
| 561 | - if (typeof block !== 'function') { | ||
| 562 | - throw new ERR_INVALID_ARG_TYPE('block', 'Function', block); | ||
| 560 | + function getActual(fn) { | ||
| 561 | + if (typeof fn !== 'function') { | ||
| 562 | + throw new ERR_INVALID_ARG_TYPE('fn', 'Function', fn); | ||
| 563 | 563 | } | |
| 564 | 564 | try { | |
| 565 | - block(); | ||
| 565 | + fn(); | ||
| 566 | 566 | } catch (e) { | |
| 567 | 567 | return e; | |
| 568 | 568 | } | |
@@ -579,20 +579,21 @@ function checkIsPromise(obj) { | |||
| 579 | 579 | typeof obj.catch === 'function'; | |
| 580 | 580 | } | |
| 581 | 581 | ||
| 582 | - async function waitForActual(block) { | ||
| 582 | + async function waitForActual(promiseFn) { | ||
| 583 | 583 | let resultPromise; | |
| 584 | - if (typeof block === 'function') { | ||
| 585 | - // Return a rejected promise if `block` throws synchronously. | ||
| 586 | - resultPromise = block(); | ||
| 584 | + if (typeof promiseFn === 'function') { | ||
| 585 | + // Return a rejected promise if `promiseFn` throws synchronously. | ||
| 586 | + resultPromise = promiseFn(); | ||
| 587 | 587 | // Fail in case no promise is returned. | |
| 588 | 588 | if (!checkIsPromise(resultPromise)) { | |
| 589 | 589 | throw new ERR_INVALID_RETURN_VALUE('instance of Promise', | |
| 590 | - 'block', resultPromise); | ||
| 590 | + 'promiseFn', resultPromise); | ||
| 591 | 591 | } | |
| 592 | - } else if (checkIsPromise(block)) { | ||
| 593 | - resultPromise = block; | ||
| 592 | + } else if (checkIsPromise(promiseFn)) { | ||
| 593 | + resultPromise = promiseFn; | ||
| 594 | 594 | } else { | |
| 595 | - throw new ERR_INVALID_ARG_TYPE('block', ['Function', 'Promise'], block); | ||
| 595 | + throw new ERR_INVALID_ARG_TYPE( | ||
| 596 | + 'promiseFn', ['Function', 'Promise'], promiseFn); | ||
| 596 | 597 | } | |
| 597 | 598 | ||
| 598 | 599 | try { | |
@@ -672,20 +673,20 @@ function expectsNoError(stackStartFn, actual, error, message) { | |||
| 672 | 673 | throw actual; | |
| 673 | 674 | } | |
| 674 | 675 | ||
| 675 | - assert.throws = function throws(block, ...args) { | ||
| 676 | - expectsError(throws, getActual(block), ...args); | ||
| 676 | + assert.throws = function throws(promiseFn, ...args) { | ||
| 677 | + expectsError(throws, getActual(promiseFn), ...args); | ||
| 677 | 678 | }; | |
| 678 | 679 | ||
| 679 | - assert.rejects = async function rejects(block, ...args) { | ||
| 680 | - expectsError(rejects, await waitForActual(block), ...args); | ||
| 680 | + assert.rejects = async function rejects(promiseFn, ...args) { | ||
| 681 | + expectsError(rejects, await waitForActual(promiseFn), ...args); | ||
| 681 | 682 | }; | |
| 682 | 683 | ||
| 683 | - assert.doesNotThrow = function doesNotThrow(block, ...args) { | ||
| 684 | - expectsNoError(doesNotThrow, getActual(block), ...args); | ||
| 684 | + assert.doesNotThrow = function doesNotThrow(fn, ...args) { | ||
| 685 | + expectsNoError(doesNotThrow, getActual(fn), ...args); | ||
| 685 | 686 | }; | |
| 686 | 687 | ||
| 687 | - assert.doesNotReject = async function doesNotReject(block, ...args) { | ||
| 688 | - expectsNoError(doesNotReject, await waitForActual(block), ...args); | ||
| 688 | + assert.doesNotReject = async function doesNotReject(fn, ...args) { | ||
| 689 | + expectsNoError(doesNotReject, await waitForActual(fn), ...args); | ||
| 689 | 690 | }; | |
| 690 | 691 | ||
| 691 | 692 | assert.ifError = function ifError(err) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,7 @@ const promises = []; | |||
| 41 | 41 | name: 'TypeError [ERR_INVALID_RETURN_VALUE]', | |
| 42 | 42 | code: 'ERR_INVALID_RETURN_VALUE', | |
| 43 | 43 | message: 'Expected instance of Promise to be returned ' + | |
| 44 | - 'from the "block" function but got type undefined.' | ||
| 44 | + 'from the "promiseFn" function but got type undefined.' | ||
| 45 | 45 | })); | |
| 46 | 46 | ||
| 47 | 47 | promise = assert.rejects(Promise.resolve(), common.mustNotCall()); | |
@@ -62,7 +62,7 @@ promises.push(assert.rejects( | |||
| 62 | 62 | assert.rejects('fail', {}), | |
| 63 | 63 | { | |
| 64 | 64 | code: 'ERR_INVALID_ARG_TYPE', | |
| 65 | - message: 'The "block" argument must be one of type ' + | ||
| 65 | + message: 'The "promiseFn" argument must be one of type ' + | ||
| 66 | 66 | 'Function or Promise. Received type string' | |
| 67 | 67 | } | |
| 68 | 68 | )); | |
@@ -73,7 +73,7 @@ promises.push(assert.rejects( | |||
| 73 | 73 | const promise = assert.doesNotReject(() => new Map(), common.mustNotCall()); | |
| 74 | 74 | promises.push(assert.rejects(promise, { | |
| 75 | 75 | message: 'Expected instance of Promise to be returned ' + | |
| 76 | - 'from the "block" function but got instance of Map.', | ||
| 76 | + 'from the "promiseFn" function but got instance of Map.', | ||
| 77 | 77 | code: 'ERR_INVALID_RETURN_VALUE', | |
| 78 | 78 | name: 'TypeError [ERR_INVALID_RETURN_VALUE]' | |
| 79 | 79 | })); | |
@@ -116,7 +116,7 @@ promises.push(assert.rejects( | |||
| 116 | 116 | assert.doesNotReject(123), | |
| 117 | 117 | { | |
| 118 | 118 | code: 'ERR_INVALID_ARG_TYPE', | |
| 119 | - message: 'The "block" argument must be one of type ' + | ||
| 119 | + message: 'The "promiseFn" argument must be one of type ' + | ||
| 120 | 120 | 'Function or Promise. Received type number' | |
| 121 | 121 | } | |
| 122 | 122 | )); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -341,15 +341,15 @@ try { | |||
| 341 | 341 | } | |
| 342 | 342 | ||
| 343 | 343 | { | |
| 344 | - // Verify that throws() and doesNotThrow() throw on non-function block. | ||
| 345 | - const testBlockTypeError = (method, block) => { | ||
| 344 | + // Verify that throws() and doesNotThrow() throw on non-functions. | ||
| 345 | + const testBlockTypeError = (method, fn) => { | ||
| 346 | 346 | common.expectsError( | |
| 347 | - () => method(block), | ||
| 347 | + () => method(fn), | ||
| 348 | 348 | { | |
| 349 | 349 | code: 'ERR_INVALID_ARG_TYPE', | |
| 350 | 350 | type: TypeError, | |
| 351 | - message: 'The "block" argument must be of type Function. Received ' + | ||
| 352 | - `type ${typeof block}` | ||
| 351 | + message: 'The "fn" argument must be of type Function. Received ' + | ||
| 352 | + `type ${typeof fn}` | ||
| 353 | 353 | } | |
| 354 | 354 | ); | |
| 355 | 355 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -178,7 +178,7 @@ function run_test_3() { | |||
| 178 | 178 | ||
| 179 | 179 | const run_test_4 = common.mustCall(function() { | |
| 180 | 180 | // Error: start must be >= zero | |
| 181 | - const block = () => { | ||
| 181 | + const fn = () => { | ||
| 182 | 182 | fs.createWriteStream(filepath, { start: -5, flags: 'r+' }); | |
| 183 | 183 | }; | |
| 184 | 184 | const err = { | |
@@ -187,7 +187,7 @@ const run_test_4 = common.mustCall(function() { | |||
| 187 | 187 | 'It must be >= 0. Received {start: -5}', | |
| 188 | 188 | type: RangeError | |
| 189 | 189 | }; | |
| 190 | - common.expectsError(block, err); | ||
| 190 | + common.expectsError(fn, err); | ||
| 191 | 191 | }); | |
| 192 | 192 | ||
| 193 | 193 | run_test_1(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,8 +62,8 @@ const net = require('net'); | |||
| 62 | 62 | const hints = (dns.ADDRCONFIG | dns.V4MAPPED) + 42; | |
| 63 | 63 | const hintOptBlocks = doConnect([{ hints }], | |
| 64 | 64 | () => common.mustNotCall()); | |
| 65 | - for (const block of hintOptBlocks) { | ||
| 66 | - common.expectsError(block, { | ||
| 65 | + for (const fn of hintOptBlocks) { | ||
| 66 | + common.expectsError(fn, { | ||
| 67 | 67 | code: 'ERR_INVALID_OPT_VALUE', | |
| 68 | 68 | type: TypeError, | |
| 69 | 69 | message: /The value "\d+" is invalid for option "hints"/ | |
@@ -136,67 +136,59 @@ function doConnect(args, getCb) { | |||
| 136 | 136 | function syncFailToConnect(port, assertErr, optOnly) { | |
| 137 | 137 | if (!optOnly) { | |
| 138 | 138 | // connect(port, cb) and connect(port) | |
| 139 | - const portArgBlocks = doConnect([port], () => common.mustNotCall()); | ||
| 140 | - for (const block of portArgBlocks) { | ||
| 141 | - assert.throws(block, | ||
| 142 | - assertErr, | ||
| 143 | - `${block.name}(${port})`); | ||
| 139 | + const portArgFunctions = doConnect([port], () => common.mustNotCall()); | ||
| 140 | + for (const fn of portArgFunctions) { | ||
| 141 | + assert.throws(fn, assertErr, `${fn.name}(${port})`); | ||
| 144 | 142 | } | |
| 145 | 143 | ||
| 146 | 144 | // connect(port, host, cb) and connect(port, host) | |
| 147 | - const portHostArgBlocks = doConnect([port, 'localhost'], | ||
| 148 | - () => common.mustNotCall()); | ||
| 149 | - for (const block of portHostArgBlocks) { | ||
| 150 | - assert.throws(block, | ||
| 151 | - assertErr, | ||
| 152 | - `${block.name}(${port}, 'localhost')`); | ||
| 145 | + const portHostArgFunctions = doConnect([port, 'localhost'], | ||
| 146 | + () => common.mustNotCall()); | ||
| 147 | + for (const fn of portHostArgFunctions) { | ||
| 148 | + assert.throws(fn, assertErr, `${fn.name}(${port}, 'localhost')`); | ||
| 153 | 149 | } | |
| 154 | 150 | } | |
| 155 | 151 | // connect({port}, cb) and connect({port}) | |
| 156 | - const portOptBlocks = doConnect([{ port }], | ||
| 157 | - () => common.mustNotCall()); | ||
| 158 | - for (const block of portOptBlocks) { | ||
| 159 | - assert.throws(block, | ||
| 160 | - assertErr, | ||
| 161 | - `${block.name}({port: ${port}})`); | ||
| 152 | + const portOptFunctions = doConnect([{ port }], () => common.mustNotCall()); | ||
| 153 | + for (const fn of portOptFunctions) { | ||
| 154 | + assert.throws(fn, assertErr, `${fn.name}({port: ${port}})`); | ||
| 162 | 155 | } | |
| 163 | 156 | ||
| 164 | 157 | // connect({port, host}, cb) and connect({port, host}) | |
| 165 | - const portHostOptBlocks = doConnect([{ port: port, host: 'localhost' }], | ||
| 166 | - () => common.mustNotCall()); | ||
| 167 | - for (const block of portHostOptBlocks) { | ||
| 168 | - assert.throws(block, | ||
| 158 | + const portHostOptFunctions = doConnect([{ port: port, host: 'localhost' }], | ||
| 159 | + () => common.mustNotCall()); | ||
| 160 | + for (const fn of portHostOptFunctions) { | ||
| 161 | + assert.throws(fn, | ||
| 169 | 162 | assertErr, | |
| 170 | - `${block.name}({port: ${port}, host: 'localhost'})`); | ||
| 163 | + `${fn.name}({port: ${port}, host: 'localhost'})`); | ||
| 171 | 164 | } | |
| 172 | 165 | } | |
| 173 | 166 | ||
| 174 | 167 | function canConnect(port) { | |
| 175 | 168 | const noop = () => common.mustCall(); | |
| 176 | 169 | ||
| 177 | 170 | // connect(port, cb) and connect(port) | |
| 178 | - const portArgBlocks = doConnect([port], noop); | ||
| 179 | - for (const block of portArgBlocks) { | ||
| 180 | - block(); | ||
| 171 | + const portArgFunctions = doConnect([port], noop); | ||
| 172 | + for (const fn of portArgFunctions) { | ||
| 173 | + fn(); | ||
| 181 | 174 | } | |
| 182 | 175 | ||
| 183 | 176 | // connect(port, host, cb) and connect(port, host) | |
| 184 | - const portHostArgBlocks = doConnect([port, 'localhost'], noop); | ||
| 185 | - for (const block of portHostArgBlocks) { | ||
| 186 | - block(); | ||
| 177 | + const portHostArgFunctions = doConnect([port, 'localhost'], noop); | ||
| 178 | + for (const fn of portHostArgFunctions) { | ||
| 179 | + fn(); | ||
| 187 | 180 | } | |
| 188 | 181 | ||
| 189 | 182 | // connect({port}, cb) and connect({port}) | |
| 190 | - const portOptBlocks = doConnect([{ port }], noop); | ||
| 191 | - for (const block of portOptBlocks) { | ||
| 192 | - block(); | ||
| 183 | + const portOptFunctions = doConnect([{ port }], noop); | ||
| 184 | + for (const fn of portOptFunctions) { | ||
| 185 | + fn(); | ||
| 193 | 186 | } | |
| 194 | 187 | ||
| 195 | 188 | // connect({port, host}, cb) and connect({port, host}) | |
| 196 | - const portHostOptBlocks = doConnect([{ port: port, host: 'localhost' }], | ||
| 197 | - noop); | ||
| 198 | - for (const block of portHostOptBlocks) { | ||
| 199 | - block(); | ||
| 189 | + const portHostOptFns = doConnect([{ port, host: 'localhost' }], noop); | ||
| 190 | + for (const fn of portHostOptFns) { | ||
| 191 | + fn(); | ||
| 200 | 192 | } | |
| 201 | 193 | } | |
| 202 | 194 | ||
@@ -208,21 +200,20 @@ function asyncFailToConnect(port) { | |||
| 208 | 200 | ||
| 209 | 201 | const dont = () => common.mustNotCall(); | |
| 210 | 202 | // connect(port, cb) and connect(port) | |
| 211 | - const portArgBlocks = doConnect([port], dont); | ||
| 212 | - for (const block of portArgBlocks) { | ||
| 213 | - block().on('error', onError()); | ||
| 203 | + const portArgFunctions = doConnect([port], dont); | ||
| 204 | + for (const fn of portArgFunctions) { | ||
| 205 | + fn().on('error', onError()); | ||
| 214 | 206 | } | |
| 215 | 207 | ||
| 216 | 208 | // connect({port}, cb) and connect({port}) | |
| 217 | - const portOptBlocks = doConnect([{ port }], dont); | ||
| 218 | - for (const block of portOptBlocks) { | ||
| 219 | - block().on('error', onError()); | ||
| 209 | + const portOptFunctions = doConnect([{ port }], dont); | ||
| 210 | + for (const fn of portOptFunctions) { | ||
| 211 | + fn().on('error', onError()); | ||
| 220 | 212 | } | |
| 221 | 213 | ||
| 222 | 214 | // connect({port, host}, cb) and connect({port, host}) | |
| 223 | - const portHostOptBlocks = doConnect([{ port: port, host: 'localhost' }], | ||
| 224 | - dont); | ||
| 225 | - for (const block of portHostOptBlocks) { | ||
| 226 | - block().on('error', onError()); | ||
| 215 | + const portHostOptFns = doConnect([{ port, host: 'localhost' }], dont); | ||
| 216 | + for (const fn of portHostOptFns) { | ||
| 217 | + fn().on('error', onError()); | ||
| 227 | 218 | } | |
| 228 | 219 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,10 +54,10 @@ const listenOnPort = [ | |||
| 54 | 54 | ||
| 55 | 55 | { | |
| 56 | 56 | function shouldFailToListen(options) { | |
| 57 | - const block = () => { | ||
| 57 | + const fn = () => { | ||
| 58 | 58 | net.createServer().listen(options, common.mustNotCall()); | |
| 59 | 59 | }; | |
| 60 | - common.expectsError(block, | ||
| 60 | + common.expectsError(fn, | ||
| 61 | 61 | { | |
| 62 | 62 | code: 'ERR_INVALID_OPT_VALUE', | |
| 63 | 63 | type: TypeError, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments