| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent be20e9e commit 1b2733f
18 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,7 +50,7 @@ Platform normalizes the `dd` command | |||
| 50 | 50 | ||
| 51 | 51 | Check if there is more than 1gb of total memory. | |
| 52 | 52 | ||
| 53 | - ### expectsError([fn, ]settings) | ||
| 53 | + ### expectsError([fn, ]settings[, exact]) | ||
| 54 | 54 | * `fn` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) | |
| 55 | 55 | * `settings` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) | |
| 56 | 56 | with the following optional properties: | |
@@ -63,9 +63,12 @@ Check if there is more than 1gb of total memory. | |||
| 63 | 63 | if a string is provided for `message`, expected error must have it for its | |
| 64 | 64 | `message` property; if a regular expression is provided for `message`, the | |
| 65 | 65 | regular expression must match the `message` property of the expected error | |
| 66 | + * `exact` [<Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1 | ||
| 66 | 67 | ||
| 67 | 68 | * return function suitable for use as a validation function passed as the second | |
| 68 | - argument to `assert.throws()` | ||
| 69 | + argument to e.g. `assert.throws()`. If the returned function has not been called | ||
| 70 | + exactly `exact` number of times when the test is complete, then the test will | ||
| 71 | + fail. | ||
| 69 | 72 | ||
| 70 | 73 | If `fn` is provided, it will be passed to `assert.throws` as first argument. | |
| 71 | 74 | ||
@@ -217,7 +220,7 @@ Array of IPV6 hosts. | |||
| 217 | 220 | * return [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) | |
| 218 | 221 | ||
| 219 | 222 | Returns a function that calls `fn`. If the returned function has not been called | |
| 220 | - exactly `expected` number of times when the test is complete, then the test will | ||
| 223 | + exactly `exact` number of times when the test is complete, then the test will | ||
| 221 | 224 | fail. | |
| 222 | 225 | ||
| 223 | 226 | If `fn` is not provided, an empty function will be used. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -488,17 +488,15 @@ exports.mustCallAtLeast = function(fn, minimum) { | |||
| 488 | 488 | return _mustCallInner(fn, minimum, 'minimum'); | |
| 489 | 489 | }; | |
| 490 | 490 | ||
| 491 | - function _mustCallInner(fn, criteria, field) { | ||
| 491 | + function _mustCallInner(fn, criteria = 1, field) { | ||
| 492 | 492 | if (typeof fn === 'number') { | |
| 493 | 493 | criteria = fn; | |
| 494 | 494 | fn = noop; | |
| 495 | 495 | } else if (fn === undefined) { | |
| 496 | 496 | fn = noop; | |
| 497 | 497 | } | |
| 498 | 498 | ||
| 499 | - if (criteria === undefined) | ||
| 500 | - criteria = 1; | ||
| 501 | - else if (typeof criteria !== 'number') | ||
| 499 | + if (typeof criteria !== 'number') | ||
| 502 | 500 | throw new TypeError(`Invalid ${field} value: ${criteria}`); | |
| 503 | 501 | ||
| 504 | 502 | const context = { | |
@@ -702,13 +700,14 @@ Object.defineProperty(exports, 'hasSmallICU', { | |||
| 702 | 700 | }); | |
| 703 | 701 | ||
| 704 | 702 | // Useful for testing expected internal/error objects | |
| 705 | - exports.expectsError = function expectsError(fn, options) { | ||
| 703 | + exports.expectsError = function expectsError(fn, options, exact) { | ||
| 706 | 704 | if (typeof fn !== 'function') { | |
| 705 | + exact = options; | ||
| 707 | 706 | options = fn; | |
| 708 | 707 | fn = undefined; | |
| 709 | 708 | } | |
| 710 | 709 | const { code, type, message } = options; | |
| 711 | - function innerFn(error) { | ||
| 710 | + const innerFn = exports.mustCall(function(error) { | ||
| 712 | 711 | assert.strictEqual(error.code, code); | |
| 713 | 712 | if (type !== undefined) { | |
| 714 | 713 | assert(error instanceof type, | |
@@ -721,7 +720,7 @@ exports.expectsError = function expectsError(fn, options) { | |||
| 721 | 720 | assert.strictEqual(error.message, message); | |
| 722 | 721 | } | |
| 723 | 722 | return true; | |
| 724 | - } | ||
| 723 | + }, exact); | ||
| 725 | 724 | if (fn) { | |
| 726 | 725 | assert.throws(fn, innerFn); | |
| 727 | 726 | return; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -153,11 +153,7 @@ assert.throws(makeBlock(a.deepEqual, /a/igm, /a/im), | |||
| 153 | 153 | { | |
| 154 | 154 | const re1 = /a/g; | |
| 155 | 155 | re1.lastIndex = 3; | |
| 156 | - assert.doesNotThrow(makeBlock(a.deepEqual, re1, /a/g), | ||
| 157 | - common.expectsError({ | ||
| 158 | - code: 'ERR_ASSERTION', | ||
| 159 | - message: /^\/a\/g deepEqual \/a\/g$/ | ||
| 160 | - })); | ||
| 156 | + assert.doesNotThrow(makeBlock(a.deepEqual, re1, /a/g)); | ||
| 161 | 157 | } | |
| 162 | 158 | ||
| 163 | 159 | assert.doesNotThrow(makeBlock(a.deepEqual, 4, '4'), 'deepEqual(4, \'4\')'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,7 +57,7 @@ assert.strictEqual(1, a.compare(b, Infinity, -Infinity)); | |||
| 57 | 57 | // zero length target because default for targetEnd <= targetSource | |
| 58 | 58 | assert.strictEqual(1, a.compare(b, '0xff')); | |
| 59 | 59 | ||
| 60 | - const oor = common.expectsError({code: 'ERR_INDEX_OUT_OF_RANGE'}); | ||
| 60 | + const oor = common.expectsError({code: 'ERR_INDEX_OUT_OF_RANGE'}, 7); | ||
| 61 | 61 | ||
| 62 | 62 | assert.throws(() => a.compare(b, 0, 100, 0), oor); | |
| 63 | 63 | assert.throws(() => a.compare(b, 0, 1, 0, 100), oor); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,17 +14,17 @@ child.on('close', common.mustCall((code, signal) => { | |||
| 14 | 14 | type: Error, | |
| 15 | 15 | message: 'Channel closed', | |
| 16 | 16 | code: 'ERR_IPC_CHANNEL_CLOSED' | |
| 17 | - }); | ||
| 17 | + }, 2); | ||
| 18 | 18 | ||
| 19 | - child.on('error', common.mustCall(testError)); | ||
| 19 | + child.on('error', testError); | ||
| 20 | 20 | ||
| 21 | 21 | { | |
| 22 | 22 | const result = child.send('ping'); | |
| 23 | 23 | assert.strictEqual(result, false); | |
| 24 | 24 | } | |
| 25 | 25 | ||
| 26 | 26 | { | |
| 27 | - const result = child.send('pong', common.mustCall(testError)); | ||
| 27 | + const result = child.send('pong', testError); | ||
| 28 | 28 | assert.strictEqual(result, false); | |
| 29 | 29 | } | |
| 30 | 30 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -186,7 +186,7 @@ if (!common.isWindows) { | |||
| 186 | 186 | // Validate the killSignal option | |
| 187 | 187 | const typeErr = /^TypeError: "killSignal" must be a string or number$/; | |
| 188 | 188 | const unknownSignalErr = | |
| 189 | - common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL', type: TypeError }); | ||
| 189 | + common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL', type: TypeError }, 17); | ||
| 190 | 190 | ||
| 191 | 191 | pass('killSignal', undefined); | |
| 192 | 192 | pass('killSignal', null); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ const assert = require('assert'); | |||
| 6 | 6 | const _validateStdio = require('internal/child_process')._validateStdio; | |
| 7 | 7 | ||
| 8 | 8 | const expectedError = | |
| 9 | - common.expectsError({code: 'ERR_INVALID_OPT_VALUE', type: TypeError}); | ||
| 9 | + common.expectsError({code: 'ERR_INVALID_OPT_VALUE', type: TypeError}, 2); | ||
| 10 | 10 | ||
| 11 | 11 | // should throw if string and not ignore, pipe, or inherit | |
| 12 | 12 | assert.throws(() => _validateStdio('foo'), expectedError); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,12 +28,10 @@ fs.readFile(url, common.mustCall((err, data) => { | |||
| 28 | 28 | ||
| 29 | 29 | // Check that using a non file:// URL reports an error | |
| 30 | 30 | const httpUrl = new URL('http://example.org'); | |
| 31 | - fs.readFile(httpUrl, common.mustCall((err) => { | ||
| 32 | - common.expectsError({ | ||
| 33 | - code: 'ERR_INVALID_URL_SCHEME', | ||
| 34 | - type: TypeError, | ||
| 35 | - message: 'The URL must be of scheme file' | ||
| 36 | - })(err); | ||
| 31 | + fs.readFile(httpUrl, common.expectsError({ | ||
| 32 | + code: 'ERR_INVALID_URL_SCHEME', | ||
| 33 | + type: TypeError, | ||
| 34 | + message: 'The URL must be of scheme file' | ||
| 37 | 35 | })); | |
| 38 | 36 | ||
| 39 | 37 | // pct-encoded characters in the path will be decoded and checked | |
@@ -46,31 +44,25 @@ fs.readFile(new URL('file:///c:/tmp/%00test'), common.mustCall((err) => { | |||
| 46 | 44 | if (common.isWindows) { | |
| 47 | 45 | // encoded back and forward slashes are not permitted on windows | |
| 48 | 46 | ['%2f', '%2F', '%5c', '%5C'].forEach((i) => { | |
| 49 | - fs.readFile(new URL(`file:///c:/tmp/${i}`), common.mustCall((err) => { | ||
| 50 | - common.expectsError({ | ||
| 51 | - code: 'ERR_INVALID_FILE_URL_PATH', | ||
| 52 | - type: TypeError, | ||
| 53 | - message: 'File URL path must not include encoded \\ or / characters' | ||
| 54 | - })(err); | ||
| 47 | + fs.readFile(new URL(`file:///c:/tmp/${i}`), common.expectsError({ | ||
| 48 | + code: 'ERR_INVALID_FILE_URL_PATH', | ||
| 49 | + type: TypeError, | ||
| 50 | + message: 'File URL path must not include encoded \\ or / characters' | ||
| 55 | 51 | })); | |
| 56 | 52 | }); | |
| 57 | 53 | } else { | |
| 58 | 54 | // encoded forward slashes are not permitted on other platforms | |
| 59 | 55 | ['%2f', '%2F'].forEach((i) => { | |
| 60 | - fs.readFile(new URL(`file:///c:/tmp/${i}`), common.mustCall((err) => { | ||
| 61 | - common.expectsError({ | ||
| 62 | - code: 'ERR_INVALID_FILE_URL_PATH', | ||
| 63 | - type: TypeError, | ||
| 64 | - message: 'File URL path must not include encoded / characters' | ||
| 65 | - })(err); | ||
| 56 | + fs.readFile(new URL(`file:///c:/tmp/${i}`), common.expectsError({ | ||
| 57 | + code: 'ERR_INVALID_FILE_URL_PATH', | ||
| 58 | + type: TypeError, | ||
| 59 | + message: 'File URL path must not include encoded / characters' | ||
| 66 | 60 | })); | |
| 67 | 61 | }); | |
| 68 | 62 | ||
| 69 | - fs.readFile(new URL('file://hostname/a/b/c'), common.mustCall((err) => { | ||
| 70 | - common.expectsError({ | ||
| 71 | - code: 'ERR_INVALID_FILE_URL_HOST', | ||
| 72 | - type: TypeError, | ||
| 73 | - message: `File URL host must be "localhost" or empty on ${os.platform()}` | ||
| 74 | - })(err); | ||
| 63 | + fs.readFile(new URL('file://hostname/a/b/c'), common.expectsError({ | ||
| 64 | + code: 'ERR_INVALID_FILE_URL_HOST', | ||
| 65 | + type: TypeError, | ||
| 66 | + message: `File URL host must be "localhost" or empty on ${os.platform()}` | ||
| 75 | 67 | })); | |
| 76 | 68 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,12 +4,11 @@ const common = require('../common'); | |||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const util = require('internal/util'); | |
| 6 | 6 | ||
| 7 | - const expectedError = common.expectsError({ | ||
| 8 | - code: 'ERR_NO_CRYPTO', | ||
| 9 | - type: Error | ||
| 10 | - }); | ||
| 11 | - | ||
| 12 | 7 | if (!process.versions.openssl) { | |
| 8 | + const expectedError = common.expectsError({ | ||
| 9 | + code: 'ERR_NO_CRYPTO', | ||
| 10 | + type: Error | ||
| 11 | + }); | ||
| 13 | 12 | assert.throws(() => util.assertCrypto(), expectedError); | |
| 14 | 13 | } else { | |
| 15 | 14 | assert.doesNotThrow(() => util.assertCrypto()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,7 +91,7 @@ const unixSpecialCaseFormatTests = [ | |||
| 91 | 91 | const expectedMessage = common.expectsError({ | |
| 92 | 92 | code: 'ERR_INVALID_ARG_TYPE', | |
| 93 | 93 | type: TypeError | |
| 94 | - }); | ||
| 94 | + }, 18); | ||
| 95 | 95 | ||
| 96 | 96 | const errors = [ | |
| 97 | 97 | {method: 'parse', input: [null], message: expectedMessage}, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments