Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make url-util-format engine agnostic #21141

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: make url-util-format engine agnostic
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.
  • Loading branch information
Trott committed Jun 4, 2018
commit cb6e68e52c482d45bcf18626ea37211f48969043
18 changes: 15 additions & 3 deletions test/parallel/test-util-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,21 @@ 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.
if (e.code !== undefined)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These few lines can just be return e.code === undefined;

return false;

return true;
}
);

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