Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve the code in test-process-cpuUsage #10714

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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