Skip to content

Commit 2f44d7f

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 730c3b2 commit 2f44d7f

1 file changed

Lines changed: 11 additions & 32 deletions

File tree

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

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,34 @@
11
'use strict';
2-
varcommon=require('../common');
3-
varassert=require('assert');
2+
constcommon=require('../common');
43

54
if(!common.hasCrypto){
65
common.skip('missing crypto');
76
return;
87
}
9-
varcrypto=require('crypto');
8+
9+
constassert=require('assert');
10+
constcrypto=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-
functioncheckCall(cb,desc){
42-
varcalled_=false;
43-
44-
process.on('exit',function(){
45-
assert.equal(true,called_,desc||('callback not called: '+cb));
46-
});
47-
48-
returnfunction(){
49-
returncalled_=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)