Skip to content

Commit

Permalink
test: improve the code in test-process-cpuUsage
Browse files Browse the repository at this point in the history
* validate the errors for assert.throws
* use arrow functions

PR-URL: nodejs#10714
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
edsadr authored and italoacasas committed Jan 27, 2017
1 parent b5c0b43 commit 7165f1d
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions test/parallel/test-process-cpuUsage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,57 @@ for (let i = 0; i < 10; i++) {
assert(diffUsage.system >= 0);
}

const invalidUserArgument =
/^TypeError: value of user property of argument is invalid$/;
const invalidSystemArgument =
/^TypeError: value of system property of argument is invalid$/;

// Ensure that an invalid shape for the previous value argument throws an error.
assert.throws(function() { process.cpuUsage(1); });
assert.throws(function() { process.cpuUsage({}); });
assert.throws(function() { process.cpuUsage({ user: 'a' }); });
assert.throws(function() { process.cpuUsage({ system: 'b' }); });
assert.throws(function() { process.cpuUsage({ user: null, system: 'c' }); });
assert.throws(function() { process.cpuUsage({ user: 'd', system: null }); });
assert.throws(function() { process.cpuUsage({ user: -1, system: 2 }); });
assert.throws(function() { process.cpuUsage({ user: 3, system: -2 }); });
assert.throws(function() {
assert.throws(() => {
process.cpuUsage(1);
}, invalidUserArgument);

assert.throws(() => {
process.cpuUsage({});
}, invalidUserArgument);

assert.throws(() => {
process.cpuUsage({ user: 'a' });
}, invalidUserArgument);

assert.throws(() => {
process.cpuUsage({ system: 'b' });
}, invalidUserArgument);

assert.throws(() => {
process.cpuUsage({ user: null, system: 'c' });
}, invalidUserArgument);

assert.throws(() => {
process.cpuUsage({ user: 'd', system: null });
}, invalidUserArgument);

assert.throws(() => {
process.cpuUsage({ user: -1, system: 2 });
}, invalidUserArgument);

assert.throws(() => {
process.cpuUsage({ user: 3, system: -2 });
}, invalidSystemArgument);

assert.throws(() => {
process.cpuUsage({
user: Number.POSITIVE_INFINITY,
system: 4
});
});
assert.throws(function() {
}, invalidUserArgument);

assert.throws(() => {
process.cpuUsage({
user: 5,
system: Number.NEGATIVE_INFINITY
});
});
}, invalidSystemArgument);

// Ensure that the return value is the expected shape.
function validateResult(result) {
Expand Down

0 comments on commit 7165f1d

Please sign in to comment.