From cb6e68e52c482d45bcf18626ea37211f48969043 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 4 Jun 2018 14:07:52 -0700 Subject: [PATCH 1/2] 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. --- test/parallel/test-util-format.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-util-format.js b/test/parallel/test-util-format.js index f99f85b78c853b..6ca86175df1555 100644 --- a/test/parallel/test-util-format.js +++ b/test/parallel/test-util-format.js @@ -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) + return false; + + return true; + } +); // Number format specifier assert.strictEqual(util.format('%d'), '%d'); From ec4cf562bc9a41aa92cf02ca4d4a70e01e87a54e Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 6 Jun 2018 21:16:30 -0700 Subject: [PATCH 2/2] squash! cjihrig nit --- test/parallel/test-util-format.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/parallel/test-util-format.js b/test/parallel/test-util-format.js index 6ca86175df1555..a8adf936719932 100644 --- a/test/parallel/test-util-format.js +++ b/test/parallel/test-util-format.js @@ -53,10 +53,7 @@ assert.throws( // 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) - return false; - - return true; + return e.code === undefined; } );