Skip to content

Commit 62bfc75

Browse 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 696d859 commit 62bfc75

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,28 @@
11
'use strict';
22
constcommon=require('../common');
3-
constassert=require('assert');
43

54
if(!common.hasCrypto){
65
common.skip('missing crypto');
76
return;
87
}
8+
constassert=require('assert');
99
constcrypto=require('crypto');
1010

1111
crypto.DEFAULT_ENCODING='buffer';
1212

1313
// bump, we register a lot of exit listeners
1414
process.setMaxListeners(256);
1515

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(){});});
16+
[crypto.randomBytes,crypto.pseudoRandomBytes].forEach(function(f){
17+
[-1,undefined,null,false,true,{},[]].forEach(function(value){
18+
assert.throws(function(){f(value);},TypeError);
19+
assert.throws(function(){f(value,function(){});},TypeError);
2920
});
3021

3122
[0,1,2,4,16,256,1024].forEach(function(len){
3223
f(len,common.mustCall(function(ex,buf){
33-
assert.strictEqual(null,ex);
34-
assert.strictEqual(len,buf.length);
24+
assert.strictEqual(ex,null);
25+
assert.strictEqual(buf.length,len);
3526
assert.ok(Buffer.isBuffer(buf));
3627
}));
3728
});

0 commit comments

Comments
 (0)