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

Commit

Permalink
test: add assert to engineSpecificMessage
Browse files Browse the repository at this point in the history
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 <[email protected]>

test: removing unneeded `engineSpecificMessage`

Removing unneeded `engineSpecificMessage` usages.
  • Loading branch information
kfarnung committed Jul 25, 2017
1 parent e04401e commit 72b7dc2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
16 changes: 16 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,23 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
}
};

function areAllValuesEqual(obj) {
let exemplar;
for (const key of Object.keys(obj)) {
if (exemplar === undefined) {
exemplar = obj[key];
} else if (exemplar !== obj[key]) {
return false;
}
}

return true;
}

exports.engineSpecificMessage = function(messageObject) {
assert.ok(!areAllValuesEqual(messageObject),
'Unnecessary usage of \'engineSpecificMessage\'');

const jsEngine = process.jsEngine || 'v8'; //default is 'v8'
return messageObject[jsEngine];
};
Expand Down
11 changes: 2 additions & 9 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ assert.strictEqual(util.inspect([1, [2, 3]]), '[ 1, [ 2, 3 ] ]');

assert.strictEqual(util.inspect({}), '{}');
assert.strictEqual(util.inspect({a: 1}), '{ a: 1 }');
assert.strictEqual(util.inspect({a: function() {}}),
common.engineSpecificMessage({
v8: '{ a: [Function: a] }',
chakracore: '{ a: [Function: a] }'
}));
assert.strictEqual(util.inspect({a: function() {}}), '{ a: [Function: a] }');
assert.strictEqual(util.inspect({a: () => {}}), '{ a: [Function: a] }');
assert.strictEqual(util.inspect({a: async function() {}}),
'{ a: [AsyncFunction: a] }');
Expand Down Expand Up @@ -302,10 +298,7 @@ assert.strictEqual(
{
const value = () => {};
value.aprop = 42;
assert.strictEqual(util.inspect(value), common.engineSpecificMessage({
v8: '{ [Function: value] aprop: 42 }',
chakracore: '{ [Function: value] aprop: 42 }'
}));
assert.strictEqual(util.inspect(value), '{ [Function: value] aprop: 42 }');
}

// Anonymous function with properties
Expand Down
5 changes: 1 addition & 4 deletions test/parallel/test-util-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ const tests = [
{input: null, output: 'null'},
{input: false, output: 'false'},
{input: 42, output: '42'},
{input: function() {}, output: common.engineSpecificMessage({
v8: '[Function: input]',
chakracore: '[Function: input]'
})},
{input: function() {}, output: '[Function: input]'},
{input: parseInt('not a number', 10), output: 'NaN'},
{input: {answer: 42}, output: '{ answer: 42 }'},
{input: [1, 2, 3], output: '[ 1, 2, 3 ]'}
Expand Down

0 comments on commit 72b7dc2

Please sign in to comment.