Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7165f1d

Browse filesBrowse files
edsadrItalo A. Casas
authored andcommitted
test: improve the code in test-process-cpuUsage
* validate the errors for assert.throws * use arrow functions PR-URL: #10714 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b5c0b43 commit 7165f1d
Copy full SHA for 7165f1d

File tree

Expand file treeCollapse file tree

1 file changed

+42
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+42
-12
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-process-cpuUsage.js
+42-12Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,57 @@ for (let i = 0; i < 10; i++) {
3333
assert(diffUsage.system >= 0);
3434
}
3535

36+
const invalidUserArgument =
37+
/^TypeError: value of user property of argument is invalid$/;
38+
const invalidSystemArgument =
39+
/^TypeError: value of system property of argument is invalid$/;
40+
3641
// Ensure that an invalid shape for the previous value argument throws an error.
37-
assert.throws(function() { process.cpuUsage(1); });
38-
assert.throws(function() { process.cpuUsage({}); });
39-
assert.throws(function() { process.cpuUsage({ user: 'a' }); });
40-
assert.throws(function() { process.cpuUsage({ system: 'b' }); });
41-
assert.throws(function() { process.cpuUsage({ user: null, system: 'c' }); });
42-
assert.throws(function() { process.cpuUsage({ user: 'd', system: null }); });
43-
assert.throws(function() { process.cpuUsage({ user: -1, system: 2 }); });
44-
assert.throws(function() { process.cpuUsage({ user: 3, system: -2 }); });
45-
assert.throws(function() {
42+
assert.throws(() => {
43+
process.cpuUsage(1);
44+
}, invalidUserArgument);
45+
46+
assert.throws(() => {
47+
process.cpuUsage({});
48+
}, invalidUserArgument);
49+
50+
assert.throws(() => {
51+
process.cpuUsage({ user: 'a' });
52+
}, invalidUserArgument);
53+
54+
assert.throws(() => {
55+
process.cpuUsage({ system: 'b' });
56+
}, invalidUserArgument);
57+
58+
assert.throws(() => {
59+
process.cpuUsage({ user: null, system: 'c' });
60+
}, invalidUserArgument);
61+
62+
assert.throws(() => {
63+
process.cpuUsage({ user: 'd', system: null });
64+
}, invalidUserArgument);
65+
66+
assert.throws(() => {
67+
process.cpuUsage({ user: -1, system: 2 });
68+
}, invalidUserArgument);
69+
70+
assert.throws(() => {
71+
process.cpuUsage({ user: 3, system: -2 });
72+
}, invalidSystemArgument);
73+
74+
assert.throws(() => {
4675
process.cpuUsage({
4776
user: Number.POSITIVE_INFINITY,
4877
system: 4
4978
});
50-
});
51-
assert.throws(function() {
79+
}, invalidUserArgument);
80+
81+
assert.throws(() => {
5282
process.cpuUsage({
5383
user: 5,
5484
system: Number.NEGATIVE_INFINITY
5585
});
56-
});
86+
}, invalidSystemArgument);
5787

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.