Skip to content

Commit 7dea1a2

Browse files
committed
fixup!
1 parent a41a7a5 commit 7dea1a2

File tree

4 files changed

+26
-35
lines changed

4 files changed

+26
-35
lines changed

lib/assert.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const {
2727
ArrayPrototypePush,
2828
ArrayPrototypeSlice,
2929
Error,
30-
ErrorPrototypeToString,
3130
NumberIsNaN,
3231
ObjectAssign,
3332
ObjectDefineProperty,
@@ -54,7 +53,7 @@ const {
5453
},
5554
} = require('internal/errors');
5655
const AssertionError = require('internal/assert/assertion_error');
57-
const { inspect, format } = require('internal/util/inspect');
56+
const { inspect } = require('internal/util/inspect');
5857
const {
5958
isPromise,
6059
isRegExp,
@@ -144,8 +143,6 @@ function Assert(options) {
144143
// they lose their `this` context and will use default behavior instead of the
145144
// instance's custom options.
146145

147-
// See `internal/assert/utils.js` for MessageFactory/MessageTuple/InnerFailOptions typedefs
148-
149146
/**
150147
* Throws an AssertionError with the given message.
151148
* @param {any | Error} [message]
@@ -186,7 +183,7 @@ assert.AssertionError = AssertionError;
186183
* @returns {void}
187184
*/
188185
function assert(...args) {
189-
innerOk(assert, args.length, ...args);
186+
innerOk(assert, ...args);
190187
}
191188

192189
/**
@@ -197,7 +194,7 @@ function assert(...args) {
197194
* @returns {void}
198195
*/
199196
Assert.prototype.ok = function ok(...args) {
200-
innerOk(ok, args.length, ...args);
197+
innerOk(ok, ...args);
201198
};
202199

203200
/**
@@ -882,7 +879,7 @@ Assert.prototype.doesNotMatch = function doesNotMatch(string, regexp, ...message
882879
* @returns {void}
883880
*/
884881
function strict(...args) {
885-
innerOk(strict, args.length, ...args);
882+
innerOk(strict, ...args);
886883
}
887884

888885
ArrayPrototypeForEach([

lib/internal/assert/utils.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ const {
99
} = primordials;
1010

1111
const {
12-
codes: { ERR_AMBIGUOUS_ARGUMENT, ERR_INVALID_ARG_TYPE },
12+
codes: {
13+
ERR_AMBIGUOUS_ARGUMENT,
14+
ERR_INVALID_ARG_TYPE,
15+
},
1316
isErrorStackTraceLimitWritable,
1417
} = require('internal/errors');
1518
const AssertionError = require('internal/assert/assertion_error');
@@ -41,7 +44,6 @@ const escapeFn = (str) => meta[StringPrototypeCharCodeAt(str, 0)];
4144
* It is invoked only when the assertion fails.
4245
*
4346
* Other return values than a string are ignored.
44-
*
4547
* @callback MessageFactory
4648
* @param {any} actual
4749
* @param {any} expected
@@ -59,20 +61,19 @@ const escapeFn = (str) => meta[StringPrototypeCharCodeAt(str, 0)];
5961
*
6062
* Additional elements after [Error] or [MessageFactory] are rejected with ERR_AMBIGUOUS_ARGUMENT.
6163
* A first element that is neither string, Error nor function is rejected with ERR_INVALID_ARG_TYPE.
62-
*
6364
* @typedef {[] | [string] | [string, ...any[]] | [Error] | [MessageFactory]} MessageTuple
6465
*/
6566

6667
/**
6768
* Options consumed by innerFail to construct and throw the AssertionError.
6869
* @typedef {object} InnerFailOptions
69-
* @property {any} actual
70-
* @property {any} expected
71-
* @property {MessageTuple} message
72-
* @property {string} operator
73-
* @property {Function} stackStartFn
74-
* @property {'simple' | 'full'} [diff]
75-
* @property {boolean} [generatedMessage]
70+
* @property {any} actual Actual value
71+
* @property {any} expected Expected value
72+
* @property {MessageTuple} message Message
73+
* @property {string} operator Operator
74+
* @property {Function} stackStartFn Stack start function
75+
* @property {'simple' | 'full'} [diff] Diff mode
76+
* @property {boolean} [generatedMessage] Generated message
7677
*/
7778

7879
function getErrMessage(fn) {
@@ -148,31 +149,25 @@ function innerFail(obj) {
148149
/**
149150
* Internal ok handler delegating to innerFail for message handling.
150151
* @param {Function} fn
151-
* @param {number} argLen
152-
* @param {any} value
153-
* @param {...any} message
152+
* @param {...any} args
154153
*/
155-
function innerOk(fn, argLen, value, ...message) {
156-
if (!value) {
154+
function innerOk(fn, ...args) {
155+
if (!args[0]) {
157156
let generatedMessage = false;
158-
/** @type {any[]} */
159157
let messageArgs;
160158

161-
if (argLen === 0) {
159+
if (args.length === 0) {
162160
generatedMessage = true;
163161
messageArgs = ['No value argument passed to `assert.ok()`'];
164-
} else if (message.length === 0 || message[0] == null) {
162+
} else if (args.length === 1 || args[1] == null) {
165163
generatedMessage = true;
166164
messageArgs = [getErrMessage(fn)];
167-
} else if (typeof message[0] === 'string' || isError(message[0]) || typeof message[0] === 'function') {
168-
messageArgs = message;
169165
} else {
170-
// Accept any other type as custom message for assert.ok()
171-
messageArgs = [String(message[0])];
166+
messageArgs = args.slice(1);
172167
}
173168

174169
innerFail({
175-
actual: value,
170+
actual: args[0],
176171
expected: true,
177172
message: messageArgs,
178173
operator: '==',

lib/internal/test_runner/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class TestContext {
333333
if (plan !== null) {
334334
plan.count();
335335
}
336-
innerOk(ok, args.length, ...args);
336+
innerOk(ok, ...args);
337337
}
338338

339339
assert.ok = ok;

test/parallel/test-assert.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,9 @@ test('Additional asserts', () => {
904904
assert.throws(
905905
() => assert(false, Symbol('foo')),
906906
{
907-
code: 'ERR_ASSERTION',
908-
constructor: assert.AssertionError,
909-
generatedMessage: false,
910-
message: 'Symbol(foo)'
907+
code: 'ERR_INVALID_ARG_TYPE',
908+
constructor: TypeError,
909+
message: /"message" argument.+Symbol\(foo\)/
911910
}
912911
);
913912

0 commit comments

Comments
 (0)