Skip to content

Commit

Permalink
test: make url-util-format engine agnostic
Browse files Browse the repository at this point in the history
test-util-format checks the message of an error that is
generated by the JavaScript engine. Error messages that change in the
underlying JavaScript engine should not be breaking changes in Node.js
and therefore should not cause tests to fail. Remove the message check
and replace it with a check of the type of the Error object along with
the absence of a `code` property. (If a `code` property were present, it
would indicate that the error was coming from Node.js rather than the
JavaScript engine.)

This also makes this test usable without modification in the ChakraCore
fork of Node.js.

PR-URL: nodejs#21141
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Trott committed Jun 7, 2018
1 parent 214ff0a commit 5d32c1a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/parallel/test-util-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,18 @@ assert.strictEqual(util.format(symbol), 'Symbol(foo)');
assert.strictEqual(util.format('foo', symbol), 'foo Symbol(foo)');
assert.strictEqual(util.format('%s', symbol), 'Symbol(foo)');
assert.strictEqual(util.format('%j', symbol), 'undefined');
assert.throws(function() {
util.format('%d', symbol);
}, /^TypeError: Cannot convert a Symbol value to a number$/);
assert.throws(
() => { util.format('%d', symbol); },
(e) => {
// The error should be a TypeError.
if (!(e instanceof TypeError))
return false;

// The error should be from the JS engine and not from Node.js.
// JS engine errors do not have the `code` property.
return e.code === undefined;
}
);

// Number format specifier
assert.strictEqual(util.format('%d'), '%d');
Expand Down

0 comments on commit 5d32c1a

Please sign in to comment.