Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 72b7dc2

Browse files
committed
test: add assert to engineSpecificMessage
Make sure that it's actually necessary to use `engineSpecificMessage` by asserting that at least one string is different. Also removed uses where it was no longer needed. PR-URL: #346 Reviewed-By: Kunal Pathak <kunal.pathak@microsoft.com> test: removing unneeded `engineSpecificMessage` Removing unneeded `engineSpecificMessage` usages.
1 parent e04401e commit 72b7dc2

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

test/common/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,23 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
633633
}
634634
};
635635

636+
function areAllValuesEqual(obj) {
637+
let exemplar;
638+
for (const key of Object.keys(obj)) {
639+
if (exemplar === undefined) {
640+
exemplar = obj[key];
641+
} else if (exemplar !== obj[key]) {
642+
return false;
643+
}
644+
}
645+
646+
return true;
647+
}
648+
636649
exports.engineSpecificMessage = function(messageObject) {
650+
assert.ok(!areAllValuesEqual(messageObject),
651+
'Unnecessary usage of \'engineSpecificMessage\'');
652+
637653
const jsEngine = process.jsEngine || 'v8'; //default is 'v8'
638654
return messageObject[jsEngine];
639655
};

test/parallel/test-util-inspect.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ assert.strictEqual(util.inspect([1, [2, 3]]), '[ 1, [ 2, 3 ] ]');
5252

5353
assert.strictEqual(util.inspect({}), '{}');
5454
assert.strictEqual(util.inspect({a: 1}), '{ a: 1 }');
55-
assert.strictEqual(util.inspect({a: function() {}}),
56-
common.engineSpecificMessage({
57-
v8: '{ a: [Function: a] }',
58-
chakracore: '{ a: [Function: a] }'
59-
}));
55+
assert.strictEqual(util.inspect({a: function() {}}), '{ a: [Function: a] }');
6056
assert.strictEqual(util.inspect({a: () => {}}), '{ a: [Function: a] }');
6157
assert.strictEqual(util.inspect({a: async function() {}}),
6258
'{ a: [AsyncFunction: a] }');
@@ -302,10 +298,7 @@ assert.strictEqual(
302298
{
303299
const value = () => {};
304300
value.aprop = 42;
305-
assert.strictEqual(util.inspect(value), common.engineSpecificMessage({
306-
v8: '{ [Function: value] aprop: 42 }',
307-
chakracore: '{ [Function: value] aprop: 42 }'
308-
}));
301+
assert.strictEqual(util.inspect(value), '{ [Function: value] aprop: 42 }');
309302
}
310303

311304
// Anonymous function with properties

test/parallel/test-util-log.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ const tests = [
3939
{input: null, output: 'null'},
4040
{input: false, output: 'false'},
4141
{input: 42, output: '42'},
42-
{input: function() {}, output: common.engineSpecificMessage({
43-
v8: '[Function: input]',
44-
chakracore: '[Function: input]'
45-
})},
42+
{input: function() {}, output: '[Function: input]'},
4643
{input: parseInt('not a number', 10), output: 'NaN'},
4744
{input: {answer: 42}, output: '{ answer: 42 }'},
4845
{input: [1, 2, 3], output: '[ 1, 2, 3 ]'}

0 commit comments

Comments
 (0)