Browse Source

test: improve the code in test-process-cpuUsage

* validate the errors for assert.throws
* use arrow functions

PR-URL: https://github.com/nodejs/node/pull/10714
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
Adrian Estrada 8 years ago
committed by Italo A. Casas
parent
commit
c963094f3c
  1. 54
      test/parallel/test-process-cpuUsage.js

54
test/parallel/test-process-cpuUsage.js

@ -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) {

Loading…
Cancel
Save