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 2f44d7f

Browse filesBrowse files
TrottMylesBorins
authored andcommitted
test: refactor test-crypto-random
* specify constructor for assert.throws() * load additional modules only if crypto check passes * normalize some potentially confusing indentation * provided actual first and expected second in assertions PR-URL: #10232 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 730c3b2 commit 2f44d7f
Copy full SHA for 2f44d7f

File tree

Expand file treeCollapse file tree

1 file changed

+11
-32
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-32
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-crypto-random.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-random.js
+11-32Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,34 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
43

54
if (!common.hasCrypto) {
65
common.skip('missing crypto');
76
return;
87
}
9-
var crypto = require('crypto');
8+
9+
const assert = require('assert');
10+
const crypto = require('crypto');
1011

1112
crypto.DEFAULT_ENCODING = 'buffer';
1213

1314
// bump, we register a lot of exit listeners
1415
process.setMaxListeners(256);
1516

16-
[crypto.randomBytes,
17-
crypto.pseudoRandomBytes
18-
].forEach(function(f) {
19-
[-1,
20-
undefined,
21-
null,
22-
false,
23-
true,
24-
{},
25-
[]
26-
].forEach(function(value) {
27-
assert.throws(function() { f(value); });
28-
assert.throws(function() { f(value, function() {}); });
17+
[crypto.randomBytes, crypto.pseudoRandomBytes].forEach(function(f) {
18+
[-1, undefined, null, false, true, {}, []].forEach(function(value) {
19+
assert.throws(function() { f(value); }, TypeError);
20+
assert.throws(function() { f(value, function() {}); }, TypeError);
2921
});
3022

3123
[0, 1, 2, 4, 16, 256, 1024].forEach(function(len) {
32-
f(len, checkCall(function(ex, buf) {
33-
assert.equal(null, ex);
34-
assert.equal(len, buf.length);
24+
f(len, common.mustCall(function(ex, buf) {
25+
assert.strictEqual(ex, null);
26+
assert.strictEqual(buf.length, len);
3527
assert.ok(Buffer.isBuffer(buf));
3628
}));
3729
});
3830
});
3931

40-
// assert that the callback is indeed called
41-
function checkCall(cb, desc) {
42-
var called_ = false;
43-
44-
process.on('exit', function() {
45-
assert.equal(true, called_, desc || ('callback not called: ' + cb));
46-
});
47-
48-
return function() {
49-
return called_ = true, cb.apply(cb, Array.prototype.slice.call(arguments));
50-
};
51-
}
52-
5332
// #5126, "FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData()
5433
// length exceeds max acceptable value"
5534
assert.throws(function() {

0 commit comments

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