Skip to content

Commit 4800b62

Browse files
GaryGSCaddaleax
authored andcommitted
test: use arrow functions in addons tests
Convert all anonymous callback functions in `test/addons/**/*.js` to use arrow functions, except for those in `test/addons/make-callback/test.js` (which reference `this`) `writing-tests.md` states to use arrow functions when appropriate. PR-URL: #30131 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]>
1 parent 8fcb450 commit 4800b62

File tree

14 files changed

+24
-24
lines changed

14 files changed

+24
-24
lines changed

‎test/addons/async-hello-world/test-makecallback.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const common = require('../../common');
33
constassert=require('assert');
44
const{ runMakeCallback }=require(`./build/${common.buildType}/binding`);
55

6-
runMakeCallback(5,common.mustCall(function(err,val){
6+
runMakeCallback(5,common.mustCall((err,val)=>{
77
assert.strictEqual(err,null);
88
assert.strictEqual(val,10);
99
process.nextTick(common.mustCall());

‎test/addons/async-hello-world/test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const common = require('../../common');
33
constassert=require('assert');
44
const{ runCall }=require(`./build/${common.buildType}/binding`);
55

6-
runCall(5,common.mustCall(function(err,val){
6+
runCall(5,common.mustCall((err,val)=>{
77
assert.strictEqual(err,null);
88
assert.strictEqual(val,10);
99
process.nextTick(common.mustCall());

‎test/addons/load-long-path/test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ fs.writeFileSync(addonDestinationPath, contents);
4848

4949
// Run test
5050
constchild=fork(__filename,['child'],{stdio: 'inherit'});
51-
child.on('exit',common.mustCall(function(code){
51+
child.on('exit',common.mustCall((code)=>{
5252
assert.strictEqual(code,0);
5353
}));

‎test/addons/make-callback-domain-warning/test.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ function makeCallback(object, cb){
1010
}
1111

1212
letlatestWarning=null;
13-
process.on('warning',function(warning){
13+
process.on('warning',(warning)=>{
1414
latestWarning=warning;
1515
});
1616

1717
constd=domain.create();
1818

1919
// When domain is disabled, no warning will be emitted
20-
makeCallback({domain: d},common.mustCall(function(){
20+
makeCallback({domain: d},common.mustCall(()=>{
2121
assert.strictEqual(latestWarning,null);
2222

23-
d.run(common.mustCall(function(){
23+
d.run(common.mustCall(()=>{
2424
// No warning will be emitted when no domain property is applied
25-
makeCallback({},common.mustCall(function(){
25+
makeCallback({},common.mustCall(()=>{
2626
assert.strictEqual(latestWarning,null);
2727

2828
// Warning is emitted when domain property is used and domain is enabled
29-
makeCallback({domain: d},common.mustCall(function(){
29+
makeCallback({domain: d},common.mustCall(()=>{
3030
assert.strictEqual(latestWarning.name,'DeprecationWarning');
3131
assert.strictEqual(latestWarning.code,'DEP0097');
3232
}));

‎test/addons/make-callback-recurse/test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ assert.throws(() =>{
7171
if(arg===1){
7272
// The tests are first run on bootstrap during LoadEnvironment() in
7373
// src/node.cc. Now run the tests through node::MakeCallback().
74-
setImmediate(function(){
74+
setImmediate(()=>{
7575
makeCallback({},common.mustCall(()=>{
7676
verifyExecutionOrder(2);
7777
}));

‎test/addons/openssl-client-cert-engine/test.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ const server = https.createServer(serverOptions, common.mustCall((req, res) =>{
4343
headers: {}
4444
};
4545

46-
constreq=https.request(clientOptions,common.mustCall(function(response){
46+
constreq=https.request(clientOptions,common.mustCall((response)=>{
4747
letbody='';
4848
response.setEncoding('utf8');
49-
response.on('data',function(chunk){
49+
response.on('data',(chunk)=>{
5050
body+=chunk;
5151
});
5252

53-
response.on('end',common.mustCall(function(){
53+
response.on('end',common.mustCall(()=>{
5454
assert.strictEqual(body,'hello world');
5555
server.close();
5656
}));

‎test/addons/openssl-key-engine/test.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ const server = https.createServer(serverOptions, common.mustCall((req, res) =>{
4545
headers: {}
4646
};
4747

48-
constreq=https.request(clientOptions,common.mustCall(function(response){
48+
constreq=https.request(clientOptions,common.mustCall((response)=>{
4949
letbody='';
5050
response.setEncoding('utf8');
51-
response.on('data',function(chunk){
51+
response.on('data',(chunk)=>{
5252
body+=chunk;
5353
});
5454

55-
response.on('end',common.mustCall(function(){
55+
response.on('end',common.mustCall(()=>{
5656
assert.strictEqual(body,'hello world');
5757
server.close();
5858
}));

‎test/addons/repl-domain-abort/test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if (common.isWindows)
3131
buildPath=buildPath.replace(/\\/g,'/');
3232
letcb_ran=false;
3333

34-
process.on('exit',function(){
34+
process.on('exit',()=>{
3535
assert(cb_ran);
3636
console.log('ok');
3737
});

‎test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
2525
common.skip(skipMessage);
2626

2727
conststringLengthHex=kStringMaxLength.toString(16);
28-
common.expectsError(function(){
28+
common.expectsError(()=>{
2929
buf.toString('ascii');
3030
},{
3131
message: `Cannot create a string longer than 0x${stringLengthHex} `+

‎test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
2525
common.skip(skipMessage);
2626

2727
conststringLengthHex=kStringMaxLength.toString(16);
28-
common.expectsError(function(){
28+
common.expectsError(()=>{
2929
buf.toString('base64');
3030
},{
3131
message: `Cannot create a string longer than 0x${stringLengthHex} `+

0 commit comments

Comments
(0)